This feature in Carts API allows users to add, update, and delete payment details. The cart maintains the state of each payment—pending, authorized, captured, and failed—as provided by the user, but it doesn’t store tokens, which are expected from the System Integrator (SI).
Prerequisites
The following prerequisites must be completed sequentially to configure a payment.
Create a cart .
Add an item to the cart.
Payments Initialization
The cart displays authorized amounts and allows updates or removals of payments. Payments can be purged or held when the cart changes such as, price changes. The cart also verifies the authorized payment amount against the cart total.
The following code sample provides an example of the structure of payment information and status in the response:
Click to expand the JSON example.
{
"provider" : "fabricmock" ,
"processor" : "fabricmock" ,
"method" : "CREDIT_CARD" ,
"methodType" : "VISA" ,
"state" : "PENDING" ,
"authorization" : {
"amount" : 520.0 ,
"expiry" : "" ,
"verifier" : {
"type" : "PAYMENT_TOKEN" ,
"key" : "{{payment_token}}"
}
} ,
"billToAddress" : "{{addressId}}" ,
"cardDetails" : null ,
"attributes" : {
"orderSource" : "ecommerce" ,
"expirationDate" : "0224" ,
"requestedDate" : "2022-01-27T16:15:58-05:00" ,
"paymentDate" : "2022-01-27T16:15:58-05:00" ,
"billToId" : "213321"
}
}
As the cart can contain multiple payments, they are shown as a collection. The authorized amount is the sum of all payments with the AUTHORIZED state added to the cart as in the following example:
Click to expand the JSON example.
"payments" : {
"authorized" : 0 ,
"collection" : [
{
"provider" : "fabricmock" ,
"processor" : "fabricmock" ,
"method" : "CREDIT_CARD" ,
"methodType" : "VISA" ,
"state" : "PENDING" ,
"authorization" : {
"amount" : 520.0 ,
"expiry" : "" ,
"verifier" : {
"type" : "PAYMENT_TOKEN" ,
"key" : "{{payment_token}}"
}
} ,
"billToAddress" : "{{addressId}}" ,
"cardDetails" : null ,
"attributes" : {
"orderSource" : "ecommerce" ,
"expirationDate" : "0224" ,
"requestedDate" : "2022-01-27T16:15:58-05:00" ,
"paymentDate" : "2022-01-27T16:15:58-05:00" ,
"billToId" : "213321"
}
}
]
}
Examples
Adding payments with the CAPTURED
status to the cart
Use the create a payment endpoint to add a CAPTURED
payment method to the cart as in the following example:
Click to expand the curl and JSON response example.
curl --location '{{modular_cart_domain}}/carts/ba0e93f5-e47f-4b0d-bac8-6233b67ef65f/payments' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: {tenantId}' \
--header 'Authorization: {authToken}' \
--data '{
"provider": "fabricmock",
"processor": "fabricmock",
"method": "CREDIT_CARD",
"methodType": "VISA",
"state": "CAPTURED",
"authorization": {
"amount": 500.0,
"expiry": "",
"verifier": {
"type": "PAYMENT_TOKEN",
"key": "{{payment_token}}"
}
},
"billToAddress": "46622c9c-604c-4f8c-8bcf-2a393a572839",
"cardDetails": null,
"attributes": {
"orderSource": "ecommerce",
"expirationDate": "0224",
"requestedDate": "2022-01-27T16:15:58-05:00",
"paymentDate": "2022-01-27T16:15:58-05:00",
"billToId": "213321"
}
}
'
A successful response to carts/{cartId}/payments
provides a payments object as the following example:
"payments" : {
"authorized" : 0 ,
"collection" : [
{
"provider" : "fabricmock" ,
"processor" : "fabricmock" ,
"method" : "CREDIT_CARD" ,
"methodType" : "VISA" ,
"state" : "CAPTURED" ,
"authorization" : {
"amount" : 500.0 ,
"expiry" : "" ,
"verifier" : {
"type" : "PAYMENT_TOKEN" ,
"key" : "{{payment_token}}"
}
}
} ,
"billToAddress" : "46622c9c-604c-4f8c-8bcf-2a393a572839" ,
"cardDetails" : null ,
"attributes" : {
"orderSource" : "ecommerce" ,
"expirationDate" : "0224" ,
"requestedDate" : "2022-01-27T16:15:58-05:00" ,
"paymentDate" : "2022-01-27T16:15:58-05:00" ,
"billToId" : "213321"
}
]
}
Adding payments with the AUTHORIZED
status to the cart
Use the create a payment endpoint to add AUHTORIZED
payments to the cart as in the following example:
Click to expand the curl and JSON response example.
curl --location '{{modular_cart_domain}}/carts/ba0e93f5-e47f-4b0d-bac8-6233b67ef65f/payments' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: {tenantId}' \
--header 'Authorization: {authToken}' \
--data '{
"provider": "fabricmock",
"processor": "fabricmock",
"method": "CREDIT_CARD",
"methodType": "VISA",
"state": "AUTHORIZED",
"authorization": {
"amount": 500.0,
"expiry": "",
"verifier": {
"type": "PAYMENT_TOKEN",
"key": "{{payment_token}}"
}
},
"billToAddress": "46622c9c-604c-4f8c-8bcf-2a393a572839",
"cardDetails": null,
"attributes": {
"orderSource": "ecommerce",
"expirationDate": "0224",
"requestedDate": "2022-01-27T16:15:58-05:00",
"paymentDate": "2022-01-27T16:15:58-05:00",
"billToId": "213321"
}
}
'
A successful response to carts/{cartId}/payments
provides a payments object as in the following example:
"payments" : {
"authorized" : 500.0 ,
"collection" : [
{
"provider" : "fabricmock" ,
"processor" : "fabricmock" ,
"method" : "CREDIT_CARD" ,
"methodType" : "VISA" ,
"state" : "AUTHORIZED" ,
"authorization" : {
"amount" : 500.0 ,
"expiry" : "" ,
"verifier" : {
"type" : "PAYMENT_TOKEN" ,
"key" : "{{payment_token}}"
}
}
} ,
"billToAddress" : "46622c9c-604c-4f8c-8bcf-2a393a572839" ,
"cardDetails" : null ,
"attributes" : {
"orderSource" : "ecommerce" ,
"expirationDate" : "0224" ,
"requestedDate" : "2022-01-27T16:15:58-05:00" ,
"paymentDate" : "2022-01-27T16:15:58-05:00" ,
"billToId" : "213321"
}
]
}