On-File Transactions

Trustly can be used to allow a user to store an Online Banking account on file. You can then use that on-file account to initiate Payments and Withdrawals in your system as needed. There are 5 pieces required for this use case:

  1. Create a Bank Authorization using Online Banking. Implement the Trustly Online Banking interface to allow a User to authenticate with their Bank and authorize you to use that bank for payment transactions. This returns a transactionId and splitToken that you will store on the User's account in your system as a method of payment.
  2. Display Bank or User PII from Trustly. With a valid transactionId, use the Trustly Get Transaction and Get Financial Institution User API to retrieve information from the User's selected bank to display or pre-fill fields on your site or application.
  3. Create a Transaction from the Bank Authorization. When the User requests to make a payment, use the Trustly Capture API, passing the previously obtained transactionId, splitToken, amount, and merchantReference. When a User requests to make a withdrawal, use the Trustly Deposit API, passing the previously obtained transactionId, amount, and merchantReference.
  4. Handle Event Notifications. The payment transaction returns a PENDING or ERROR response. Implement Trustly Event Notifications to receive transaction status updates in real-time and message your customers accordingly.
  5. Refresh a Bank Authorization using Online Banking. A transactionId can become invalidated and a splitToken can become expired. If that happens, you'll want to send the User back to Online Banking to select a new Bank or refresh their Bank Authorization.

Integration Options and Branding Requirements

Trustly offers two types of Integration Options for its Online Banking solution: Select Bank Widget and Trustly Lightbox.

The Select Bank Widget is shown in-line on your page and shows the most popular bank accounts. Clicking one of the buttons on the Widget opens the Trustly Lightbox, where the User can sign in and authorize their account for use.

Alternatively, you can trigger the Trustly Lightbox using your own button. The Trustly Lightbox opens over your existing page.

In addition to determining if the Select Bank Widget or opening the Trustly Lightbox directly is the best option for you, Trustly has a number of Branding Requirements to consider. If you have any questions or specific requirements, please work with your Trustly team or email [email protected].

Create a Bank Authorization using Online Banking

The Trustly Online Banking Payment service enables end-users to pay by signing in to their online banking interface within your website. The Trustly User interaction can be completed in 3 simple steps.

  1. The User selects Online Banking as a payment method on your website, which either displays the Trustly Widget (which then launches the Trustly Lightbox) or launches the Trustly Lightbox directly.
  2. From the Trustly Lightbox, the user authenticates with their bank and selects the account they wish to use for the transaction.
  3. Before returning the User to your returnUrl, we will send an Event Notification to your listener with the transactionId and splitToken. You'll store the User's account on file at this point and return a successful response to the Trustly Notification system. The User is then returned to your returnUrl with the transactionId, at which point continue your flow as usual.

Integrate the Trustly SDK into your flow.

Trustly offers 3 SDK's: JavaScript, iOS, and Android. The SDK has 2 main methods: selectBankWidget and establish. The methods accept 2 parameters, options and establishData. The options parameter is optional and can be used to control pieces of the Lightbox experience. The establishData parameter is used to pass transaction parameters to Trustly that are used when establishing the Bank Authorization transaction.

The following examples are using the JavaScript SDK

1. To load the SDK on the page, use the following JavaScript tag (replacing {accessId} with the Access Id provided to you by Trustly):

<script src="https://sandbox.trustly.com/start/scripts/trustly.js?accessId={accessId}"> </script>

2. To provide optional Trustly configuration options, create a TrustlyOptions object:

var TrustlyOptions = {
  closeButton: false,
  dragAndDrop: false,
  widgetContainerId: "widget-container-id" //Page element container for the widget
};

For details on the Trustly configuration options, refer to the SDK Specification.

3. To provide the transaction details to the SDK, create an establishData object:

var establishData = {
  accessId: {accessId},
  requestSignature: {requestSignature},
  merchantId: {merchantId},
  description: 'transaction description',
  currency: 'USD',
  amount: '0.00',
  merchantReference: 'merchant reference',
  paymentType: 'Deferred',
  returnUrl: 'https://merchant.com/trustly/return',
  cancelUrl: 'https://merchant.com/trustly/cancel'      
};

🚧

Warning

Do not pass Consumer PII (name, email address, etc) in the description field. Pass Consumer PII in the customer object.

📘

Tip

Ensure you're securing your call by including the requestSignature parameter.

4. Finally, call the Trustly SDK's establish or selectBankWidget function:

Select Bank Widget

Trustly.selectBankWidget(establishData, TrustlyOptions);

Establish

Trustly.establish(establishData, TrustlyOptions);

The following is a full HTML page using the above example:

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script>
      var TrustlyOptions = {
        closeButton: false,
        dragAndDrop: true,
        widgetContainerId: 'widget',
      };
    </script>
    <script src="https://sandbox.trustly.com/start/scripts/trustly.js?accessId={accessId}"></script>
  </head>
  <body style="margin: 0;">
    <div id="widget"></div>
  </body>
   <script>
    var establishData = {
      accessId: {accessId},
      merchantId: {merchantId},
      merchantReference: {merchantReference},
      description: 'transaction description',
      currency: 'USD',
      amount: '0.00',
      merchantReference: 'merchant reference',
      paymentType: 'Deferred',
      returnUrl: 'https://merchant.com/trustly/return',
      cancelUrl: 'https://merchant.com/trustly/cancel'      
    };
    Trustly.selectBankWidget(establishData, TrustlyOptions);
  </script>
</html>

📘

Info

Replace {accessId} and {merchantId} with the values provided to you by Trustly.

