Skip to main content

Cart Calculation and Committing Payment

danger

This step (especially the cart commitment step) can potentially process real payments and charge the customer. Ensure that you have the customer's consent before proceeding. Also double check if your operating on a dev or production environment.

Overview

Once you have the payment data and the customer's payment information, you can now proceed to the checkout part with two steps: getting the cart cost and committing the payment. This guide will walk you through the process of getting the cart cost and committing the payment using the NGnair Payments API.

Pre-requisites

  1. Account setup, onboarded merchant account and API keys. If you don't have these, follow the steps in the API Keys guide.
  2. Payment data object. If you don't have one, follow the steps in the Creating Payment Data guide.
  3. Customer's payment information. If you don't have this, follow the steps in the Tokenizing Payment Information guide.

Getting Cart Cost

API Request

Get Cart Cost - Request (curl)
curl -X 'POST' \
'https://demo-be.ngnair.com/api/gateway/computeTokenizedCheckout' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"groupID": "MID-840-04-2025-000003",
"token": "b2e1bee9-db0b-4d0a-96b5-1bb8193e69c4",
"data": {
"paymentData": "U2FsdGVkX1+gyTpC1+sebSC2Rj8+Yc7Kd0gn//83iElTmkrISvdwE3hgpSZOTgRhiGSpIug7LOMAZ//Vt/oFA44eSToo9wrcURcfthBDd0Tt0w4ylVs2vkwRAQRpOKN540dChMRlYPzJTVYmPYNt572wbIdp99ZpHz8qUxxzxrlQC7n6c6N3pw1YRgWEaW9pRHk7viTR+DqyETgaV3es2ah5VRL+UiALeWfHOL8NKL9qFiKuZTUUolvCOUURZH+zG8QFqjD+DKNiGID53+Tj3Q/WWqBI1hIl+iFWom2AYAUXnijttKrX7U4yNZIVqTsF/fPR98nU90m8iHHKcP40Jc4U9pnKlNqJ5j74jTa/Scc5rvnRyvmk11BLvLiQHk1hTaaPBYaqXTlzVAG14skGo/8XjxvDSIXhOYOFg74sB7j9JKZhzdp3Xb3Ap0vg6KG62j08+LqjnLC003TICq2VgvpJHakvlVg9b/GwEB9jqvihuROc13a2wXzdoO4PLwyb10C2ntkXQr0eAzGE2EqHwNGGnJ5ne/iY0TVYXjaG9CnOrMgTYclGrwksSv4uCs1XkLyvKsgGphPsY6Uesx4KhemOfnYGDRBQEgs19vcYv2fZqQFzXpa1H04eRDmf3cU5/svyL9DsfQB6rB7hmETXmj90qOKA/MdfplqsWQJgwRQ1ZSCA9QrTEkSONjP2Ae57",
"dynamicData": {
"paymentType": "card"
}
}
}'
  • groupID: Your merchant identifier
  • token: The payment token received from the tokenization step
  • data:
    • paymentData: Encrypted payment information string
    • dynamicData: Additional data for cart calculation
      • paymentType: Payment method used (card, ach). This could be important as card and ach payments may have different surcharges and fees.

API Response

Get Cart Cost - Response
{
"breakdown": {
"subtotal": 2999,
"discount": 0,
"tax": 299,
"shipping": 500,
"fees": 0,
"tip": 0,
"total": 3798
},
"lineItems": [
{
"product": {
"sku": "TSHIRT-001",
"name": "Premium T-Shirt",
"description": "100% Cotton T-Shirt",
"price": 2999
},
"amount": 1,
"total": 2999
}
],
"discountBreakdown": [],
"allowEdit": true,
"allowExtraDiscount": false,
"allowTip": true,
"referenceID": "ORDER123",
"onSuccessUrl": "https://your-store.com/success",
"onFailureUrl": "https://your-store.com/failed"
}

The response contains detailed cost breakdown and cart information:

Breakdown Object:

  • subtotal: Base cost of items before tax/shipping (in cents)
  • discount: Applied discount amount (in cents)
  • tax: Calculated tax amount (in cents)
  • shipping: Shipping cost (in cents)
  • fees: Additional fees (in cents)
  • tip: Tip amount (in cents)
  • total: Final total including all charges (in cents)

Line Items Array: Each line item contains:

  • product: Product details including SKU, name, description, and price
  • amount: Quantity ordered
  • total: Total cost for this line item

Additional Fields:

  • allowEdit: Whether the cart can be modified
  • allowExtraDiscount: Whether additional discounts can be applied
  • allowTip: Whether tipping is enabled
  • referenceID: Your order reference number
  • onSuccessUrl: Redirect URL for successful payment
  • onFailureUrl: Redirect URL for failed payment

Passing dynamic values to cart cost

