NAV
JavaScript

Introduction

OnPay maintains a JavaScript SDK provided directly from Onpay.io.

This SDK provides tools for implementing interactivity on webpages related to OnPay.

The SDK is self-contained and does not depend any external libraries, and shouldn't cause any conflicts with other libraries.

Including SDK

Place the following <script> at the end of page, right before the closing </body> tag.

<script src="https://onpay.io/sdk/v1.js"></script>

When including the SDK on your page, a variable window.OnPayIO is registered in the global space.

Check browser support

Tools are available to check browser support for Apple Pay and Google Pay.

It is a requirement that only cardholders with compatible browsers, is shown these payment methods. Therefore the SDK provides tools for checking support of these.

The intended usage of these tools, is to only present a cardholder the option to use either Apple Pay or Google pay, if their browser supports it. This could be done by showing/hiding buttons, text, etc. accordingly.

Apple Pay

if (typeof window['Promise'] === 'function') {
    let applePayAvailablePromise = OnPayIO.applePay.available();
    applePayAvailablePromise.then(function (result) {
        if (result) {
            console.log("Browser supports Apple Pay");
        } else {
            console.log("Browser does not support Apple Pay");
        }
    });
} else {
    console.log("Browser does not support Promises");
}

OnPayIO.applePay.available()

Returns a Promise containing result of browser support check. The browser needs to support Promises to use this function, and it is recommended to check for this before using this function.

Google Pay

if (typeof window['Promise'] === 'function') {
    let googlePayAvailablePromise = OnPayIO.googlePay.available();
    googlePayAvailablePromise.then(function (result) {
        if (result) {
            console.log("Browser supports Google Pay");
        } else {
            console.log("Browser does not support Google Pay");
        }
    });
} else {
    console.log("Browser does not support Promises");
}

OnPayIO.googlePay.available()

Returns a Promise containing result of browser support check. The browser needs to support Promises to use this function, and it is recommended to check for this before using this function.