Receive the Split Token

Before the User is returned via the returnUrl, Trustly will send you an Event Notification that contains the objectId (transactionId), splitToken, and other related fields. Once you receive the Notification, save the payment method to the User's account and return a 200 OK response to the Notification server.

📘

Info

Trustly will not redirect the User to your returnUrl until we either receive a response (success or failure) or until the request times out after 3 seconds.

🚧

Warning

If you fail to receive or store the splitToken, it can not be resent. You can (and should) attempt a Capture API call without it.

Example Authorization notification

merchantId=1002463580&merchantReference=123123&paymentType=2&transactionType=1&eventId=1002596466&eventType=Authorize&objectId=1002596444&objectType=Transaction&message=&timeZone=Etc%2FUTC&createdAt=1556311335754&accessId=ASs345fldAHJPTHXcaK&fiCode=051000017&status=2&statusMessage=Authorized&splitToken=CLnEidulLRABGHAgACo4dO9iOB%2BMPGWJheNrxkZGZBJatkOVU0228urTXrz8xzqqyXRr7s1ZJFsVlZBuug48VW7kMq0BprQ%3D

Please refer to Event Notifications for more information on handling Event Notifications.

Handle the redirect

If the User cancels the request, Trustly will direct the User to your provided cancelUrl. If the User successfully authorizes the request, Trustly will direct the User to your provided returnUrl.

Once you get a successful redirect to your returnUrl, check to ensure you've received the Split Token and added the account on file. If you have not, add the account on file with the provided transactionId and a blank or null splitToken.

Example Cancel URL

https://merchant.com/trustly/cancel?transactionId=1002632909&transactionType=1&merchantReference=123123&status=7&payment.paymentType=2&panel=1&payment.paymentProviderTransaction.status=UC01&requestSignature=tp%2B%2B%2BI5nM%2BSeOT8TQKLGvfaEGcs%3D

Example Return URL

https://merchant.com/trustly/return?transactionId=1002633191&transactionType=1&merchantReference=123123&status=2&payment.paymentType=2&payment.paymentProvider.type=1&payment.account.verified=false&panel=1&requestSignature=b7yr%2F3qOupPa1B7VeI32PhGQ7C8%3D

Redirect URL Parameters

Trustly will append the following parameters to your returnUrl or cancelUrl:

ParameterDefinition
transactionIdA unique Trustly transaction identifier. (15 characters)
transactionTypeWill always be 1 in this use case.
merchantReferenceA specific merchant reference for this cancelation. For example, this could be your order number or session id.
statusInteger value representing the Transaction Status. This will either be 2 (Authorized) or 7 (Cancelled). Refer to Transaction Status Values in the SDK Specification for a complete list of values and their definitions.
payment.paymentTypeWill always be 2 (Deferred) in this use case.
payment.paymentProvider.typeWill always be 1 (Online Banking) in this use case.
payment.account.verified...
panelInteger value representing the Trustly screen the user exited the flow on. Refer to Panel Values in the SDK Specification for a complete list of values and their definitions.
payment.paymentProviderTransaction.statusInteger value representing the Payment Provider Transaction Status of the transaction. Refer to Payment Provider Transaction Status in the SDK Specification for a complete list of values and their definitions.
requestSignatureThis is a signature that ensures the request you receive is coming from Trustly. See Validate the Redirect Signature for more information.

Display Bank or User PII from Trustly

With a valid Bank Authorization, use the Trustly Get Transaction API to retrieve information about the User's bank account that can be displayed in their account on your system. Use the Trustly Get User API to retrieve personal information (name, address, email, etc) that can be used to pre-fill fields on your flow or verify the information you have already collected from the User.

Use Get Transaction to display Bank information

Calling the Get Transaction API allows you to get transaction details and the current status of a transaction. You call the Get Transaction API by executing a GET request to the Get Transaction endpoint (/transactions/{transactionId}), where {transactionId} is the Bank Account Authorization transaction id.

Example Get Transaction request

https://sandbox.trustly.com/api/v1/transactions/1002548448

The Get Transaction call returns a JSON response with Bank Account data that you can use in your application. Relevant fields from the response include:

  • payment.account.name: Name (friendly identifier) of the User's Bank Account.
  • payment.account.type: Type of Account selected (Checking or Savings).
  • payment.account.accountNumber: Last 4 digits of the Bank Account number selected.
  • payment.paymentProvider.paymentProviderId: Trustly Identifier for the Bank selected. Use this identifier to display the Bank logo to the User.
  • payment.paymentProvider.name: Name of the Bank the User selected.
  • statusMessage: Status of the transaction. Should be Authorized.

Use this information to display the selected Payment Method to your user.

Example Get Transaction response (abbreviated)

{
  "transaction": {
    "transactionId": "1002580075",
    "payment": {
      "account": {
        "name": "Adv Plus Banking",
        "type": 1,
        "accountNumber": "3254",
      },
      "paymentProvider": {
        "paymentProviderId": "051000017",
        "name": "Bank of America"
      },
    },
    "statusMessage": "Authorized",
  }
}

Please refer to the Get Transaction definition in the API Reference for more information.

Use Get User Information to retrieve, validate, and display User information

Calling the Get User API allows you to get the personal information (Account Owner name, address, phone, and email) of the User from their selected Bank Account. You call the Get User API by executing a GET request to the Get Transaction endpoint, where {transactionId} is the Bank Account Authorization transaction id.

Example Get User request

https://sandbox.trustly.com/api/v1/transactions/1002548448/payment/paymentProvider/user

