capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
MIT License
185 stars 74 forks source link

Stripe.presentPaymentSheet() return an error #119

Closed loicparent closed 2 years ago

loicparent commented 2 years ago

Hello,

I try to setup a payment subscription using this plugin.

Description of the issue:

I retrieve correctly (from the server) the 3 keys required for the function "Stripe.createPaymentSheet". But, when I log this function, I see nothing in the console.

const paymentSheet = await Stripe.createPaymentSheet({
  paymentIntentClientSecret: paymentIntent,
  customerEphemeralKeySecret: ephemeralKey,
  customerId: customer
});

When I call then this function "Stripe.presentPaymentSheet", I have an error returned:

Uncaught (in promise): TypeError: this.paymentSheet.present is not a function
at StripeWeb.presentPaymentSheet (web.js:37)
at index.js:196
…

Could someone helps me to understand what's wrong?

More information:

  1. Version of Ionic: 6.18.0
  2. Version of Capacitor: 3.2.5
  3. Version of the Stripe-capacitor plugin: 3.4.0
  4. Version of Stripe API: 2020-08-27
  5. Backend: WordPress and so PHP library of Stripe
  6. I need to use this plugin on: Android & IOS (it's better if I can test it on browser too)

Thanks and have a nice day Loïc

hideokamoto commented 2 years ago

Sorry to delay the reply. Does the error occur in non-subscription payments? Or just occur with only a subscription payment?

Thanks.

loicparent commented 2 years ago

Hi @hideokamoto,

Thanks for your reply!

I tried several things and the error appears because I have tested on the browser using ionic serve (my mistake). When I try on the ios simulator, I don't have this error anymore.

However, after the function Stripe.createPaymentSheet(), when I call the function Stripe.presentPaymentSheet(), the modal appears a short time with a loader but then disappears directly. I can see in the console that the event PaymentSheetEventsEnum.Failed is called too.

Demo: link to video

So very similar to this issue: https://github.com/capacitor-community/stripe/issues/106

Do you know what I have to change?

I am gradually approaching :)

Thanks, Loïc

loicparent commented 2 years ago

Hi @hideokamoto,

Ok I see what was wrong. I used the secretKey (sk_test…) instead of the publicKey (pk_test…). After changing this, I have no more error, the payment modal appears correctly and the payment process works fine.

Now I will try the ApplePay and GooglePay tools :)

Regards

rdlabo commented 2 years ago

@loicparent Did you adapt this plugin for production? If yes, please tell us what app. Please help us to develop this plugin in 2022. https://github.com/capacitor-community/stripe/issues/145 Thanks.