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:

Prerequisites

Before you initiate a payment, ensure you have completed the following:

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

ParameterDescription
amountThe amount to debit from the user.
merchantReferenceYour 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.

StatusDescriptionAction
PENDINGThe 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.
DECLINEDThe 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.
ERRORA 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

ParameterDescription
amountThe amount to credit to the user.
merchantReferenceYour 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.

StatusDescriptionAction
AUTHORIZEDThe payout request is accepted.Deduct the funds from the user's balance in your system and wait for the Completed webhook.
DECLINED/ERRORThe 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 StatusError CodeDescriptionAction
FailedSW057 / 326Expired split tokenSee Handle Events and Authorization Refresh.
FailedSW051 / 380Invalid / corrupt split tokenSee Handle Events and Authorization Refresh.
FailedSW056 / 330Invalid accountRemove the bank account from the user's profile. Prompt the user to add a new payment method.
FailedSW054 / 390Fraud analysisPrompt the user to use a different payment method. If a thirdPartyDeclineCode is provided, direct the user to the supplier.
FailedSW055 / 390Fraud analysis (Negative Data)Remove the bank account from the user's profile. Prompt the user to add a new payment method.
FailedSW052 / 378Internal error or bank request errorShow a generic error message and allow the user to try again.
DeniedSW021 / 331Not enough balancePrompt the user to check their balance or use another payment method.