JavaScript methods

The window.spay.saveToPayUI interface exposes the following methods, which you can use to display and control the Save to Pay welcome UI on your website:

showWelcomeModal()

The showWelcomeModal() method displays the Save to Pay welcome UI in a modal window (iframe). When the card provisioning process reaches a final state (such as success or failure), the UI automatically redirects to the URL provided in the POST /registrations operation's welcomeCallbackUrl request field.

Syntax

showWelcomeModal(S2PRequest)

Parameters

Field
Type

Required/Optional

Description

S2PRequest

Object

Required

Information used to display the welcome UI.

S2PRequest.welcomeUrl

String

Required

URL returned in the POST /registrations operation's welcomeUrl response field.

Return value

None

Example

var input = {
  "welcomeUrl": "https://s2p.mpay.samsung.com/v1/welcome/eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..eLtgW8qp56CIEzo2.mh34gjebgYP_M7-gW0SbDL3CkaPlP7RtvMC8fe-TmQ2IPMP2rcC1A39qODbVW2sCHiArbooahBE77LPvL8NhKkaPI6MHYNL-Yz6GQx0Sjw.xfRTYjpdZxRnMlQ8Ffe6pg"
};

window.spay.saveToPayUI.showWelcomeModal(input);

showWelcomeModalPromise()

The showWelcomeModalPromise() method displays the Save to Pay welcome UI in a modal window (iframe) and returns a promise that resolves with the result either when the customer closes the UI or when the provisioning completes (Android only):

Device type

When the promise resolves

Desktop / Tablet / Mobile (iOS)

The promise resolves when the customer closes the iframe or when the closeWelcomeModal() method is invoked.

Mobile (Android)

The promise resolves when the registration session ends or when the closeWelcomeModal() method is invoked.
The registration provisioning session ends when one of the following occurs:
  • Card is successfully added.
  • Failure prevents the card provisioning flow from continuing.
  • Timeout occurs.
  • Customer cancels the provisioning process.

Syntax

showWelcomeModalPromise(S2PRequest)

Parameters

Field
Type

Required/Optional

Description

S2PRequest

Object

Required

Information used to display the welcome UI.

S2PRequest.welcomeUrl

String

Required

URL returned in the POST /registrations operation's welcomeUrl response field.

Return value

The method returns a promise that resolves to an object that contains the following fields:

Field
Type

Description

status

Enum

Overall result of the Save to Pay process.
The possible values are:
  • SUCCESS
  • FAILURE
  • DEFAULT_PENDING
  • DEVICE_NOT_SUPPORTED

isIframeClosed

Boolean

Whether the iframe was closed by the customer or parent page. If not, it was closed automatically (Android only).

details

Object

Optional error details, provided if status is FAILURE.

details.errorCode

Enum

Error type.
The possible values are:
  • INVALID_INPUT
  • PROVISION_FAILURE
  • NETWORK_ERROR
  • UNKNOWN_ERROR
  • CARD_ALREADY_PRESENT
  • CANCELED

details.message

String

Error message.

Example

var request = {
  "welcomeUrl": "https://s2p.mpay.samsung.com/v1/welcome/eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIn0..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(successCallback, failureCallback);

closeWelcomeModal()

The closeWelcomeModal() method closes the Save to Pay welcome UI.

Parameters

None

Return value

None

Example

window.spay.saveToPayUI.closeWelcomeModal();