Payment Widget Backend Integration Guide
Why is Backend Integration Needed?
Before you can render the Resurs Payment Widget on your frontend, your backend must securely obtain a session token from the Widget API. This token is required to initialize the widget for each customer session, ensuring secure and personalized payment experiences.Integration Flow Overview
- Obtain a JWT access token from the Merchant API (
/oauth2/token). - Create a widget session by calling the Widget API
/sessionendpoint, using the JWT as a bearer token. - Receive a widget session token from the Widget API.
- Pass the session token to your frontend, where it will be used to initialize the payment widget.
Sequence Diagram
Step 1: Get a JWT Access Token
Request a JWT from the Merchant API. The response will contain an access token, valid for 1 hour, which you’ll use as a bearer token in subsequent API calls. POST /oauth2/token (See Merchant API documentation for details.)Step 2: Create a Widget Session
Use the JWT access token to create a widget session. This returns a session token, which is required by the frontend widget. Example Request:- The
tokenis your session token for widget operations. Pass this to your frontend and reuse it until it expires.
Step 3: Provide the Session Token to the Frontend
The session token from the previous step must be sent to your frontend. The frontend will use this token to initialize and render the Resurs Payment Widget.Optional: Fetching Payment Method Types for Widget
Note: This step is only needed for advanced use cases, such as custom filtering or categorization of payment methods in your widget. Most integrations do not require this.Example Request:
- The response maps each payment method ID to its type.
RESURS_INVOICERESURS_PART_PAYMENT_SELECT_LATERRESURS_PART_PAYMENT_SELECT_NOWRESURS_CARDRESURS_REVOLVING_CREDITRESURS_NEW_REVOLVING_CREDIT
Error Handling
When making backend requests to the Resurs Widget API, error responses follow the Problem Details for HTTP APIs (RFC 9457) standard. This provides a consistent structure for communicating errors in HTTP APIs, with additional fields for more expressive error reporting in modern APIs. Example Error Response (Session Endpoint):type: URI reference for the error typetitle: Short summary of the errorstatus: HTTP status codedetail: Human-readable explanationinstance: The request patherrors: Array of field-specific validation errors (if applicable)
- Always check the HTTP status code of the response.
- Use the
detailanderrorsfields to provide feedback or logging in your backend. - Common error codes: 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 422 (Validation Error), 500 (Internal Server Error)