Process refunds to a custom tender through an external module that you build, with InStore recording only the result.
How composable tender refunds work
A composable tender refund is a refund that your own module processes inside the InStore POS. InStore loads the module, gives it the refund amount, and waits for the module to report success or cancellation. How the module issues the refund, and which services it calls, is up to you: InStore doesn't call a payment processor endpoint for these refunds.
Use composable tender refunds for tenders that the built-in refund types don't cover, such as store credit, rebates, or trade-in credit. Composable tender refunds use the
Custom payment type.Composable tender refunds use the same refund session and webhooks as delegated refunds. This page describes only what's different for a
Custom tender. Set up delegated refunds before setting up composable tender refunds.Set up a composable tender refund
- Build and deploy a custom module. If you already use a custom module for checkout payments, you can reuse it. See Build the module.
- Create a payment processor with
integrationConfiguration.typeset toCustom. SetintegrationConfiguration.urlto the URL of your module's remote entry file, andintegrationConfiguration.moduleto the exposed module key, such as./Component. - Create a payment option with
methodset toCustom, and withpaymentProcessorIdset to the processor that you created. - In the refund object, reference the payment option in
refunds[].paymentOption, or inrefunds[].fallbackRefundTypes[].paymentOptionto offer it as a fallback.
{
"key": "processor-store-credit-1",
"name": {
"en-US": "Store credit"
},
"integrationConfiguration": {
"type": "Custom",
"url": "https://modules.example.com/store-credit/remoteEntry.js",
"module": "./Component",
"process": "store-credit"
}
}
integrationConfiguration.process is optional. InStore doesn't interpret it, and passes it to your module as the process property. Use it to run different flows from one module.{
"refundAmount": { "amount": 1500, "currency": "USD" },
"paymentOption": { "typeId": "paymentOption", "key": "option-store-credit-us-1" },
"order": { "typeId": "order", "key": "order-1" },
"originalCTPayment": { "typeId": "payment", "id": "pay_3Nk82jLkQ4eR1mWx" },
"metaData": {
"prompt": "Refund will be made to store credit",
"promptInfo": "Store credit: -$15.00"
}
}
A composable tender refund can also be unreferenced. In that case, leave out
order and originalCTPayment.How a composable tender refund runs
- The store associate reviews the refund plan and presses Next.
- InStore shows the refund prompt for the refund instruction, using the
metaDatathat you sent. The associate presses Next to start the refund. - InStore loads your module and passes it the module properties. In its prompt area, InStore shows the
Refund.promptMessageCustomstring, which defaults toComplete the refund using the form below. - Your module processes the refund, then calls either
finishPaymentorcancelPayment.- After
finishPayment, InStore records aCustomtender against the refund session and continues with the next refund instruction. - After
cancelPayment, InStore treats the attempt as failed, the same as a refund that your payment processor declines.
- After
- When every refund instruction is complete, InStore finalizes the refund session and sends the finalize refund webhook and the receipt data request.
InStore doesn't send a refund webhook to your processor for a
Custom tender, and doesn't create or update a commercetools Payment or Transaction for it. Your module or your own services are responsible for issuing the refund and for any updates to commercetools.Build the module
InStore loads the module that you configured on the payment processor object, with the same webpack Module Federation setup as a checkout custom payment module. The module must use the remote name
InStore_CustomPayment. For the full configuration, see Composable tender extension.If one module handles both checkout payments and refunds, read
transactionType to tell them apart: InStore sets it to refund for a refund, and doesn't send it for a checkout payment.Module properties
InStore passes the following properties to your module's exposed component.
| Property | Data type | Description |
|---|---|---|
transactionType | String | Always refund for a composable tender refund. |
cartKey | String | The key of the return Cart from the refund object, or its id when the refund object referenced the Cart by id. |
amountDue | Object | The amount to refund for this refund instruction, as a Dinero.js object. Positive. |
amountRequested | Object | The same amount as amountDue. |
tenantKey | String | Identifies the tenant. |
locationKey | String | The key of the location. |
workstationKey | String | The key of the workstation. |
process | String | The integrationConfiguration.process value of the payment processor. Absent when you didn't set one. |
finishPayment | Function | Call it when the refund succeeds. See Report a successful refund. |
cancelPayment | Function | Call it when the refund fails or the store associate abandons it. InStore ignores any arguments. |
showBackButton | Function | Call it with true to show a Back button in the InStore POS, and with false to hide it. When the store associate presses Back, InStore calls cancelPayment. |
Report a successful refund
Call
finishPayment with an object in the following format, and wait for the returned promise to settle.await finishPayment({
result: 'Success',
data: {
cartKey,
processor: 'processor-store-credit-1',
method: 'Store credit',
amount: { amount: 1500, currency: 'USD', precision: 2 },
creditAccountId: 'sc-55102',
approvalCode: 'A-123',
},
});
| Field | Data type | Description |
|---|---|---|
result | String | Success. Call finishPayment only when the refund succeeded. To report a failure, call cancelPayment instead. |
data.method | String | Optional. InStore records it as the payment method of the tender. |
data.cartKey, data.processor, data.amount | Various | Optional. Accepted for compatibility with checkout custom payment modules. InStore doesn't store these values. InStore records the amount from the refund instruction, not data.amount. |
Any other key in data | Any | InStore stores every other key unchanged in the tender's custom object, and reports it back to you in the finalize refund webhook and the receipt data request. In the sample above, custom is { "creditAccountId": "sc-55102", "approvalCode": "A-123" }. |
Changes to the payloads that InStore sends you
Finalize refund webhook
A composable tender refund appears in the finalize refund webhook with a
Custom tenderInformation block.{
"paymentOption": { "typeId": "paymentOption", "id": "option-store-credit-us-1" },
"amount": { "currencyCode": "USD", "centAmount": 1500, "fractionDigits": 2 },
"originalRefundTransactionId": "pay_3Nk82jLkQ4eR1mWx",
"tenderInformation": {
"type": "Custom",
"tenderItemId": "6a3c091003353f78bbe2c094",
"payment": { "typeId": "payment", "id": "pay_3Nk82jLkQ4eR1mWx" },
"custom": {
"creditAccountId": "sc-55102",
"approvalCode": "A-123"
}
}
}
| Field | Data type | Presence | Description |
|---|---|---|---|
tenderInformation.type | String | Required | Always Custom for a composable tender refund. |
tenderInformation.tenderItemId | String | Required | The internal identifier of the InStore tender. |
tenderInformation.payment | Object | Optional | A reference to the original commercetools Payment from the refund instruction's originalCTPayment. Absent when the refund instruction has no originalCTPayment. |
tenderInformation.custom | Object | Optional | The keys that your module passed in finishPayment data, apart from cartKey, processor, method, and amount. |
Receipt data request
In the receipt data request, the tender appears in
data.tenderItems[] with tender_type set to Custom. It also carries payment_method, with the data.method value from your module, and custom, with the same object as in the finalize refund webhook. Either field is absent when your module didn't supply it.Customize text strings
You can override the following strings for composable tender refunds. For more information, see Override core strings.
| String key | Default text (en-US) |
|---|---|
Refund.promptMessageCustom | Complete the refund using the form below. |
Refund.Custom | Custom |
Refund.Custom is the label for the Custom payment method on the refund screens.