laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.39k stars 679 forks source link

Payment confirmation Page creates a new payment method for the customer on Stripe #971

Closed mehrancodes closed 4 years ago

mehrancodes commented 4 years ago

Description:

I tried to implement failed payments confirmation handler by adding the CASHIER_PAYMENT_NOTIFICATION env key. Everything seems to work fine except that it adds a new Payment Method for the customer EVERY time. wondering if this is something correct or not. shouldn't we just confirm the payment? or update the current payment method if needed? Screen Shot 2020-07-08 at 4 19 41 PM

Steps To Reproduce:

Add a new subscription with this card 4000002760003184 which asks for 3D if you have it enabled. then Cashier sends a confirm payment email after the first invoice payment gets failed.

Things I have tried to fix it with no success

I have tried to replace this inside the Casher's resources/views/payment.blade.php:

    stripe.handleCardPayment(
        '{{ $payment->clientSecret() }}', this.cardElement, {
            payment_method_data: {
                billing_details: { name: this.name }
            }
        }

With confirmCardPayment, but it still creates a new payment method

    stripe.confirmCardPayment(
        '{{ $payment->clientSecret() }}', {
            payment_method: {
                card: this.cardElement,
                billing_details: { name: this.name }
            }
        }
driesvints commented 4 years ago

I've forwarded this question to Stripe themselves on how we can prevent this. I'll get back to you once they give an answer. Thanks!

driesvints commented 4 years ago

So as it turns out we can re-use the payment method id of the payment intent to set the it as the payment method to be verified. We'll need to update the payment page to do that instead.

   stripe.confirmCardPayment(
          clientSecret,
          {
            payment_method: "pm_xxxx"
          }
        ).then(function(x) {

We'll need to also test the scenario where the card can't be verified and a new one needs to be added.

driesvints commented 4 years ago

Marking this as an enhancement because the current way still works but is a bit cumbersome.

mehrancodes commented 4 years ago

I have these scenarios handled inside our app, So I think I can help to put some time at the weekend to do the same thing here as well. It would be great if we use the user's card here as well since it would be easier for them to remember what card they're using and also they might not need to write their card again when just confirming the payment requires_action.

driesvints commented 4 years ago

PR: https://github.com/laravel/cashier-stripe/pull/987