Webhooks and Errors
Receive and verify webhook events, handle API errors, send requests again safely, and recover a lost response.
Handle webhook events and API errors, send requests again safely, and recover after a timeout.
Webhooks
When a payout, beneficiary or customer changes status, Durianpay sends a signed event to your HTTPS URL.
Register one URL for each event type in the Durianpay dashboard, under Settings → Webhooks. The event body does not contain the event type. So the URL tells you which event arrived. Sandbox and production have separate URLs. See Step 2: Register your webhook URLs.
Events
| Event | When Durianpay sends it | additionalInfo | Reference |
|---|---|---|---|
global.payout.updated | Every payout status change. | status. For refunded, also refundAmount. For need_action, also action (coming soon). | Payout Notification |
global.beneficiary.updated | Every beneficiary status change. | status | Beneficiary Notification |
global.customer.updated | Every customer status change. | status | Customer Notification |
- Durianpay sends an event even when your own call caused the change. For example, you get an event after a
cancel. - You get
global.beneficiary.updatedeven when the response of the Create Beneficiary API already showsactive. - An event gives only the new status. For the details, call the Fetch by ID API of the resource. For example, to get the
failureof afailedpayout, call the Fetch Payout by ID API. - Durianpay sends no event when you create a payout. The response of the Create Payout API gives the first status,
processing. - Durianpay sends no event for screening or review (see Key terms). During screening or review, the payout stays
processing.
Each event is a POST with the SNAP headers of Durianpay's SNAP notifications. The body has the format of the Durianpay SNAP transfer notification. These are the fields that you use most:
| Field | Meaning |
|---|---|
originalReferenceNo | The referenceNo of the payout, beneficiary or customer. |
originalPartnerReferenceNo | Your partnerReferenceNo. It is not in the body when the resource has no partnerReferenceNo. |
additionalInfo.status | The new status. |
responseCode | Always 2000000. It does not give the status. |
Payout events also have amount, beneficiaryAccountNo, beneficiaryBankCode and sourceAccountNo. A refunded payout event also has refundAmount. The notification pages in the table above describe every header and field.
{
"originalReferenceNo": "orm_2m9x4h",
"originalPartnerReferenceNo": "merchant-tx-44821",
"responseCode": "2000000",
"responseMessage": "Request has been processed successfully",
"amount": {
"value": "9876.54",
"currency": "USD"
},
"beneficiaryAccountNo": "******1847",
"beneficiaryBankCode": "026009593",
"sourceAccountNo": "mer_8a7c2d",
"additionalInfo": {
"status": "completed"
}
}{
"originalReferenceNo": "par_7pq3m",
"originalPartnerReferenceNo": "bnf-acme-001",
"responseCode": "2000000",
"responseMessage": "Request has been processed successfully",
"additionalInfo": {
"status": "active"
}
}Verify each webhook
Verify X-SIGNATURE before you process an event. It is a SHA256withRSA signature (RSASSA-PKCS1-v1_5 with SHA-256) in standard base64. It signs a string of four parts, joined with ::
POST:<path>:<lowercase hex SHA-256 of the minified JSON body>:<X-TIMESTAMP>- Path: Use the path of your registered URL, without the host and the query string. An example is
/hooks/durianpay/payouts. - Body: Take the raw body. Remove each space, tab,
\rand\nthat is not inside a JSON string. Then calculate the hash. - No parsing: Do not parse the JSON and encode it again. This can change the escape sequences and the numbers.
- Timestamp: Use the
X-TIMESTAMPheader exactly as you receive it. Do not change its format. - Key: Use the Durianpay public key. Download it in the dashboard, under Settings → API Key. Sandbox and production have different keys.
Code examples in Python, Node.js and Go, and a test vector, are on Payout Notification.
Answer the webhook
- Verify
X-SIGNATURE. If the signature is not valid, do not process the event. Return HTTP 401. - Store or queue the event. Return HTTP 200 within 10 seconds.
- Then find the resource by
originalReferenceNo.originalPartnerReferenceNois not in every event. - Compare
additionalInfo.statuswith the status that you have. Then use the table below.
The event body has no event ID and no event time. The same event can arrive again, even with a valid signature. Events can also arrive in any order. X-EXTERNAL-ID changes on each retry, so you cannot use it to find a repeated event.
In the table, "read" means: call the Fetch by ID API of the resource. Use the Fetch Payout by ID API, Fetch Beneficiary by ID API or Fetch Customer by ID API.
| Case | What to do |
|---|---|
| The status in the event is different from your status. | The event can be old. Read the resource. Save the status from the response, not the status from the event. |
| The status in the event is the same as your status. | Read the resource. The event can be a repeat. It can also be a new change to the same status. |
You will act on the status. For example, you will replace a failed payout. | Read the resource first. Act on the status that you read. |
A failed or refunded payout does not change again. A completed payout can change only to refunded. So if your payout is failed or refunded, an event with another status is old.
Retries and missed events
Durianpay tries to send each event within five seconds of the change. If your server does not answer with HTTP 200 or 201 in time, Durianpay sends the event again.
The gaps between two attempts are 2, 5, 10, 90 and then 210 minutes. After the last retry, Durianpay stops the delivery of that event.
If you missed events, or an event does not come, read each resource with its Fetch by ID API. For payouts, you can also call the Fetch Payouts API.
Errors
For every code and its meaning, see Response Code Handling.
Error response format
Every response body has responseCode and responseMessage. An error body also has additionalInfo. It gives the details of the error.
responseCode has 7 digits:
| Part | Digits | Example in 4030014 |
|---|---|---|
| HTTP status | 3 | 403 |
| Service code | 2 | 00 (always 00) |
| Case code | 2 | 14 |
A successful call returns HTTP 200 with 2000000 (Successful).
The token request (POST /v1.0/access-token/b2b) is the exception. It keeps the codes of the Durianpay token endpoint. An example is 2007300, with the service code 73.
Reading an error response
Use additionalInfo to select your error handling. When additionalInfo has errors or code, do not use responseCode or the HTTP status.
Each error with a code has its own responseCode. But 4000002 can be a missing field or a missing SNAP header. The API also returns HTTP 404 for some refusals, such as AMOUNT_BELOW_MINIMUM and CANCEL_NOT_ALLOWED.
Read additionalInfo in this order:
| Order | What additionalInfo has | What to do |
|---|---|---|
| 1 | errors | This is a validation error. Read each entry. See Validation errors. |
| 2 | code | Use code. See Errors with a code. |
| 3 | Neither errors nor code | Handle it by its responseCode. The cause is an authentication error, a body that is not a valid JSON object (4000000), an unknown path (4040000), a wrong HTTP method (4050000), or an HTTP 5xx error. |
In an authentication error, additionalInfo has only trace_id. The response for an unknown client key has no additionalInfo. See Authentication errors. For an HTTP 5xx error, see Timeouts and 5xx responses.
Each error with a code has its own responseCode. For example:
responseCode | additionalInfo.code | What to do |
|---|---|---|
4030001 | FEATURE_NOT_ENABLED | Contact Durianpay support to enable the Global Payout API for your merchant account. |
4030024 | CORRIDOR_UNAVAILABLE | Call the List Corridors API. Use a corridor from the list. |
4030025 | CUSTOMER_NOT_ALLOWED | Your merchant account has a setup without customers. Do not create or update customers. Do not send customerReferenceNo. |
4030006 | QUOTE_TEMPORARILY_UNAVAILABLE | The error is retriable. See Retriable errors. |
4030027 | PAYOUT_TEMPORARILY_UNAVAILABLE | The error is retriable. See Retriable errors. |
4030026 | RATE_UNAVAILABLE | The error has no retriable field. Call the API without destinationCurrency to see the currencies that have a rate now. |
4030029 | BENEFICIARY_NOT_ACTIVE | Call the Fetch Beneficiary by ID API. Only an active beneficiary can receive a payout. |
4030028 | CUSTOMER_NOT_ACTIVE | Call the Fetch Customer by ID API. A payout accepts only an active customer. |
4030030 | PAYMENT_ACCOUNT_INACTIVE | The payment account is inactive. Use another payment account. |
4030018 | None | Your merchant account is inactive. Contact Durianpay support. |
Validation errors
additionalInfo.errors lists every field that fails. Each entry has code, field and action. An entry can also have pattern: the regular expression that the value must match.
responseCode is 4000002 when a field is missing. Otherwise it is 4000001. Every endpoint can return FIELD_MISSING (4000002) and FIELD_INVALID (4000001). This is true even when the error table of the endpoint does not list them.
{
"responseCode": "4000002",
"responseMessage": "Invalid Mandatory Field",
"additionalInfo": {
"errors": [
{
"code": "FIELD_MISSING",
"field": "accountDetails.accountHolderName",
"action": "Provide accountDetails.accountHolderName"
},
{
"code": "FIELD_INVALID",
"field": "accountDetails.accountNumber",
"action": "Use 1 to 34 characters",
"pattern": "^.{1,34}$"
}
]
}
}Errors with a code
additionalInfo.code is the name of the error, for example INSUFFICIENT_BALANCE. Use this name in your error handling.
Some codes add more fields to additionalInfo. For example, INSUFFICIENT_BALANCE adds required and available.
{
"responseCode": "4030014",
"responseMessage": "Insufficient Funds",
"additionalInfo": {
"code": "INSUFFICIENT_BALANCE",
"required": {
"value": "160015000.00",
"currency": "IDR"
},
"available": {
"value": "100000000.00",
"currency": "IDR"
}
}
}If you send a corridor that is not in the corridor list, the API returns CORRIDOR_UNAVAILABLE (4030024). Response Code Handling lists the calls that check the corridor. For the access rules, see Merchant scope and Feature access.
When the API checks the requirements
A success response to a create call does not mean that the requirements are metWhen you create a beneficiary, a payment account or a customer, the API checks only some fields. The API checks all the corridor requirements only when you create the payout.
Send the fields of the requirements when you create each resource, and when you create the payout. The base fields are the request body fields on the API Reference page of the endpoint.
| API | What the API checks |
|---|---|
| Create Beneficiary API | The base fields of the beneficiary, and the value of each beneficiary.fields field that you send. The API checks that each required field of beneficiary.fields is present when you create the payout. |
| Create Payment Account API | The account against paymentAccount.fields, for the same corridor, payout rail and beneficiary type. It does not check the beneficiary fields. |
| Update Payment Account API | The same uniqueness and corridor checks as the Create Payment Account API. |
| Create Customer API and Update Customer API | Only the base fields of the customer type (customerType). You can also send the values of the corridor's customer.fields. |
| Create Payout API | The beneficiary and its payment account again, and also the customer and the documents. The API uses the current requirements for the corridor, payout rail and beneficiary type of the quote. It also checks the payout request body against payout.fields. It ignores a payout field that payout.fields does not list. |
Fix a REQUIREMENTS_UNMET error
REQUIREMENTS_UNMET errorWhen you create the payout, the API can find a missing field or a missing document. Then it returns one REQUIREMENTS_UNMET (4030015) error. The error lists every missing field of the beneficiary, the payment account and the customer. It also lists every missing document.
{
"responseCode": "4030015",
"responseMessage": "Transaction Not Permitted",
"additionalInfo": {
"code": "REQUIREMENTS_UNMET",
"missingFields": [
{
"resource": "beneficiary",
"field": "mobileNumber"
},
{
"resource": "payment_account",
"field": "accountDetails.bankCode"
},
{
"resource": "customer",
"field": "sourceOfIncome"
}
],
"missingDocuments": [
{
"documentType": "COMMERCIAL_INVOICE"
}
]
}
}- The API did not create the payout. It did not use the quote.
missingFieldslists each missing field as{resource, field}.resourceisbeneficiary,payment_accountorcustomer.fieldis a dotted path, for exampleaccountDetails.bankCode. For a beneficiary, it is the path that the requirements show, for exampleaddress.country. In the requirements, akeyis never a dotted path.missingDocumentslists each missing supporting document as{documentType}.
missingFields never lists a field of the payout request body. A missing payout field gives a validation error, FIELD_MISSING (4000002). A bad value in a field that payout.fields lists gives FIELD_INVALID (4000001). Fix the payout request body and send it again. A payout field that payout.fields does not list gives no error: the API ignores it and does not store it.
To fix the error:
- Update each resource that
missingFieldsnames. An update replaces the full resource. So send the full create request body, with the missing fields added. If you omit an optional field, the API removes it.- For
beneficiary, use the Update Beneficiary API. - For
payment_account, use the Update Payment Account API. - For
customer, use the Update Customer API.
- For
- Upload each document in
missingDocuments. First send the document details with the Upload Document API. Then send the file to theuploadUrlin the response. When the document status isuploaded, send itsreferenceNoindocuments. See Send supporting documents. - Check that the beneficiary is
active. Some updates move it toprocessing. These are a change of the name, the beneficiary type or the country. A change of an identity or birth-date field that Durianpay screens also does this. A payout to aprocessingbeneficiary returnsBENEFICIARY_NOT_ACTIVE(4030029). In a setup with customers, the customer must also beactive. - Check the
expiresAtof the quote. If the quote expired, create a new quote. An expired quote givesQUOTE_EXPIRED(4030000). - Send the request to create the payout again, with the same
partnerReferenceNo. The API did not store the refused request. See Idempotency and repeated requests.
Retriable errors
A retriable error has retriable: true in additionalInfo. Other errors do not have this field.
additionalInfo.code | When you get it | What to do |
|---|---|---|
QUOTE_TEMPORARILY_UNAVAILABLE (4030006) | Durianpay cannot price the quote now. For example, no rate is available. | Send the call again later. |
PAYOUT_TEMPORARILY_UNAVAILABLE (4030027) | Durianpay cannot accept the payout now. It did not create the payout, and it did not use the quote. | Create the payout again later. Use the same quote before its expiresAt, or use a new quote. You can keep the same partnerReferenceNo, even with a new quote. |
{
"responseCode": "4030006",
"responseMessage": "Feature Not Allowed At This Time",
"additionalInfo": {
"code": "QUOTE_TEMPORARILY_UNAVAILABLE",
"retriable": true
}
}Timeouts and 5xx responses
A call can time out. It can also return HTTP 5xx, with a responseCode such as 5000000, 5000001 or 5040000. Then you do not know the result.
- When you create a payout, follow Recover a lost response.
- When you create another resource, follow Recover other create calls.
- For the other calls, see Idempotency and repeated requests.
Idempotency and repeated requests
A repeated request is a request that you send again. The API uses a key to find a repeated request:
| API | Key |
|---|---|
| Create Payout API | Your partnerReferenceNo |
| Create Beneficiary API | Your partnerReferenceNo |
| Create Customer API | Your partnerReferenceNo |
| Upload Document API, step 1 (create the document) | Your partnerReferenceNo |
| Create Payment Account API | The beneficiary, the payout rail and the account identifiers. The API page lists the account fields. |
Payout Action API (for example cancel), every call that deactivates a resource (DELETE), every GET call | No key. These calls are safe to send again. |
| Create Quote API | No key. The call is not safe to send again: each call creates a new quote. A quote does not debit your balance, and an unused quote expires. |
When the key matches an existing resource:
- Same request body: Durianpay does not create the resource again. You get the existing resource in its current status, with
additionalInfo.replayed: true. There is no time limit. - Same
partnerReferenceNo, another request body: You getPARTNER_REFERENCE_NO_CONFLICT(4090001), with thereferenceNoof the existing resource. For a payout, the error givespayoutReferenceNo. - Same payment account, other details: You get
PAYMENT_ACCOUNT_EXISTS(4090000), withpaymentAccountReferenceNo.
"Same request body" means the same fields with the same values. Field order and whitespace outside the values do not matter. An optional field that you omit is not the same as one that you send. A field that the create call ignores does not count.
Special cases:
| Case | Result |
|---|---|
You send the partnerReferenceNo of a rejected or inactive beneficiary or customer. | Always PARTNER_REFERENCE_NO_CONFLICT (4090001). Use a new partnerReferenceNo. |
| You send the details of an inactive payment account again. | The API creates a new payment account. An inactive account does not count. |
| You send the same account identifiers on another payout rail. | The API creates another payment account. |
| You send step 1 of the document upload again. | While the status is pending_upload, you get a new uploadUrl. The earlier link stops working. |
You use an uploadUrl that expired, or that you already used to upload a file (step 2). | ACTION_NOT_ALLOWED (4050001). An uploadUrl works for one successful upload. For a new link, send step 1 again while the status is pending_upload. |
You send a cancel that already applied. | You get the payout. There is no second status change and no second event. |
| You deactivate a resource again. | You get the inactive resource. |
A refused request stores nothing. When the API refuses a create request, send the corrected request with the same partnerReferenceNo. When the API refuses to create a payout, the quote stays unused. This is only for a refused request. After a payout becomes failed, use a new partnerReferenceNo for the new payout.
X-EXTERNAL-ID is not an idempotency key. Send a new X-EXTERNAL-ID value on every request, also on a repeated request.
Recover a lost response
Use these steps when a call that creates a resource times out or returns HTTP 5xx.
Do not create the resource again with a newpartnerReferenceNoThe first request can still complete after the error. While you do not know the result, follow the steps below. A payout with the status
processingcan still becomecompleted. Do not create a new payout to replace it.
To recover a payout:
- Read the payout. Call the Fetch Payout by ID API. Use the
quoteReferenceNothat you sent as thereferenceNo, because a payout has thereferenceNoof its quote. You can also call the Fetch Payout by Reference API with yourpartnerReferenceNo. - Act on the result. Use the table below.
- Track the payout. Follow its
global.payout.updatedevents, or call the Fetch Payout by ID API. See Webhooks.
| Result | What to do |
|---|---|
| HTTP 200 with the payout | Durianpay created the payout. Track that payout. If it is failed, its status does not change again. Then create a new quote and a new payout with a new partnerReferenceNo. |
RESOURCE_NOT_FOUND (4040001) | No payout uses the quote yet. Send the original request to the Create Payout API again. Use the same partnerReferenceNo and the same request body. |
The request that you sent again returns an error, for example QUOTE_EXPIRED (4030000) | The API stored nothing and did not use the quote. Fix the cause. For an expired quote, create a new quote. Then send the corrected request with the same partnerReferenceNo. |
The first request can still complete after you read the payout. So keep the same partnerReferenceNo. If your new request creates the payout, you get the new payout. If the first request created it, you get that payout with additionalInfo.replayed: true. In both cases, there is only one payout.
Recover other create calls
When you create a beneficiary, a customer or a payment account, send the same request again. Do the same for step 1 of the document upload. Use the same key and the same request body. The key of each call is in Idempotency and repeated requests. You get the new resource, or the existing one with additionalInfo.replayed: true.
Step 2 of the document upload is the file upload to the uploadUrl. If you do not get its response, call the Fetch Document by ID API. Then read the status:
status | What to do |
|---|---|
uploaded | Durianpay has the file. Send the referenceNo of the document in the payout. |
pending_upload | Durianpay does not have the file. Send the file to the uploadUrl again. If the link expired, send step 1 again with the same partnerReferenceNo and the same request body. The response has a new uploadUrl. |
Compatibility
Build your client to follow these rules:
- Accept new response fields, and new enum values where the pages say so. Ignore the response fields that you do not know.
- Accept unknown webhook events, and ignore them.
- Durianpay can add failure codes. If your client does not know a
failure.code, the payout isfailedand final. Do not create a new payout automatically. Contact Durianpay support. See Response Code Handling. - Send only the request fields that the endpoint documents.
A breaking change of the API needs a new version prefix.
Updated about 14 hours ago
