You can control when Payments are captured, canceled, or refunded by using the Checkout Payment Intents API. Although Checkout handles Payment authorization and creates Orders, you must implement the business logic for triggering captures, cancellations, and refunds based on your fulfillment workflow.
This page covers the key Payment lifecycle operations that you need to implement and the actions that Checkout handles automatically.
Key lifecycle operations
The Payment lifecycle consists of the following important operations:
Refund
Refunds become necessary when you need to return captured funds to Customers. This can occur due to the following scenarios:
- Customer returns
- Damaged or incorrect goods received
- Other situations requiring reimbursement
refundPayment action.import { checkoutApiRoot } from "./apiClient.js";
async function refundPayment(paymentId, amount) {
try {
const response = await checkoutApiRoot
.paymentIntents()
.withPaymentId({ paymentId })
.post({
body: {
actions: [
{
action: "refundPayment",
amount,
},
],
},
})
.execute();
console.log("Payment refunded successfully:", response.body);
return response;
} catch (error) {
console.error("Failed to refund payment:", error.message);
throw error;
}
}
// Refund €20.00 for returned item (original order was €50.00)
await refundPayment(
order.paymentInfo.payments[0].id,
{centAmount: 2000, currencyCode: "EUR"} // €20.00
);
Automated reversals
Checkout lets you set predicates to define conditions for automatically canceling or refunding a Payment if the Order creation fails.
true, then the Automated Reversal is processed for the relevant Payment.Requirements to implement business logic
Checkout creates the Order and manages the Payment lifecycle, including updating the Payment record with transactions and Payment status.
You must implement the business logic for the following:
-
Managing
orderStatetransitions: Checkout doesn't update theorderStatefield. You can determine when to transition Orders betweenOpen,Confirmed,Complete, orCanceledStates based on your fulfillment workflow. -
Triggering payment captures: decide when to capture authorized Payments, such as when Inventory is allocated, Order is picked, or shipment is dispatched.
-
Handling cancellations and refunds: implement the logic to cancel authorizations or issue refunds in response to business events like Order cancellation and returns processing.
-
Reconciliation and monitoring: track Payment States, handle failed transactions, and implement retry logic for transient failures.
The following table shows how Payment fields in Composable Commerce map to the Merchant Center Payment UI:
| Composable Commerce Payment field | Merchant Center Payment UI |
|---|---|
interfaceId | Payment provider ID |
transactions[0].id | Transaction ID in Transactions list |
transactions[0].interactionId | Interaction ID in Transactions list |
interfaceId).
In the Transactions list, the Interaction ID displays the reference returned by the PSP for that specific operation. Depending on the PSP's logic, this value may match the Payment Provider ID (common for Authorizations) or differ for subsequent operations like Charges or Refunds.The following example shows a complete workflow that combines Payment capture with Order State management:
import { apiRoot } from "./apiClient.js"; // Your Composable Commerce API client
async function confirmOrderAfterCapture(orderId, version) {
const order = await apiRoot
.orders()
.withId({ ID: orderId })
.post({
body: {
version: version,
actions: [
{
action: "changeOrderState",
orderState: "Confirmed",
},
],
},
})
.execute();
return order.body;
}
// Workflow: Capture payment, then update orderState
try {
// 1. Capture the payment
await capturePayment(
order.paymentInfo.payments[0].id,
{ centAmount: 5000, currencyCode: "EUR" }
);
// 2. Update orderState to Confirmed
await confirmOrderAfterCapture(order.id, order.version);
console.log("Order confirmed and payment captured");
} catch (error) {
console.error("Failed to capture payment or update order", error);
// Implement your error handling and retry logic
}
Key takeaways
- Checkout authorizes Payments and creates Orders, but you can control when Payments are captured by using the Checkout Payment Intents API.
- Use manual capture to align Payment capture with your fulfillment workflow, such as when Inventory is allocated or the shipment is dispatched.
- Cancel authorizations by using the
cancelPaymentaction when Orders are canceled before capture. - Issue full or partial refunds by using the
refundPaymentaction for returns or other refund scenarios. - Configure Automated Reversal predicates to automatically cancel or refund Payments if Order creation fails.
- You are responsible for managing
orderStatetransitions—Checkout doesn't update this field. - Implement error handling and retry logic for Payment operations to handle transient failures.
- Track Payment States and reconcile transactions between Checkout, your PSP, and your Order management system.