The Get User call returns a JSON response with User data that you can use in your application. Relevant fields from the response include:

  • name: Name(s) associated with the User's Bank Account.
  • address: Address(es) associated with the User's Bank Account.
  • phone: Phone Number(s) associated with the User's Bank Account.
  • email: Email Address(es) associated with the User's Bank Account.

You can then use this information to pre-fill or display the User's information in your flow. You can also use this information to validate the personal information the User may have previously provided in your flow.

Example Get User response (abbreviated)

{
  "user": {
    "name": [
      "John Smith",
      "Mary Smith"
    ],
    "address": [
      {
      "address1": "2000 Broadway Street",
      "address2": "",
      "city": "Redwood City",
      "state": "CA",
      "zip": "94063",
      "country": "US"
      },
      {
      "address1": "105 Alternate1 Street",
      "address2": "#401",
      "city": "Redmond",
      "state": "WA",
      "zip": "98052",
      "country": "US"
      },
    ],
    "phone": [
      "2145553434"
    ],
    "email": [
      "[email protected]"
    ],
  }
}

Please refer to the Get User definition in the API Reference for more information.

Create a Transaction from the Bank Authorization

Once you have a valid Bank Authorization, you can use the Trustly Transaction APIs to initiate Payments and Withdrawals.

Use the Pre-authorization API to create a pre-authorization

The Pre-authorization API allows the merchant to determine if a given amount of funds would be available for a given window. You call the Pre-authorization API by executing a POST request to the Pre-authorize endpoint (/transactions/{transactionId}/capture/preAuth), where {transactionId} is the Bank Account Authorization transaction id.

📘

Info

Any amount captured during the specified window against an approved pre-authorization transaction will be guaranteed. Any captures after the preauthorization window will be treated as a normal Capture request (where balance check and risk analysis will need to be passed in order for the transaction to be guaranteed).

In order to execute the Pre-authorization API request, ensure you pass in the following fields:

  • splitToken: Split Token you received from the Bank Authorization Notification.
  • amount: Amount to be authorized.
  • merchantReference: Your specific identifier for this transaction. For example, this could be your Order Number or the same merchant reference value used in the Bank Authorization transaction. This will appear in Event Notifications and Reporting.
  • window: Interval (in hours) that the preauthorization will be valid for.

Example Pre-authorization request

splitToken=CPSrlZajLRABGGAgACowghLbNU6b7dM1S95Q1Pu1FbQ87yCE%2Ba%2BL0muWQxno%2Fz%2F%2F5Sc8TJ7JCBUPCXTkG4P4&amount=10.00&merchantReference=9ce392f7-f99b-41e9-9028-3f33c8b0a46e&window=72

If the pre-authorization is approved, the Preauthorization API returns a transactionId that can be passed to the Capture API to capture funds.

Example Pre-authorization response (abbreviated)

{
    "transaction": {
        "transactionId": "1001001894",
        "transactionType": 2,
        "currency": "USD",
        "amount": "2.10",
        "status": 2,
        "statusMessage": "Authorized",
        "ip": "192.168.100.147",
        "createdAt": 1449176555750,
        "updatedAt": 1449176576137,
        "merchantReference": "BE3C26BC3F713AF8",
        "recordVersion": 3,
        "payment": {
            "paymentId": "1001001891",
            "paymentType": 1,
            "merchant": {
                "merchantId": "110005502"
            },
            "merchantReference": "BE3C26BC3F713AF8",
            "fingerprint": "eaGRmtHdk23hA7U2zB5TmDAJjDE=",
            "verification": {
                "status": 3,
                "mode": 3,
                "verifyCustomer": false
            },
            "account": {
                "name": "Demo Checking Account",
                "type": -1,
                "profile": -1,
                "accountNumber": "6576",
                "token": "KSDF23KL6576",
                "verified": true,
                "verification": {
                    "type": 2
                },
                "source": 1
            },
            "description": "Merchant.com purchase #BE3C26BC3F713AF8",
            "returnUrl": "https://merchant.com/instant/receipt",
            "cancelUrl": "https://merchant.com/instant/cancel",
            "currency": "USD",
            "amount": "2.10",
            "paymentProvider": {
                "paymentProviderId": "200005501",
                "type": 1,
                "name": "Demo Bank"
            },
            "auth": {
                "token": "1001000020",
                "status": 2,
                "message": "Authorized"
            },
            "createdAt": 1449176555744,
            "updatedAt": 1449176576159,
            "recordVersion": 5,
            "paymentFlow": 59
        }
    }
}

Please refer to the Pre-authorize Transaction definition in the API Reference for more information.

Use the Capture API to initiate Payments

The Capture API allows the merchant to request the transfer of a specific amount from the User's Bank Account given a Bank Account Authorization. You call the Capture API by executing a POST request to the Capture endpoint (/transactions/{transactionId}/capture), where {transactionId} is the Bank Account Authorization or Preauthorization transaction id.

📘

Tip

If you would like a given Capture request applied to a previously approved Preauthorization, ensure that you pass the Preauthorization transaction id as an input to the Capture API. Otherwise, the Capture request will be treated as a stand-alone Capture request.

This API returns one of the following 3 responses:

  • PENDING: The transaction was accepted and is in progress. You will be notified via Event Notifications of the final disposition of the transaction. For guaranteed payments, that will happen within 3-10 seconds. For non-guaranteed payments, that will happen within 3 banking days.
  • DECLINED: The transaction was declined and the User should be message appropriately (see Error Handling).
  • ERROR: There was an error processing the request. Correct the error and try the request again (see Error Handling).

