Online SDK (Self-Hosted Page)
Online SDK (Self-Hosted Page)
Introduction
SagaPay’s online payment solution comes in three different modes tailored to meet your diverse business needs:
- Payment Page
- Online SDK (Self-Hosted Page)
- Merchant Initiated
Online SDK (Self-Hosted Page) is one of these modes where SagaPay renders fields on your web-shop page, providing you with the flexibility to customise the layout any way you want.
Note
To know more about our online payment terminals available refer to the online guide.
The following guide applies only to the Online SDK (Self-Hosted Page) flow.
Loading the SDK
To use the Online SDK, you need to include the Surfboard SDK script in your HTML page. Add the following script tag in your <head> section:
SDK Script URL
The SDK script URL will be provided by your account manager during terminal setup. The URL above is an example - use the URL provided specifically for your integration.
The SDK exposes a global SurfboardOnlineSDK object that you’ll use for all payment operations.
Initialising the SDK
To initialise the SDK, you will need following three params:
You can also retrieve the terminal’s public key later using the Fetch Terminal by ID API. The public key is returned as terminalPublicKey in the API response.
Once you have the three params, you can initialise the SDK with the following code. This returns a promise which you can await if you have an async method:
The errorCallback function that you provide will notify you of the various error cases as it occurs. Any error that occurs as part of the initialisation is usually a terminal error. Refer to the error table below to identify the error type.
The paymentStatusCallback is used to list the changes in paymentStatus and can be listened to handle UI changes accordingly.
The SurfboardOnlineSDK.remountOnlineSDK method re-initializes the SDK for a different order (for example, if the customer changes their cart or you want to start a new payment). This method takes the same parameters as initialiseOnlineSDK and allows you to dynamically update the SDK context without a full page reload.
Error Codes
When the SDK is initialised, it could either complete successfully or run into one of the following errors:
Data Objects
If none of the errors are encountered, you would have the following interfaces exposed on the SurfboardOnlineSDK window object:
- Orders
- Merchant
- Branding
- Store
- Payment methods
- Customer info
Order Object
Merchant Object
Branding Object
Store Object
Payment Methods Object
Customer Object
You can use the data provided here to display the required information on the web checkout.
Important
It is mandatory for you to display the contact information, privacy policy and the terms and conditions on the payment page.
Payment Flow
Almost all payment methods require you to provide customer information if it is not already present as part of creating the order.
Updating Customer Information
When handling online payments via the SDK, it is vital to include specific customer information for the payment. This customer information can be provided via the SDK or through the address field while creating the order.
Mandatory Fields by Payment Method
To update the customer information you can use the following code:
Important
Please note that the customer’s address is mandatory for card payments due to requirements from the payment schemes and acquirers we follow. We recommend that, whenever you have the address, you include it in the API request when creating the order. This way, the address will be pre-filled and displayed to the customer, eliminating the need for them to enter it manually.
In case the customer details update fails for any reason, the following error code is returned:
Initiating Payments
Payments can be initiated for the following methods:
- Swish payments
- Vipps payments
- Card payments
- Apple Pay
- Google Pay
- Klarna
Swish Payments
Swish payment involves customers making the payment in their Swish app. For mobile devices, the customer will be automatically redirected to the Swish app, complete the transaction, and then redirected to your application. For web payments, the customer will need to scan the displayed QR code using the Swish app and complete the payment.
To initiate a Swish payment, you can use the following code:
This will generate a payment attempt object that provides the following utility methods:
getSwishAppRedirectUrl(callback?: string)returns the URL to redirect the customer to the Swish app on mobile devices. When calling this method, make sure to provide a callback URL where the Swish app should redirect the customer after the payment is complete.getSwishQRDatareturns the QR code data to display on the web for the customer to scan and complete the payment.
The paymentStatusCallback will return the change in payment status’s as it happens.
Vipps Payments
Vipps is a Norwegian mobile payment solution. Vipps payments are only available for customers paying in Norwegian Kroner (NOK).
Currency Restriction
Vipps payments are only available for NOK currency. Ensure your order is created with NOK before offering Vipps as a payment option.
To initiate a Vipps payment, you can use the following code:
Critical: No Phone Number for Vipps
Vipps must NOT receive a phone number in the customer data. Including a phone number will break the payment flow. Only provide name, email, and billing address.
Customer Data for Vipps
Vipps Payment Flow
- Desktop/Mobile browser: SDK opens a popup/overlay where the customer sees Vipps QR code or instructions
- Customer opens the Vipps app on their mobile and approves the payment
- SDK receives
PAYMENT_COMPLETEDviapaymentStatusCallback
Payment Status Handling
Recurring Payments
Vipps does not support recurring/subscription payments via SDK. For products with automatic renewal, the customer must use card (CARD) to save a payment token for future MIT transactions.
Card Payments
To process card payments with the SDK, you need to provide a mount point for the SDK to load the fields. The SDK provides various options for how these fields are displayed, and you control this through configuration passed during mounting.
- In your web page, add a div element that will hold the card input fields:
- Call the mount function by passing in the relevant containers:
The SDK will use this container to load and display the card fields when you initialise it.
Apple Pay
To process Apple Pay with the SDK you need to provide a mount point in your HTML and call the SurfboardOnlineSDK.mount() function as follows:
This renders the Apple Pay button which handles the payment.
Apple Pay Additional Setup
For Apple Pay to work, you must set up the domain association file correctly.
Apple Pay Domain Association File Setup:
- Download/Copy the domain association file
- Host it on each domain/subdomain you want to use Apple Pay on
- Use the exact filename:
apple-developer-merchantid-domain-association - Place it in the
/.well-known/directory
File requirements:
- Content-Type must be
text/plain - Must be publicly accessible
- No password protection
- No proxy or redirects
The file needs to be accessible at this exact location for Apple Pay verification to work properly.
You can wait for the response in paymentStatusCallback function to check the payment status.
Google Pay
Google Pay™ allows customers to complete purchases using their debit or credit cards linked to their Google Accounts.
Acceptable Use Policy
All merchants must adhere to the Google Pay™ APIs Acceptable Use Policy and accept the terms defined in the Google Pay™ API Terms of Service.
Mounting Google Pay
To render the Google Pay button, add a mount point in your HTML and include it in the mount() call:
The SDK will render the Google Pay button in the specified container. When clicked, it opens the Google Pay payment sheet where customers can select their saved cards or add a new one.
Google Pay Setup Requirements
To enable Google Pay for your integration, you need to complete the following steps in the Google Pay Business Console:
-
Access Google Pay Business Console
- Navigate to Google Pay Business Console
- Sign in with your Google account
- Create a new business profile or select an existing one
-
Domain Configuration
- Add your store’s domain(s) for integration
- Our API will verify and register all domains under your ownership
-
Website Integration Setup
- In the left navigation, click “Google Pay API”
- Select “Website Integrate” → “Add website”
- Choose Gateway as your Integration type
- Upload required business images
- Fill in all required business information
- Submit for review
-
Activation
- Google will review your integration request
- You’ll receive confirmation once Google Pay is activated for your website
Supported Card Networks
The following card networks and authentication methods are supported:
3D-Secure Compliance
Google Pay transactions using PAN_ONLY mode use the actual card number and must comply with 3D-Secure (SCA) requirements. If 3D-Secure applies to your market region, it will be automatically enabled on your merchant account. CRYPTOGRAM_3DS uses a secure token and does not require additional 3D-Secure verification.
Payment Status
Google Pay payment status is tracked through the same paymentStatusCallback function used for other payment methods.
Regional Availability
Some Google Pay and Google Wallet features may be unavailable in certain countries or regions. Learn more about availability.
Klarna
To initiate a Klarna payment, make sure you update the required customer information as following example:
You can then initiate the Klarna payment simply using:
The payment status can be tracked using paymentStatusCallback function.
Payment Error Codes
During this process you might face the following error codes:
Complete Example
Here’s a complete example of an HTML page with the Online SDK integrated:
Sample Application
Contact your account manager for access to complete sample applications including React integration examples.