Process Payments
Once you have a valid Bank Authorization, use the Trustly Transaction APIs to initiate Payments and Withdrawals.
In addition to the Trustly APIs discussed here, Trustly offers the following APIs that you can use to process payment transactions:
- Refund Transaction: Use to refund a previously completed Capture transaction.
- Reclaim Transaction: Use to refund a previously completed Deposit transaction.
- Cancel Transaction: Use to cancel a previously authorized Bank Authorization or unsettled Capture transaction.
Prerequisites
Before you initiate a payment, ensure you have completed the following:
- Bank Authorization: You must have a valid
transactionIdfrom a successful bank authorization. See Create a Bank Authorization. - Event Listener: You should have a webhook listener configured to receive asynchronous status updates (see Handle Event Notifications).
Payins (capture)
Use the Capture API to request a transfer of funds from the user's bank account to your merchant account.
Send the request
Execute a POST request to the capture endpoint (/transactions/{transactionId}/capture), where {transactionId} is the ID from the original bank authorization. For example:
curl -X POST https://sandbox.trustly.one/api/v1/transactions/{transactionId}/capture \
-H "Content-Type: application/json" \
-d '{
"amount": "10.00",
"merchantReference": "9ce392f7-f99b-41e9-9028-3f33c8b0a46e"
}'Request parameters
| Parameter | Description |
|---|---|
amount | The amount to debit from the user. |
merchantReference | Your unique identifier for this order. For example, the Order ID. This value persists in all event notifications and reports . |
Handle the response
The following table outlines the immediate response statuses returned by the Capture API and the required actions for each.
| Status | Description | Action |
|---|---|---|
| PENDING | The transaction was accepted and is processing. | Record the pending transaction in your system. Do not assume funds are guaranteed yet. Wait for the asynchronous webhook to confirm final settlement. A PENDING transaction triggers an Authorized event notification. You will receive additional notifications as the transaction processes. For a complete list of statuses and transitions, see Status codes and type definitions. |
| DECLINED | The transaction was rejected due to a risk assessment, NSF, or other reason. | Display an error to the user and ask for an alternative payment method. |
| ERROR | A technical error occurred. | Log the error and retry the request. |
Example capture response (abbreviated)
{
"transaction": {
"transactionId": "1002636615",
"transactionType": 3,
"status": 1,
"statusMessage": "Pending",
"payment": {
"paymentId": "1002636591",
"paymentType": 2,
"merchantReference": "123123"
},
"amount": "10.00",
"pending": "10.00"
}
}Payouts (deposit)
Use the Deposit API to transfer funds (withdrawal or refund) to the user's bank account.
Send the request
Execute a POST request to the deposit endpoint (/transactions/{transactionId}/deposit). For example:
curl -X POST https://sandbox.trustly.one/api/v1/transactions/{transactionId}/deposit \
-H "Content-Type: application/json" \
-d '{
"amount": "25.00",
"merchantReference": "5b83cfe7-b43c-4a6a-aec3-e483876a908a"
}'Request parameters
| Parameter | Description |
|---|---|
amount | The amount to credit to the user. |
merchantReference | Your unique identifier for this payout. |
Handle the response
Like captures, deposits are asynchronous. The API immediately returns AUTHORIZED if the request is valid, but the actual movement of funds takes 1-3 banking days.
The following table outlines the immediate response statuses returned by the Deposit API and the required actions for each.
| Status | Description | Action |
|---|---|---|
| AUTHORIZED | The payout request is accepted. | Deduct the funds from the user's balance in your system and wait for the Completed webhook. |
| DECLINED/ERROR | The request failed. | Do not deduct funds. Notify the user. |
Example deposit response (abbreviated)
{
"transaction": {
"transactionId": "1002636638",
"transactionType": 6,
"status": 2,
"statusMessage": "Authorized",
"amount": "25.00"
}
}Error codes
The following table lists the error codes you may encounter during Payin or Payout requests.
For detailed user messaging recommendations for each error code, see Status codes and type definitions.
| Transaction Status | Error Code | Description | Action |
|---|---|---|---|
| Failed | SW057 / 326 | Expired split token | See Handle Events and Authorization Refresh. |
| Failed | SW051 / 380 | Invalid / corrupt split token | See Handle Events and Authorization Refresh. |
| Failed | SW056 / 330 | Invalid account | Remove the bank account from the user's profile. Prompt the user to add a new payment method. |
| Failed | SW054 / 390 | Fraud analysis | Prompt the user to use a different payment method. If a thirdPartyDeclineCode is provided, direct the user to the supplier. |
| Failed | SW055 / 390 | Fraud analysis (Negative Data) | Remove the bank account from the user's profile. Prompt the user to add a new payment method. |
| Failed | SW052 / 378 | Internal error or bank request error | Show a generic error message and allow the user to try again. |
| Denied | SW021 / 331 | Not enough balance | Prompt the user to check their balance or use another payment method. |
Updated 4 days ago