In order to execute the Capture API request, ensure you pass in the following fields:

  • splitToken: Split Token you received from the Bank Authorization Notification.
  • amount: Amount to be captured.
  • merchantReference: Your specific identifier for this transaction. For example, this could be your Order Number or the same merchant reference value used in the Bank Authorization transaction. This will appear in Event Notifications and Reporting.

📘

Tip

If you don't have a splitToken value from the notification, attempt the Capture request anyway, omitting that field from the request. If we in fact do require the splitToken to process the request, the API will either return an error code 200 or send an Expired Split Token notification to your endpoint (see Handling expired Split Tokens).

Example Capture request

splitToken=CPSrlZajLRABGGAgACowghLbNU6b7dM1S95Q1Pu1FbQ87yCE%2Ba%2BL0muWQxno%2Fz%2F%2F5Sc8TJ7JCBUPCXTkG4P4&amount=10.00&merchantReference=9ce392f7-f99b-41e9-9028-3f33c8b0a46e

If the transaction was accepted for processing, the Capture API returns a PENDING transaction. You should create a PENDING transaction in your system and message the User appropriately.

📘

Tip

If you wish to have the User wait while the transaction with Trustly processes, you should create the pending transaction in your system, display an appropriate processing message to the user, and periodically check the status of the User's transaction in your system. Once the Event Notification is received and you update the status of the User's transaction, display the appropriate message. Set a timeout of 10 seconds in your application. If you don't receive an Event Notification in your system in 10 seconds, execute a Cancel API and attempt the request again.

Example Capture response (abbreviated)

{
  "transaction": {
    "transactionId": "1002636615",
    "transactionType": 3,
    "originalTransactionId": "1002636593",
    "payment": {
      "paymentId": "1002636591",
      "paymentType": 2,
      "merchantReference": "123123",
      "account": {
        "name": "Demo Checking Account",
        "type": 1,
        "profile": 1,
        "accountNumber": "6576",
      },
      "description": "Order",
      "paymentProvider": {
        "paymentProviderId": "200005501",
        "type": 1,
        "name": "Demo Bank"
      },
      "auth": {
        "token": "15LDRA3ENERD",
        "status": 2,
        "message": "Authorized"
      },
      "authorization": "15LDRA3ENERD",
      "authorizationStatus": 2,
      "authorizationStatusMessage": "Authorized",
    },
    "currency": "USD",
    "amount": "10.00",
    "pending": "10.00",
    "paymentProviderTransaction": {
      "paymentProviderTransactionId": "ptx-ynFSa0oAiaIruwksqTtasJOX-sbx",
      "status": 10,
      "statusMessage": "Established",
      "paymentProcessor": {
        "paymentProcessorId": "100000001"
      }
    },
    "status": 1,
    "statusMessage": "Pending",
    "merchantReference": "4160903e-4ef6-49c3-a186-69b51787e638",
    "statusCode": "SW010",
  }
}

Please refer to the Capture Transaction definition in the API Reference for more information.

Use the Deposit API to initiate Withdrawals

The Deposit API allows the merchant to request the transfer of a specific amount to the User's Bank Account given a Bank Account Authorization. You call the Deposit API by executing a POST request to the Capture endpoint (/transactions/{transactionId}/deposit), where {transactionId} is the Bank Account Authorization transaction id. This API returns one of the following 3 responses:

  • AUTHORIZED: The transaction was accepted and is in progress. You will be notified via Event Notifications of the final disposition of the transaction, usually within 3 banking days.
  • DECLINED: The transaction was declined and the User should be message appropriately (see Error Handling).
  • ERROR: There was an error processing the request. Correct the error and try the request again (see Error Handling).

In order to execute the Deposit API request, pass the following fields:

  • amount: Amount to be captured.
  • merchantReference: Your specific identifier for this transaction. For example, this could be your Order Number or the same merchant reference value used in the Bank Authorization transaction. This will appear in Event Notifications and Reporting.

Example Deposit request

amount=25.00&merchantReference=5b83cfe7-b43c-4a6a-aec3-e483876a908a

If the transaction was accepted for processing, the Deposit API returns an AUTHORIZED transaction. You should create a PENDING transaction in your system and message the User appropriately.

Example Deposit response (abbreviated)

"transaction": {
        "transactionId": "1002636638",
        "transactionType": 6,
        "originalTransactionId": "1002636593",
        "payment": {
            "paymentId": "1002636591",
            "paymentType": 2,
            "merchantReference": "123123",
            "account": {
                "name": "Demo Checking Account",
                "type": 1,
                "profile": 1,
                "accountNumber": "6576",
            },
            "description": "Order",
            "paymentProvider": {
                "paymentProviderId": "200005501",
                "type": 1,
                "name": "Demo Bank"
            },
            "auth": {
                "token": "15LDRA3ENERD",
                "status": 2,
                "message": "Authorized"
            },
            "authorization": "15LDRA3ENERD",
            "authorizationStatus": 2,
            "authorizationStatusMessage": "Authorized",
        },
        "currency": "USD",
        "amount": "25.00",
        "pending": "25.00",
        "paymentProviderTransaction": {
            "paymentProviderTransactionId": "ptx-6ygGA5gI7smyLVx52DY9D5oH-sbx",
            "status": 100,
            "statusMessage": "Pending",
            "paymentProcessor": {
                "paymentProcessorId": "100000001"
            }
        },
        "status": 2,
        "statusMessage": "Authorized",
        "merchantReference": "2534256c-634f-4ac6-a0dd-75d502cb1c3c",
        "statusCode": "AC100",
    }
}

Please refer to the Deposit Transaction definition in the API Reference for more information.

Other Transaction APIs

Trustly offers a number of other APIs that can be used to process Payment Transactions as needed.

Handle Event Notifications

Notifications are event objects pushed to a Notification URL that you provide. When a notification is received, you should update the transaction record in your system and continue processing the transaction as needed.

🚧

Warning

While Trustly makes every effort to send notifications in order, we can not guarantee that they will be received or processed by you in the order sent. Please ensure to keep the transaction state and createdAt timestamp in mind when processing events to ensure an old update isn't applied over a newer one.

When processing an Event Notification, the following fields are useful:

  • objectId: This is the transactionId of the transaction.
  • merchantReference: This is your reference id for the transaction.
  • createdAt: Timestamp that the event was created. If this was created before the last updated timestamp on your copy of the transaction, you should ignore this notification.
  • parentObjectId: If the transaction is related to another transaction (ie, a Capture is related to an Authorization), this will be the transactionId of the related transaction (ie, if this event is for a Capture transaction, the parentObjectId will the the transactionId for the Authorization).
  • transactionType: This is the type of transaction you are being notified about. If it is an Authorization flow, the transactionType will be 1. If it is an API (ie, Capture or Deposit), it will be the transactionType associated with that API (ie, 3 or 6).
  • transactionStatus: Status of the transaction to be updated in your system.
  • splitToken: If the transactionType is 1 (Authorization) and transactionStatus is 2 (Authorized), this will be the splitToken that needs to be saved on the User's profile and passed in subsequent Capture API calls.

If you need more details on a given transaction, you can use the provided objectId with the Get Transaction API call.

📘

Note

The splitToken can only ever be sent once. If it is not received or stored, go ahead and attempt your Capture API call without it. If we require a splitToken to complete a Capture request, we will send you the Expired split token notification.

For more information on Event Notifications, refer to Handling Event Notifications in this document or the Event Notifications .

Common Failure Scenarios

Common failure scenarios are outlined in the table below.

Transaction StatusPayment Provider Transaction StatusError CodeDescriptionAction to TakeSuggested User Messaging
FailedSW057326Expired split tokenSee Refresh a Bank Authorization using Online Banking.None
FailedSW051380Invalid / corrupt split tokenSee Refresh a Bank Authorization using Online Banking.None
FailedSW056330Invalid accountRemove the bank account from the User's profile in your system. Prompt the User to add another method of payment.Sorry, we are unable to process your request at this time. Please choose a different payment method.
FailedSW054390Fraud analysis.Remove the bank account from the User's profile in your system. Prompt the User to add another method of payment. If a thirdPartyDeclineCode is also provided, direct the user to TeleCheck for more information. See Common Failure Scenarios and Handling an Adverse Action decline for more information.Sorry, we are unable to process your request at this time. Please choose a different payment method.
FailedSW055390Fraud analysis (Negative Data).Remove the bank account from the User's profile in your system. Prompt the User to add another method of payment. If a thirdPartyDeclineCode is also provided, direct the user to TeleCheck for more information. See Common Failure Scenarios and Handling an Adverse Action decline for more information.Sorry, we are unable to process your request at this time. Please choose a different payment method.
FailedSW052378Internal error or bank request errorShow the suggested User message on the payment method page and allow the User to try the payment again.Sorry, we are unable to process your request at this time. Please choose a different payment method.
DeniedSW021331Not enough balanceShow the suggested User message on the payment method page and allow the User to use another method of payment.Your account can not be used for payment at this time. Please select another method of payment to continue.

Pre-authorize Transactions State Diagram

The following diagram shows the Transaction State of a Preauthorize transaction. Transaction status updates are sent via Event Notification and can also be retrieved via the Trustly Transactions Report.

  1. The Preauthorize API creates a transaction with the initial status of Pending.
  2. If the transaction is approved, it is moved to an Authorized state and you can execute Capture transactions against it.
  3. If there are any issues creating the pre-authorization, the transaction is moved to one of the other statuses.

Capture and Deposit Transactions State Diagram

The following diagram shows the Transaction State of a Capture or Deposit transaction. Transaction status updates are sent via Event Notification and can also be retrieved via the Trustly Transactions Report.

For guaranteed transactions

  1. The Capture or Deposit API creates a transaction with the initial status of Authorized.
  2. Within a few seconds, the transaction status will be updated to Processed, then to Completed.
  3. If there are any issues approving the transaction, then the final status will be updated to either Failed or Denied.

For standard transactions

  1. The Capture or Deposit API creates a transaction with the initial status of Authorized.
  2. Once the transaction is submitted to the network for processing, the transaction is moved to the Processed state.
  3. After 3 banking days, if the transaction has not been moved to the Denied state, it is moved to the Completed state.
  4. If there are any issues depositing the funds after the transaction has been moved to Completed, it is moved to the Reversed state.

Refund and Reclaim Transactions State Diagram

The following diagram shows the Transaction State of a Refund or Reclaim transaction. Transaction status updates are sent via Event Notification and can also be retrieved via the Trustly Transactions Report.

  1. The Refund or Reclaim API creates a transaction with the initial status of Authorized.
  2. Once the transaction is submitted to the network for processing, the transaction is moved to the Processed state.
  3. After 3 banking days, if the transaction has not been moved to the Denied state, it is moved to the Completed state.
  4. If there are any issues depositing the funds after the transaction has been moved to Completed, it is moved to the Reversed state.

Handling an Adverse Action decline

