stripe-archive / stripe-payments-demo

Sample store accepting universal payments on the web with Stripe Elements, Payment Request, Apple Pay, Google Pay, Microsoft Pay, and the PaymentIntents API. 💳🌍✨
https://stripe-payments-demo.appspot.com
MIT License
1.47k stars 547 forks source link

canMakePayment is not return `promise` as its throwing `undefined` when used with `.then` #175

Open m-nathani opened 3 years ago

m-nathani commented 3 years ago

Bug report

Describe the bug

i am using the below stripe version and integrated payment request button, however got a error canMakePayment returun null or false .. as the promise is showing as undefined.

    "@stripe/react-stripe-js": "^1.6.0",
    "@stripe/stripe-js": "^1.19.1",
TypeError: o.canMakePayment().then((function(t){t&&e&&l(!0)})).finally is not a function. (In 
'o.canMakePayment().then((function(t){t&&e&&l(!0)})).finally((function(){p(!1)}))', 'o.canMakePayment().then(
(function(t){t&&e&&l(!0)})).finally' is undefin...

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

It should return promise in every case to make the return consistent, and if its not supported then it should throw an error that could be catched in promise

System information

Additional context

this is the code i am using to check the canMakePayment on the payementRequest

    if (paymentRequest) {
      paymentRequest
        .canMakePayment()
        .then((res) => {
          if (res && subscribed) {
            setCanMakePayment(true);
          }
        })
        .finally(() => {
          setPaymentLoading(false);
        });
    }

Got this exception on my client using sentry..

TypeError: o.canMakePayment().then((function(t){t&&e&&l(!0)})).finally is not a function. (In 
'o.canMakePayment().then((function(t){t&&e&&l(!0)})).finally((function(){p(!1)}))', 'o.canMakePayment().then((
function(t) {t&&e&&l(!0)})).finally' is undefined.
m-nathani commented 3 years ago

one of the solution could be to use this if condition too:

    if (paymentRequest?.canMakePayment) {
      paymentRequest
        .canMakePayment()
       .... 
      }

However, still the return should be consistent.