onGetShippingMethods:function() {return [ { label:'Free Shipping', amount:'0.00', identifier:'free', detail:'Delivers in five business days', }, { label:'Express Shipping', amount:'5.00', identifier:'express', detail:'Delivers in two business days', }, ];}
onShippingContactSelected callback example
onShippingContactSelected:function(shippingContact) {constself=this;returnnewPromise(function (resolve, reject) {try {console.log("shippingContact",JSON.stringify(shippingContact));let taxAmt =0.1;constnewShippingMethods= [ { label:'Free Shipping', amount:'0.00', identifier:'free', detail:'Delivers in five business days', } ];if (shippingContact &&shippingContact.administrativeArea) {if (shippingContact.administrativeArea ==="NY") { taxAmt =0.0875;newShippingMethods.push( { label:'Overnight Shipping', amount:'10.00', identifier:'overnight', detail:'Delivers in one business days', } ); } elseif (shippingContact.administrativeArea ==="NJ") { taxAmt =0.07;newShippingMethods.push( { label:'Express Shipping', amount:'5.00', identifier:'express', detail:'Delivers in two business days', } ); } }constresp=self.getTransactionInfo(taxAmt, newShippingMethods[0]);resp.shippingMethods = newShippingMethods;resolve(resp); } catch (err) {constapErr= { code:"-101", contactField:"", message:exMsg(err) }console.error("onShippingContactSelected error.",exMsg(err));if (isDebugEnv) {setTimeout(function(){ alert("onShippingContactSelected error: "+exMsg(err))},100); }reject({errors: [err]}); } }) }
onPaymentComplete:function(paymentComplete) {if (paymentComplete.response) { //Successconstresp=JSON.parse(paymentComplete.response);if (resp.xRefNum) {setTimeout(function(){ alert("Thank you for your order:("+resp.xRefNum+")")},100); } else {setTimeout(function(){ alert("Thank you for your order.")},100); } } elseif (paymentComplete.error) {console.error("onPaymentComplete",exMsg(paymentComplete.error));handleAPError(paymentComplete.error); } }
Features required by Merchant. Each Feature is available with the certain iOS version. Therefore if device doesn’t support that version (Feature) - Apple Pay Button won’t be displayed.
List of field names used for requesting contact information in a payment request.
onAPButtonLoaded
String
Yes
Name of a callback function to be called when Apple Pay button is loaded.
Accepts an object of type APButtonLoadedResult
Please click here for the sample code.
onGetTransactionInfo
String
Yes
Name of a callback function to be called that returns the final price and tax calculations.
Please click here for the sample code.
onGetShippingMethods
String
Yes
Name of a callback function to be called that returns a list of available Shipping Methods.
Please click here for the sample code.
onShippingContactSelected
String
Yes
Name of a callback function to be called when Shipping Contact is selected/changed.
Accepts a parameter PaymentContact.
Returns ShippingContactResponse.
If address_validation is part of requiredFeatures in your ApplePay Request object you can return an Error as part of ShippingContactResponse.
Please click here for the sample code.
onShippingMethodSelected
String
Yes
Name of a callback function to be called when Shipping Method is selected/changed.
Accepts a parameter ShippingMethod.
Please click here for the sample code.
onPaymentMethodSelected
String
Yes
Name of a callback function to be called when Payment Method is selected/changed.
Accepts a parameter PaymentMethod.
Please click here for the sample code.
onBeforeProcessPayment
String
Yes
Name of a callback function to be called when consumer clicked the button but before Apple Pay sheet is loaded. Usually used to make validations before the payment.
Please click here for the sample code.
onValidateMerchant
String
Yes
Name of a callback function to be called to validate the Merchant.
This functions accepts a parameter validationUrl.
Please click here for the sample code.
onPaymentAuthorize
String
Yes
Name of a callback function to be called when Apple Payment is authorized for the completion of the transaction.
This function accepts a parameter of PaymentResponse.
Please click here for the sample code.
onPaymentComplete
String
Yes
Name of a callback function to be called when Apple confirms the completion of the transaction.
This function accepts a parameter of PaymentComplete.
Please click here for the sample code.
onError
String
Yes
Name of a callback function to be called when Error occurs.
Please click here for the sample code.
Make sure to assign onError in initAP function like below.
onCancel
String
Yes
Name of a callback function to be called when user cancels.
Please click here for the sample code.
Name
Type
Required
Description
buttonContainer
String
Yes
Name of the <div> where Apple Pay Button will be loaded
Apple Pay Button loaded successfully: status = iStatus.success
Apple Pay not supported: status = iStatus.unsupported
An error occurred while loading Apple Pay Button: status = iStatus.error
reason
String
If Apple Pay Button failed to load this field will be populated with the reason.
Name
Type
Description
phoneNumber
String
A phone number for the contact
emailAddress
String
An email address for the contact
givenName
String
The contact’s given name
familyName
String
The contact’s family name
addressLines
String[]
The street portion of the address for the contact
subLocality
String
Additional information associated with the location, typically defined at the city or town level (such as district or neighborhood), in a postal address
locality
String
The city for the contact
postalCode
String
The zip code or postal code, where applicable, for the contact
subAdministrativeArea
String
The subadministrative area (such as a county or other region) in a postal address