If you receive a Capture API or Deposit API response or receive an Event Notification with a Payment Provider Transaction Status of SW055 - Fraud analysis (Negative Data) and the response also contains a thirdPartyDeclineCode value, it means the user has an item on file with TeleCheck that needs to be resolved, and the user must contact TeleCheck directly. In this instance, you must provide this message to your user, replacing {{ thirdPartyDeclineCode }} with the thirdPartyDeclineCode value that was provided in the response or notification.

📘

Note

This use case can be tested using Demo Bank and the tckerror password in our Sandbox environment. Select the SW055 account and execute your Capture call as normal to trigger the Adverse Action SW055 decline via webhook.

🚧

Warning

Due to FCRA requirements, you MUST use this exact language:

The decision not to accept your payment was based, in whole or in part, on information provided by TeleCheck Services, Inc. To learn more, please visit https://getassistance.telecheck.com/index.html.
TeleCheck is located at 5565 Glenridge Connector, NE, Atlanta, GA 30342.
The mailing address is P.O. Box 6806 Hagerstown, MD 21741-6806.
The toll-free number is 1-800-366-2425. Please reference {{ thirdPartyDeclineCode }} when you call.

Under the Fair Credit Reporting Act: Consumers have the right to a free copy of their information held in TeleCheck’s files for a period of 60 days following an adverse action. Consumers also may dispute the accuracy or completeness of any information in TeleCheck’s consumer report.

Refresh a Bank Authorization using Online Banking

Handling invalidated Transaction Id's

If you receive a Capture API response or receive an Event Notification with an error code of 330 and a Payment Provider Transaction Status of SW056, simply follow these steps:

  • Remove the Account from the User's profile.
  • Message the User with an appropriate message, such as Sorry, we are unable to process your request at this time. Please choose a different payment method.. Allow the User to select another method of payment.
  • Create a new Bank Authorization using Online Banking. Save the new Authorization on the User's Profile.

📘

Note

This use case can be tested using Demo Bank and the tckerror password in our Sandbox environment. Select the SW056 account and execute your Capture call as normal to trigger the SW056 decline via webhook.

Handling expired Split Tokens

If you receive a Capture API response or receive an Event Notification with an error code of 326 and a Payment Provider Transaction Status of SW057, or an error code of 380 and a Payment Provider Transaction Status of SW051, simply follow these steps:

📘

Note

This use case can be tested using Demo Bank and the ExpiredSplitToken password in our Sandbox environment. Once you successfully create your bank authorization, use the Capture API to trigger the SW057 response.

Refresh an expired Bank Authorization using Online Banking

In the event a User's Split Token expires or becomes invalidated, you can use the Refresh flow to request a new one.

  1. You call the Trustly SDK's establish function, passing in parameters to launch the Refresh flow.
  2. From the Trustly Lightbox, the user authenticates with their bank and is immediately returned to your returnUrl.
  3. Before returning the User to your returnUrl, we will send an Event Notification to your listener with the transactionId and splitToken. You'll update the User's account on file at this point and attempt to process the Capture transaction again.

To integrate the Trustly Refresh flow into your website or app, you will need to do the following:

Integrate the Trustly SDK into your flow.

Trustly offers 3 SDK's: JavaScript, iOS, and Android. The SDK has 2 main methods: selectBankWidget and establish. The methods accept 2 parameters, options and establishData. The options parameter is optional and can be used to control pieces of the Lightbox experience. The establishData parameter is used to pass transaction parameters to Trustly that are used when establishing the Bank Authorization transaction.

The following examples are using the JavaScript SDK

1. To load the SDK on the page, use the following JavaScript tag (replacing {accessId} with the Access Id provided to you by Trustly):

<script src="https://sandbox.trustly.com/start/scripts/trustly.js?accessId={accessId}"> </script>

2. To provide optional Trustly configuration options, create a TrustlyOptions object:

var TrustlyOptions = {
  closeButton: false,
  dragAndDrop: false,
};

For details on the Trustly configuration options, refer to the SDK Specification.

3. To provide the transaction details to the SDK, create an establishData object:

var establishData = {
  accessId: {accessId},
  requestSignature: {requestSignature},
  merchantId: {merchantId},
  description: 'transaction description',
  currency: 'USD',
  amount: '0.00',
  merchantReference: 'merchant reference',
  paymentType: 'Verification',
  authToken: 'new',
  transactionId: {transactionId}
  returnUrl: 'https://merchant.com/trustly/return',
  cancelUrl: 'https://merchant.com/trustly/cancel'      
};

📘

Info

Ensure you are passing in the transactionId that you have stored on file. This transactionId will not change.

🚧

Warning

Do not pass Consumer PII (name, email address, etc) in the description field. You can pass Consumer PII in the customer object.

📘

Tip

Ensure you're securing your call by including the requestSignature parameter.

4. Finally, call the Trustly SDK's establish function:

Trustly.establish(establishData, TrustlyOptions);

The following is a full HTML page using the above example.

📘

Info

You'll want to replace {accessId} and {merchantId} with the values provided to you by Trustly. You'll want to replace {transactionId} with your stored transaction id.

<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script>
      var TrustlyOptions = {
        closeButton: false,
        dragAndDrop: true,
        widgetContainerId: 'widget',
      };
    </script>
    <script src="https://sandbox.trustly.com/start/scripts/trustly.js?accessId={accessId}"></script>
  </head>
  <body style="margin: 0;">
    <div id="widget"></div>
  </body>
   <script>
    var establishData = {
      accessId: {accessId},
        merchantId: {merchantId},
        description: 'transaction description',
      currency: 'USD',
      amount: '0.00',
        merchantReference: 'merchant reference',
      paymentType: 'Verification',
      authToken: 'new',
      transactionId: {transactionId}
        returnUrl: 'https://merchant.com/trustly/return',
        cancelUrl: 'https://merchant.com/trustly/cancel'        
    };
    Trustly.establish(establishData, TrustlyOptions);
  </script>