Get Cart Cost - Request (curl)
curl -X 'POST' \
'https://demo-be.ngnair.com/api/gateway/computeTokenizedCheckout' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"groupID": "MID-840-04-2025-000003",
"token": "b2e1bee9-db0b-4d0a-96b5-1bb8193e69c4",
"data": {
"paymentData": "U2FsdGVkX1+gyTpC1+sebSC2Rj8+Yc7Kd0gn//83iElTmkrISvdwE3hgpSZOTgRhiGSpIug7LOMAZ//Vt/oFA44eSToo9wrcURcfthBDd0Tt0w4ylVs2vkwRAQRpOKN540dChMRlYPzJTVYmPYNt572wbIdp99ZpHz8qUxxzxrlQC7n6c6N3pw1YRgWEaW9pRHk7viTR+DqyETgaV3es2ah5VRL+UiALeWfHOL8NKL9qFiKuZTUUolvCOUURZH+zG8QFqjD+DKNiGID53+Tj3Q/WWqBI1hIl+iFWom2AYAUXnijttKrX7U4yNZIVqTsF/fPR98nU90m8iHHKcP40Jc4U9pnKlNqJ5j74jTa/Scc5rvnRyvmk11BLvLiQHk1hTaaPBYaqXTlzVAG14skGo/8XjxvDSIXhOYOFg74sB7j9JKZhzdp3Xb3Ap0vg6KG62j08+LqjnLC003TICq2VgvpJHakvlVg9b/GwEB9jqvihuROc13a2wXzdoO4PLwyb10C2ntkXQr0eAzGE2EqHwNGGnJ5ne/iY0TVYXjaG9CnOrMgTYclGrwksSv4uCs1XkLyvKsgGphPsY6Uesx4KhemOfnYGDRBQEgs19vcYv2fZqQFzXpa1H04eRDmf3cU5/svyL9DsfQB6rB7hmETXmj90qOKA/MdfplqsWQJgwRQ1ZSCA9QrTEkSONjP2Ae57",
"dynamicData": {
"discountCodes": [],
"paymentType": "card",
"tip": {
"amount": 10,
"type": "percentage"
},
"quantityAmounts": [
{
"id": "TSHIRT-001",
"quantity": 10
}
]
}
}
}'

The dynamicData object allows runtime modifications:

  • paymentType: Payment method used (card, ach)
  • discountCodes: Array of discount codes to apply
  • tip:
    • amount: Tip value
    • type: Tip calculation method (percentage or fixed)
  • quantityAmounts: Array of items with quantities to modify
    • id: Product SKU
    • quantity: New quantity
Get Cart Cost - Response
{
"breakdown": {
"subtotal": 29990,
"discount": 0,
"tax": 299,
"shipping": 500,
"fees": 0,
"tip": 2999,
"total": 33788
},
"lineItems": [
{
"product": {
"sku": "TSHIRT-001",
"name": "Premium T-Shirt",
"description": "100% Cotton T-Shirt",
"price": 2999
},
"amount": 10,
"total": 29990
}
],
"discountBreakdown": [],
"allowEdit": true,
"allowExtraDiscount": false,
"allowTip": true,
"referenceID": "ORDER123",
"onSuccessUrl": "https://your-store.com/success",
"onFailureUrl": "https://your-store.com/failed"
}

Committing Payment

danger

This step will process the payment and charge the customer. Ensure that you have the customer's consent before proceeding. Also double check if your operating on a dev or production environment.

API Request

Commit Payment - Request (curl)
curl -X 'POST' \
'https://demo-be.ngnair.com/api/gateway/createTokenizedManualEntry' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"groupID": "MID-840-04-2025-000003",
"token": "b2e1bee9-db0b-4d0a-96b5-1bb8193e69c4",
"data": {
"paymentData": "U2FsdGVkX1+gyTpC1+sebSC2Rj8+Yc7Kd0gn//83iElTmkrISvdwE3hgpSZOTgRhiGSpIug7LOMAZ//Vt/oFA44eSToo9wrcURcfthBDd0Tt0w4ylVs2vkwRAQRpOKN540dChMRlYPzJTVYmPYNt572wbIdp99ZpHz8qUxxzxrlQC7n6c6N3pw1YRgWEaW9pRHk7viTR+DqyETgaV3es2ah5VRL+UiALeWfHOL8NKL9qFiKuZTUUolvCOUURZH+zG8QFqjD+DKNiGID53+Tj3Q/WWqBI1hIl+iFWom2AYAUXnijttKrX7U4yNZIVqTsF/fPR98nU90m8iHHKcP40Jc4U9pnKlNqJ5j74jTa/Scc5rvnRyvmk11BLvLiQHk1hTaaPBYaqXTlzVAG14skGo/8XjxvDSIXhOYOFg74sB7j9JKZhzdp3Xb3Ap0vg6KG62j08+LqjnLC003TICq2VgvpJHakvlVg9b/GwEB9jqvihuROc13a2wXzdoO4PLwyb10C2ntkXQr0eAzGE2EqHwNGGnJ5ne/iY0TVYXjaG9CnOrMgTYclGrwksSv4uCs1XkLyvKsgGphPsY6Uesx4KhemOfnYGDRBQEgs19vcYv2fZqQFzXpa1H04eRDmf3cU5/svyL9DsfQB6rB7hmETXmj90qOKA/MdfplqsWQJgwRQ1ZSCA9QrTEkSONjP2Ae57",
"dynamicData": {
"discountCodes": [],
"paymentType": "card",
"tip": {
"amount": 10,
"type": "percentage"
},
"quantityAmounts": [
{
"id": "TSHIRT-001",
"quantity": 10
}
]
},
"customerInfo": {
"nameOnCard": "John Doe",
"email": "john@doe.com",
"billingAddress": "30000 Mill Creek Ave",
"billingCity": "Alabaster",
"billingState": "AL",
"billingZip": "35007",
"billingCountry": "US",

// For card payments
"paymentType": "card",
"card": {
"cardToken": "3jniPrFbzZTt1111",
"cvc": "111",
"expiryDate": "11/26"
}

// For ACH payments
# "paymentType": "card",
# "card": {
# "accountNumber": "ey5sa5d...",
# "routingNumber": "111111111",
# "accountType": "CHECKING",
# "accountHolderType": "PERSONAL"
# },
}
}
}'

Response

Commit Payment - Response
{
"transactionID": "P-840-2025-00000149",
"status": "CAPTURED"
}

Dashboard View

Committed Payment