Skip to main content
Version: Lab (preview)

getApplePaySession

Requests an Apple Pay merchant session from Pay Theory. Pass the session to completeMerchantValidation in your Apple Pay onvalidatemerchant handler.


Function​

await messenger.getApplePaySession()

Parameters​

This function takes no parameters.


Returns​

{
type: String, // 'SUCCESS' or 'ERROR'
session: {
success: Boolean,
session: Object, // Apple Pay merchant session
error: String
},
error: String
}
Keytypedescription
typeStringSUCCESS when Pay Theory answered the request, ERROR when the Messenger couldn't connect.
sessionObjectPay Theory's validation result. Read session.success before you use it.
session.successBooleantrue when Apple validated the merchant.
session.sessionObjectThe Apple Pay merchant session to pass to completeMerchantValidation.
session.errorStringWhy validation failed, when session.success is false.
errorStringThe error message when type is ERROR.

A SUCCESS response can still carry a failed validation, so check session.success as well as type.


Usage​

const result = await messenger.getApplePaySession();

if (result.type === 'SUCCESS' && result.session.success) {
applePaySession.completeMerchantValidation(result.session.session);
} else {
console.error('Apple Pay validation failed:', result.error || result.session.error);
applePaySession.abort();
}

Notes​

  • Call initialize first.
  • If the Messenger's token has expired, getApplePaySession refreshes the connection before it answers.