Save to Pay JavaScript Library
JavaScript Library
interface saveToPayUI {
/**
* Shows the welcome UI. Redirects to welcomeCallbackUrl if it was
provided in the registration request when the page reaches one of
the final states.
*/
static void showWelcomeModal(S2PRequest r);
/**
* Shows the welcome UI. Resolves the promise with the status and
optionally details after the welcome UI is closed.
*/
static Promise <S2PResponse> showWelcomeModalPromise(S2PRequest
r);
/**
* API to close the modal
*/
static void closeWelcomeModal();
};
dictionary S2PRequest {
/**
* welcomeUrl provided by Save2Pay server in the registration
response.
*/
required DOMString welcomeUrl;
};
dictionary S2PResponse {
required Status status,
/**
* true if triggered by iframe closing (by user or parent page)
* false if the status is one of the final statuses, not triggered
by iframe closing. This can only happen in mobile android case.
*/
required boolean isIframeClosed,
/**
* Optional error information if the status is 'FAILURE'
*/
Details details
};
dictionary Details {
required ErrorCode errorCode;
DOMString message;
};
enum Status {
"SUCCESS",
"FAILURE",
"DEVICE_NOT_SUPPORTED",
"DEFAULT_PENDING"
};
enum ErrorCode {
"INVALID_INPUT",
"PROVISION_FAILURE",
"NETWORK_ERROR",
"UNKNOWN_ERROR",
"CARD_ALREADY_PRESENT",
"CANCELED"
};
USAGE
Code Block -1: HTML
<script
src="https://spay.samsung.com/s2p/libs/js/0.0.4/s2p.min.js"></script>
Code Block -2: JavaScript - Redirect
var input = {
"welcomeUrl":
'https://s2p.mpay.samsung.com/v1/welcome/eyJlbmMiOiJBMjU2R0NNIiwiYWx
nIjoiZGlyIn0..eLtgW8qp56CIEzo2.mh34gjebgYP_M7-
gW0SbDL3CkaPlP7RtvMC8fe-TmQ2IPMP2rcC1A39qODbVW2sCHiArbooahBE77LPvL8NhKkaPI6MHYNL-Yz6GQx0Sjw.xfRTYjpdZxRnMlQ8Ffe6pg'
}
window.spay.saveToPayUI.showWelcomeModal(input)
Code Block- 3: JavaScript - Promise
var request = {
"welcomeUrl":
'https://s2p.mpay.samsung.com/v1/welcome/eyJlbmMiOiJBMjU2R0NNIiwiYWx
nIjoiZGlyIn0..eLtgW8qp56CIEzo2.mh34gjebgYP_M7-
gW0SbDL3CkaPlP7RtvMC8fe-TmQ2IPMP2rcC1A39qODbVW2sCHiArbooahBE77LPvL8NhKkaPI6MHYNL-Yz6GQx0Sjw.xfRTYjpdZxRnMlQ8Ffe6pg'
}
function successCallback(response) {
console.log(response.status)
}
function failureCallback(error) {
console.log(error)
}
window.spay.saveToPayUI.showWelcomeModalPromise(request).then(succes
sCallback, failureCallback)
PROMISE RESOLUTION
Device Type | Description |
---|---|
Desktop, Tablet & Mobile - iOS | JS library will resolve the promise - 1. When the iframe is closed by the user. 2 closeWelcomeModal function is invoked. |
Mobile - Android | JS library will resolve the promise as soon as the provisioning session ends. Or closeWelcomeModal function is invoked. Provisioning session ends when one of the following has happened - 1. The card was successfully added. 2. There was some failure and card provisioning flow cannot continue further. 3. Timeout has happened. 4. User canceled the provisioning process. |