</html>

Receive the refreshed Split Token

Before the User is returned via the returnUrl, Trustly will send you an Event Notification that contains the parentObjectId (transactionId), splitToken, and other related fields. Once you receive the Notification, save the payment method to the User's account and return a 200 OK response to the Notification server.

📘

Info

Trustly will not redirect the User to your returnUrl until we either receive a response (success or failure) or until the request times out after 3 seconds.

🚧

Warning

If you fail to receive or store the splitToken, it can not be resent. You can (and should) attempt a Capture API call without it.

Example Verification notification

merchantId=1002463580&merchantReference=123123&paymentType=5&transactionType=1&parentObjectId=1002596444&parentMerchantReference=123123&eventId=1002642360&eventType=Authorize&objectId=1002642325&objectType=Transaction&message=&timeZone=Etc%2FUTC&createdAt=1557803299069&accessId=ASs345fldAHJPTHXcaK&accountVerified=true&fiCode=200005501&paymentProviderType=PWMB&status=2&statusMessage=Authorized&splitToken=CLvfv6KrLRABGGAgACowusCukkxmQ%2B%2BQseknVvMke5bDORHYSXZbLnPtCEPvL24Uae2XF7%2BcaSgIW%2BVC19J%2B

Please refer to Event Notifications for more information on handling Event Notifications.

Handle the redirect

If the User cancels the request, Trustly will direct the User to your provided cancelUrl. If the User successfully authorizes the request, Trustly will direct the User to your provided returnUrl.

Once you get a successful redirect to your returnUrl, check to ensure you've received the Split Token and added the account on file. If you have not, add the account on file with the provided transactionId and a blank or null splitToken.

Example Cancel URL

https://merchant.com/trustly/cancel?transactionId=1002632909&transactionType=1&merchantReference=123123&status=7&payment.paymentType=2&panel=1&payment.paymentProviderTransaction.status=UC01&requestSignature=tp%2B%2B%2BI5nM%2BSeOT8TQKLGvfaEGcs%3D

Example Return URL

https://merchant.com/trustly/return?merchantReference=123123&payment.account.verified=true&payment.paymentProvider.type=1&payment.paymentType=5&requestSignature=2yBF8Hlrte2yXttLEI934MfOiG4%3D&status=2&transactionId=1002642325&transactionType=1

Redirect URL Parameters

Trustly will append the following parameters to your returnUrl or cancelUrl:

ParameterDefinition
transactionIdA unique Trustly transaction identifier. (15 characters)
transactionTypeWill always be 1 in this use case.
merchantReferenceA specific merchant reference for this cancelation. For example, this could be your order number or session id.
statusInteger value representing the Transaction Status. This will either be 2 (Authorized) or 7 (Cancelled). Refer to Transaction Status Values in the SDK Specification for a complete list of values and their definitions.
payment.paymentTypeWill always be 2 (Deferred) in this use case.
payment.paymentProvider.typeWill always be 1 (Online Banking) in this use case.
payment.account.verified...
panelInteger value representing the Trustly screen the user exited the flow on. Refer to Panel Values in the SDK Specification for a complete list of values and their definitions.
payment.paymentProviderTransaction.statusInteger value representing the Payment Provider Transaction Status of the transaction. Refer to Payment Provider Transaction Status in the SDK Specification for a complete list of values and their definitions.
requestSignatureThis is a signature that you can calculate to ensure the request you receive is coming from Trustly. See Validate the Redirect Signature for more information.

Testing


Trustly offers a Demo Bank in the Sandbox environment that can be used to trigger a number of testing scenarios. You access the Demo Bank, search for "Demo Bank" in the 'Select your bank' screen of the Trustly Lightbox. To simulate errors when using the Demo Bank, you can use the phrases below in the password field to generate errors.

