Last active
February 11, 2020 03:53
-
-
Save elfassy/d8610f9ba484a9b3b00f992cbcadc0a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ?