Created
March 15, 2017 22:03
-
-
Save alekseyg/fabbdc0f5d82140eedf829efdb443f4a to your computer and use it in GitHub Desktop.
What Stripe.applePay.checkAvailability actually does
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
Stripe.applePay.checkAvailability = function (callback) { | |
if (location.protocol === 'https:') { | |
var canMakePayments = window.ApplePaySession && ApplePaySession.canMakePayments() | |
if (/^pk_test_/.test(Stripe.key || Stripe.publishableKey)) { | |
callback(canMakePayments) | |
} else if (canMakePayments) { | |
var merchantId = "merchant." + window.location.hostname + ".stripe" | |
ApplePaySession.canMakePaymentsWithActiveCard(merchantId).then(callback) | |
} else { | |
callback(false) | |
} | |
} else { | |
console.warn("To use Apple Pay, you must serve your page over HTTPS.") | |
callback(false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this.
They should change line 6 to be called asynchronously, maybe
setTimeout(callback(canMakePayments), 0)
.I was calling this function to check if apple pay is supported before starting the apple pay session. Since this function is synchronous in test mode, we saw the issue about having to start apple pay session directly from user action only after it was deployed to production.
It was a silly mistake but this function could have warned me earlier.