Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function applePayButtonClicked(event)
{
var paymentRequest = {
// countryCode: The merchant’s ISO country code.
countryCode: 'US',
// currencyCode: The ISO currency code for the payment.
currencyCode: 'USD',
// total: The total amount for the payment.
total: {
label: 'Canine Clothing',
amount: '19.99'
},
// lineItems: A set of line items detailing what is being bought.
// shippingMethods: A set of available shipping methods.
// supportedNetworks: The payment networks supported by the merchant. Must be one or more of amex, chinaUnionPay, discover, interac, masterCard, privateLabel, or visa.
supportedNetworks: ['amex', 'discover', 'visa', 'masterCard'],
// merchantCapabilities: The payment capabilities supported by the merchant. Must be one or more of supports3DS, supportsEMV, supportsCredit, or supportsDebit.
merchantCapabilities: ['supports3DS'],
// requiredBillingAddressFields: The billing information that is required from the user. Must be one or more of postalAddress, phone, email, or name.
// billingContact: Billing contact information for the user.
// requiredShippingContactFields (old requiredShippingAddressFields): The shipping information that is required from the user. Must be one or more of postalAddress, phone, email, or name.
requiredShippingContactFields: ['postalAddress']
// shippingContact: Shipping contact information for the user.
// shippingType: How the items are to be shipped. This field is option. If specified, it must be one or more of shipping, delivery, storePickup, or servicePickup.
};
// versionNumber: The version of the API you are using. The version number allows the extension of the API in a backward compatible way. The current API version number is 1.
var versionNumber = 1;
session = new ApplePaySession(versionNumber, paymentRequest);
// onvalidatemerchant: A callback function that is automatically called when the payment sheet is displayed.
session.onvalidatemerchant = function(event) {
var promise = performValidation(event.validationURL);
promise.then(function (merchantSession){
promise.completeMerchantValidation(merchantSession);
});
}
// onpaymentauthorized: A callback function that is automatically called when an Apple Pay payment has been authorized.
session.onpaymentauthorized = function(event){
var promise = sendPaymentToken(event.payment.token);
promise.then(function(success){
var status;
if (success) status = ApplePaySession.STATUS_SUCCESS;
else status = ApplePaySession.STATUS_FAILURE;
session.complePayment(status);
showConfirmation();
})
}
// oncancel: A callback function that is automatically called when the payment UI is dismissed.
// onpaymentmethodselected: A callback function that is automatically called when a new payment method is selected.
// onshippingcontactselected: A callback function that is automatically called when a shipping contact is selected.
// onshippingmethodselected: A callback function that is automatically called when a shipping method is selected.
session.begin();
}
document.addEventListener('DOMContentLoaded', function(){
if (window.ApplePaySession){
var promise = ApplePaySession.canMakePayments('merchant.com.canine-clothing');
promise.then(function (canMakePayments){
if (canMakePayments) showApplePayButtons();
})
}
})
@Thesmily
Copy link

Thesmily commented Feb 11, 2020

how I can to use this code with payfort?
how I can to get the apple response to send it to post it to payfort ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment