Build a Trustly Source Request object. A Trustly Source Request object requires the following fields:
Field
Value
Trustly Source Details Object
Create a Trustly source details object.
{"returnUrl": "https://example.com",}
Step 2: Create a Trustly source using DigitalRiver.js
Use the DigitalRiver.js library to create and mount elements to the HTML container.
The address object must contain postal code and state/province data thatadheres to a standardized format using the state attribute. Note that the state attribute listed below corresponds to the countrySubdivision attribute used when providing address information. The payment session manages the correct field name on the backend.
var sourceData = {"type":"trustly","sessionId":"ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f","owner":{"firstName":"John","lastName":"Doe","email":"jdoe@email.com","phoneNumber":"077 1723 6984","address":{"line1":"110 Uxbridge Road","line2":"","city":"SLAUGHDEN","postalCode":"IP15 9RA","country":"GB" } },"trustly": {"returnUrl":"https://example.com" }}digitalriver.createSource(sourceData).then(function(result) {if(result.error) {//handle error messagevar errorMessage =result.error.errors[0].message; } else {//send the source to the back end for processingvar source =result.source; }});
When you create a Trustly source, the customer is required to authorize the charge through their payment provider. You can accomplish this by redirecting the customer to their payment provider.
Redirecting the customer for Trustly authorization
To redirect your customer to the payment provider for authorization, use the redirectUrl parameter in your createSource response.
The payment provider will present the customer with the transaction details where they can authorize or cancel the transaction. A successful authorization redirects the customer to the Trustly Return URL parameter you specified when you created the source.
Once authorized, the source state will change to chargeable.
If you choose the full redirect flow, this is where you will redirect your customer after the customer authorizes or cancels the payment within the Trustly experience.