PasswordUse Case
NoEligibleAccountsNo eligible accounts found
LoginErrorWrong username or password
NotRecognizedMain Error that users see when using an ACA
NoSuchFieldThis error ultimately ends up as a PageNotRec error. It happens when an item cannot be found on the page. ACA will try to execute another page. If there is not another page, “page not recognized” error will be returned. Customers shouldn’t see this error.
PostErrorHTTP connection error using GET. The customer shouldn’t see this error. In real ACA, this will result in a Site not available” error.
GetErrorHTTP connection error using POST. The customer shouldn’t see this error. In real ACA, this will result in a Site not available” error.
PromptTypeErrorWhen an ACA fails to create a prompt, this error is returned. If this error appears, it means the ACA has a bug.
JsErrorWhen ACA tries to run javascript code and there are any errors during running, this error will be thrown.
UnavailableBank Site cannot be reached.
AccountLockedUser’s account is locked.
UnclassifiedThere are some run time exceptions that are not captured by ACA, like NPE(null pointer exception), array out of bounds exception, and so on.
BankActionThe bank requires the user to login and perform some action on their site.
ConnectErrorThere was a connection problem when accessing the bank site
ConnectionErrorThere was a connection problem when accessing the bank site
BlockedIpErrorThe bank indicates the caller IP was blocked
ChallengeErrorSimulates retry scenario, where the user provides a wrong challenge (or anything that isn't userid or password) and is allowed to retry
ValidRouteCodeExtraConnector returns 2 accounts whose route codes are larger than 9 digits: one of them has a valid route code as a substring, so both accounts use the same valid code
InvalidRouteCodeExtraConnector returns a single account whose route code is larger than 9 digits, but no valid route code is found as a substring. Hence, the account is ignored
TimeoutErrorIn order to simulate a timeout, the connector sleeps for at least a minute before actually doing anything.
TestPromptsThis is not an error. This is to test the prompts on the next page, including (Checkbox, radio, text, password, date, description, and so on)
NotEnoughFundsConnector returns a single account with zero balance. This is similar to having no eligible accounts, but for different reasons.
NotEnoughFundsExtraConnector returns two accounts. One with zero balance, the other with a valid balance.
InvalidAccountNumberSizeConnector returns a single account, but with an account number shorter than the required. This is to test how the screen filters invalid accounts
InvalidAccountNumberSizeExtraConnector returns two accounts. One with account number shorter (3 characters) than the required, the other with the valid account number.
PartialAccountNumbersConnector returns two accounts, however only with partial numbers. Simulating when for example the account is new and we still don't have statements to get the full account number.
OnlyPartialsPartialAccountNumbers + NoRouteCode
NoCustomerSimulates as if FIC was not able to retrieve customer information
NoRouteCodeRegular flow with 2 accounts, but none with route code. This prompts a question for account location, where the user must select where the account was open (from the given options)
InvalidRouteCodeRegular flow but simulates an invalid routing code (will simulate if ProfitStars returns invalid routing code)
2FASimulates as the bank requested a challenge question to the user. The question should be answered with the word 'error' if it's necessary to simulate a wrong credential. Otherwise, it should be anything to have successful access.
WrongCredentialsSimulates retry scenario, where the user provides a wrong challenge (or anything that isn't userid or password) and is allowed to retry
SiteRequestErrorSimulates as if the bank couldn't process a particular request, allowing the user to retry it
SessionTimeoutSimulates as if the user took too long to provide the requested information since the bank session is already expired
PreLoginErrorSimulates an error before the user gets authenticated
NotSupportedSimulates a user with no supported accounts
AccountsWithNameAndAddressSimulates a User with 2 accounts and each one with different names and addresses.
ManyInformationSimulates a User with 10 accounts.
AccountNotSupportedSimulates a User with an account not supported by our service (Chase Liquid, etc)
AmountNullSimulates the Demo Checking Account returning an amount with a null value.
AccNumberNullSimulates the Demo Checking Account returning the null value in the account number and routing number
AccFromUsernameReturns the account number from the pattern {prefix}_{accountnumber} on the username. Ex: To return an account with number 1234445 you can enter the username user1_1234445 or anotheruser_1234445.
RandomBalanceReturns account with a random balance
RandomAccountsReturns an account with a random account number
LargeCustomerInfoReturns account with very large customer information
FICWarningIt simply adds to log engine fic-warning one example message to simulate the FIC Warning flow
EmailMFASimulates as the bank requested the user to select an email address to send him an MFA token.
MixedMFASimulates as the bank requested the user to select an email address or a phone number to send him an MFA token.
CreditCardsOnlyReturns an account only with a credit card
AccountProfileReturns accounts with Business, Personal, Other, Unknown and Null profiles.
Balance{xxx}Configures the account to have a balance of {xxx}. For example, Balance1000 will set the account balance to $1000. This is useful when testing transactions of larger dollar amounts.
RandomAccWithSleepReturns random accounts with random account numbers and sleeps (in seconds) during the number passed in the password field
ExpiredSplitTokenAllows the transaction to be authorized but every refresh API call fails because of an expired split token.
tckerrorAllows you to pick an account that will return a SW054, SW055, or SW056 response. See Common Failure Scenarios and Handling an Adverse Action decline for more information.
NotEnoughFundsOnRefreshAllows the transaction to be authorized but every refresh API call returns 0.00 as a balance for all accounts.

To simulate a delay, just enter Sleep as username and the number of seconds as the password, The connector will wait for at least the given number of seconds before presenting any results.

Error Handling

Trustly uses conventional HTTP response codes to indicate the success or failure of an API request.

HTTP Status CodeDescription
200 OKEverything worked as expected.
400 Bad RequestOften due to a missing, required parameter.
401 UnauthorizedInvalid accessId or accessKey.
500 Server errorSomething went wrong on Trustly's end.
503 Service UnavailableThe server is currently unable to handle the request due to temporary overloading or server maintenance.

Not all errors map cleanly onto HTTP response codes, however. In addition to the HTTP response code, Trustly returns an array of error objects that describes the errors as a JSON string such as the example below.

{
  "errors": [
    {
      "domain" : "com.trustly.merchantgateway.v1.exception.InvalidParameterException",
      "code" : 200,
      "message" : "Could not find a transaction using Id 10000021"
    }
  ]
}
Error CodeDescription
100Internal error. An internal error (an internal database exception for example) occurred when trying to process the request.
150Remote error. A remote error (the consumer's bank interface is down) occurred when trying to process the request. This is an internal error.
200Invalid parameter error. One of the request parameters is invalid (sending an invalid amount format string for example).
300Security error. These are generic security errors that can happen when trying to process the request.
326Expired split token.
330Invalid account.
331Not enough balance.
375Access control error. These occurs when some security parameter (accessId, accessKey or requestSignature) is invalid and the request cannot be processed.
390Fraud analysis. Suspicious transaction or negative data.

Further Reading


Did this page help you?