Set up composable tender refunds

Ask about this Page
Copy for AI
View as Markdown

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

  1. Build and deploy a custom module. If you already use a custom module for checkout payments, you can reuse it. See Build the module.
  2. Create a payment processor with integrationConfiguration.type set to Custom. Set integrationConfiguration.url to the URL of your module's remote entry file, and integrationConfiguration.module to the exposed module key, such as ./Component.
  3. Create a payment option with method set to Custom, and with paymentProcessorId set to the processor that you created.
  4. In the refund object, reference the payment option in refunds[].paymentOption, or in refunds[].fallbackRefundTypes[].paymentOption to offer it as a fallback.
Sample Create Payment Processor request body: Customjson
{
  "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.
Sample instruction for a composable tender refundjson
{
  "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

  1. The store associate reviews the refund plan and presses Next.
  2. InStore shows the refund prompt for the refund instruction, using the metaData that you sent. The associate presses Next to start the refund.
  3. InStore loads your module and passes it the module properties. In its prompt area, InStore shows the Refund.promptMessageCustom string, which defaults to Complete the refund using the form below.
  4. Your module processes the refund, then calls either finishPayment or cancelPayment.
    • After finishPayment, InStore records a Custom tender 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.
  5. 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.

PropertyData typeDescription
transactionTypeStringAlways refund for a composable tender refund.
cartKeyStringThe key of the return Cart from the refund object, or its id when the refund object referenced the Cart by id.
amountDueObjectThe amount to refund for this refund instruction, as a Dinero.js object. Positive.
amountRequestedObjectThe same amount as amountDue.
tenantKeyStringIdentifies the tenant.
locationKeyStringThe key of the location.
workstationKeyStringThe key of the workstation.
processStringThe integrationConfiguration.process value of the payment processor. Absent when you didn't set one.
finishPaymentFunctionCall it when the refund succeeds. See Report a successful refund.
cancelPaymentFunctionCall it when the refund fails or the store associate abandons it. InStore ignores any arguments.
showBackButtonFunctionCall 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.
Sample finishPayment callJavascript
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',
  },
});
FieldData typeDescription
resultStringSuccess. Call finishPayment only when the refund succeeded. To report a failure, call cancelPayment instead.
data.methodStringOptional. InStore records it as the payment method of the tender.
data.cartKey, data.processor, data.amountVariousOptional. 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 dataAnyInStore 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.
Sample refund transaction for a Custom tenderjson
{
  "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"
    }
  }
}
FieldData typePresenceDescription
tenderInformation.typeStringRequiredAlways Custom for a composable tender refund.
tenderInformation.tenderItemIdStringRequiredThe internal identifier of the InStore tender.
tenderInformation.paymentObjectOptionalA reference to the original commercetools Payment from the refund instruction's originalCTPayment. Absent when the refund instruction has no originalCTPayment.
tenderInformation.customObjectOptionalThe 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 keyDefault text (en-US)
Refund.promptMessageCustomComplete the refund using the form below.
Refund.CustomCustom
Refund.Custom is the label for the Custom payment method on the refund screens.