Set up & Integrate
Learn how to set up and integrate Components.
Server-side
Generate a session_id
session_id
The first step in the process is to use your API credentials to authenticate and login. A request can then be submitted to the /payment-sessions
endpoint containing the fields of the transaction
and tds
objects. Please view our API reference for further information on this endpoint.
Request:
{
"transaction": {
"order_id": "41142534-2e55-4eb2-9553-59784c73b2b0",
"amount": 15.02,
"currency": "gbp"
},
"tds": {
"is_active": true,
"challenge_preference": "no_preference",
"contact_url": "https://yourdomain.com/contact",
"redirect_url": "https://yourdomain.com/redirect",
"webhook_url": "https://yourdomain.com/webhook"
}
}
As a result of a successful response, we will return a session_id
. When a payment is then completed using Components, the parameters set within the session_id
will be used to complete the payment.
Note
Session IDs are temporary and will expire after 10 minutes. After this time, a new
session_id
will need to be generated.
Successful response:
{
"session_id": "6d07e15a-b8ab-41e9-993b-39fbe688da92"
}
If a request is submitted to the /payment-sessions
endpoint and a required parameter is not present, we will return a 400 error.
Example response:
{
"status": "error",
"error_type": "validation",
"title": "Your request parameters did not pass our validation.",
"instance": "/v1/payment-sessions",
"invalid_parameters": [
{
"parameter": "transcaction.order_id",
"reason": "transaction.order_id can not be empty"
}
]
}
Updating a session_id
session_id
There will be instances where the initially entered amount undergoes alterations from the original request. This could occur for many reasons, including, when there is an increased delivery charge or the cardholder applies a coupon code.
In such cases, initiate a PUT request to the endpoint /payment-sessions/{session_id}
, incorporating the modified parameters. This allows changes to be submitted to any of the supported parameters. Following a successful response, when the payment is completed within Components, the authorisation request will use the latest parameter set against the session_id
. Please refer to the API reference for further details.
Client side
Add Acquired.js within your code base
You can then include Acquired.js within the script tag. At this point we recommend performing an integrity check to confirm that the code has not been altered with.
Example:
<script type=”text/javascript” src=”https://cdn.acquired.com/sdk/v1/acquired.js” integrity=JS_INTEGRITY_HASH” crossorigin=”anonymous”></script>
If you are utilising Content Security Policy, we advise adding the cdn.acquired.com
domain to your whitelist. This ensures that the script can be loaded and executed on your web pages without triggering CSP violations.
Initialise the Acquired object
To initialise the Acquired object within the code base, you firstly need your public_key
value. This can be found in Settings > API Access.
Note
Ensure that you do not copy your
app_key
orapp_id
values as these are private and must never be exposed on the Client-Side.
You can also determine which environment is being targeted by inputting test
or prod
within the options
.
Example:
const sessionId = “7048422b-6985-4608-9240-3dc9cc966317”;
const acquired = new Acquired(‘pkc4ac45debfe91b36e4fb092d2b30f3a5’);
const options = {
session: sessionId,
environment: “test”
};
const components = acquired.components(options);
Creating your Components
Once you have successfully initialised the Acquired.js object within your script, the next step is to choose the right component form for your business. Acquired provides two solutions for achieving this:
- Form: Use a single form to implement the Components solution.
- Fields: Utilise individual components to construct a solution that aligns with your requirements.
Option one: Form
Acquired’s form solution encompasses all the essential components required for building the payment form.
The HTML code represents the Acquired js DOM, representing the structure of the webpage. It includes each form element and the components contained within the div.
Example:
<form id=”payment-form” class=”form-main”>
<div id=”payment-component”></div>
With our form solution, you can create the component, which contains all the required card fields, and then mount it in your checkout.
Example:
const cardComponent = components.create(‘cardForm’, {
style: style
}),
cardComponent.mount(‘#payment-component’);
Option two: Fields
Acquired’s fields solution allows you to create your own card form, defining the components that you want to display within your checkout.
Unlike the form discussed above, the “payment-component” contains multiple individual fields that can be created and mounted.
Firstly, confirm which fields you want to display in your payment form by inputting the required fields within your code.
Example (the input fields can be named according to your preference):
<form id=”payment-form” class=”form-main”>
<div id=”payment-component”>
<div class=”input-field” id=”card-holder-component”></div>
<p clas="component-error"></p>
<div class=”input-field” id=”card-number-component”></div>
<p clas="component-error"></p>
<div class=”input-field” id=”card-expiry-date-component”></div>
<p clas="component-error"></p>
<div class=”input-field” id=”card-cvv-component”></div>
<p clas="component-error"></p>
</div>
The next step is to create the individual components and mount them into your checkout.
const cardNumberComponent = components.create(‘cardNumber’, {
style: style
});
cardNumberComponent.mount(‘#card-number-component’);
const cardholderNameComponent = components.create(‘cardholderName’, {
style: style
});
cardholderNameComponent.mount(#card-holder-component’);
const cardExpiryDateComponent = components.create(cardExpiryDate’, {
style: style
});
cardExpiryDateComponent.mount(‘#card-expiry-date-component’);
const cardCvvComponent = components.create(‘cardCvv’, {
style: style
});
cardCVVComponent.mount(‘#card-cvv-component’);
Components configuration
Component object - Acquired.js
A component
object points to an embeddable element within your checkout, such as the card form or card expiration date.
Option | Definition | Possible Values |
---|---|---|
components.create | This creates a component ready for it to be mounted. | cardForm cardNumber cardholderName cardExpiryDate cardCvv |
components.mount | Once you have created each required component , the next step is to mount them by referencing the <div> where it will be attached. This adds the component to the DOM, making it visible within your checkout. | The possible values will include the input-fields that have been created. |
Set your confirmParameters
The confirmParams
object, allows you to send additional information for the payment authorisation request after the session has been initiated. You can pass through further information such as customer, shipping and billing data to support AVS verification.
Note
If you want to change the transaction or 3DS parameters generated in the /payment-sessions request, you are required to submit a PUT request to /payment-sessions/{session_id}.
For a list of the parameters that can be passed, please refer to our /payments endpoint.
Example:
const confirmParams = {
customer: {
reference: "cfe19f01-6fe5-4c82-be05-0f66054efde1",
billing: {
address: {
line_1: "Flat 1",
line_2: "152 Aldgate Drive",
city: "London",
postcode: "E1 7RT",
country_code: "GB"
},
email: "[email protected]",
phone: {
country_code: "44",
number: "2039826580"
},
shipping: {
address_match: true
},
webhook_url: 'https://www.yourdomain.com/webhook'
}
}
Handling form submit
Your are required to attach an event listener to the form element, which will listen for a “submit” event. This occurs when the user clicks on the submit button. The response will then be returned when the payment request has been processed, which refers to the confirmParams function.
form.addEventListener(‘submit’, async (event) => {
event.preventDefault();
const response = await acquired.confirmPayment({
components,
confirmParams: confirmParams,
})
Handling errors
To handle errors within Components, you need to confirm which responses will be rendered.
Response statuses
Status | Description |
---|---|
isSuccess | The payment has been successfully processed. |
isTdsPending | Awaiting authentication completion. |
isError | The request was received, but an error has occurred. |
isDecline | The payment request was declined by the bank, or the user failed to authenticate the payment. |
if(response.isTdsPending()){
Window.location.href = response.data.redirect_url;
}
if(response.isSuccess()){
const messageContainer = document.querySelector(‘#error-message);
messageContainer.textContent = JSON.stringify(response.data);
}
if(response.isError()){
acquired.showComponentErrorMessage('.component-error', response.data);
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = JSON.stringify(response.data);
}
if(response.isDecline()){
const messageContainer = document.querySelector(‘#error-message);
messageContainer.textContent = JSON.stringify(response.data);
Handling errors: Form
When an error occurs in the initial field, an error message will be displayed. Subsequent errors will be shown once the displayed error has been resolved.
<textarea id="error-message" placeholder="error message" readonly="true"></textarea>
Handling errors: Fields
In cases where multiple errors occur across various fields, all these errors will be displayed underneath the field that they occur in.
<form id=payment-form class=”form-main>
<div class=”input-field” id=”card-holder-component”></div>
<p class=”component-error”></p>
<div class=”input-field” id=”card-number-component”></div>
<p class=”component-error”></p>
<div class=”input-field” id=”card-expiry-date-component”></div>
<p class=”component-error”></p>
<div class=”input-field” id=”card-cvv-component”></div>
<p class=”component-error”></p>
</div>
In order to display the error message and enable custom messaging for individual fields, you are required to add the following code. The blur
event will ensure the error message is displayed whenever the component loses focuses (is clicked away after being interacted with).
components.on('blur', (response) => {
acquired.showComponentErrorMessage('.component-error', response);
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = JSON.stringify(response);
})
The default error message can then be overwritten to display what you require. In the below example we have set the message to "Invalid request".
if(response.isError()){
response.data.message = "Invalid request";
acquired.showComponentErrorMessage('.component-error', response.data);
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = JSON.stringify(response.data);
}
Error messaging
Components has a comprehensive suite of default error messaging that will be displayed to the end user.
The structure of the error response is outlined below:
Field | Description | Example |
---|---|---|
status | The current status of the response. | error decline |
component | The component where the error occurred. | cardForm cardNumber cardholderName cardExpireDate cardCvv |
error_type | The type of error returned. | required incomplete invalid not_accepted |
message | A message containing more detail about the error. | "Cardholder name required" |
Cardholder name required
{
"status": "error",
"component": "cardholderName",
"error_type": "required",
"message": "Cardholder name required"
}
Card number required
{
"status": "error",
"component": "cardNumber",
"error_type": "required",
"message": "Card number required"
}
Incomplete card number
{
"status": "error",
"component": "cardNumber",
"error_type": "incomplete",
"message": "Incomplete card number"
}
Invalid card number
{
"status": "error",
"component": "cardNumber",
"error_type": "invalid",
"message": "Invalid card number"
}
Card number not accepted
{
"status": "error",
"component": "cardNumber",
"error_type": "not-accepted",
"message": "Card number not accepted"
}
Expiry date required
{
"status": "error",
"component": "cardExpiryDate",
"error_type": "required",
"message": "Expiry date required"
}
Card expired
{
"status": "error",
"component": "cardExpiryDate",
"error_type": "expired",
"message": "Card expired"
}
Invalid card expiry year
{
"status": "error",
"component": "cardExpiryDate",
"error_type": "invalid",
"message": "Invalid card expiry year"
}
CVV required
{
"status": "error",
"component": "cardCvv",
"error_type": "required",
"message": "CVV required"
}
Incomplete CVV
{
"status": "error",
"component": "cardCvv",
"error_type": "incomplete",
"message": "Incomplete CVV"
}
Webhook notifications
We will send a status_update
webhook to update your application of the status of the payment.
In order to send webhook notifications, you must add the webhook_url
parameter to the confirmParams component of the SDK.
confirmParams:
webhook_url: 'https:/www.yourdomain.com/webhook'
status_update
webhook:
{
"webhook_type": "status_update",
"webhook_id": "113eeb0e-483e-4fc5-b1b3-4de99e3a9a6f",
"webhook_body": {
"transaction_id": "10ef7f23-2f7b-46d8-af40-fc9846ff59bf",
"status": "success",
"timestamp": 32908394083,
"order_id": "6112dfb4-81de-460e-ad39-7037677d6148"
}
}
For further information on webhooks, including the structure and validating the integrity of a webhook, please view our documentation.
Updated 6 days ago