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 680 forks source link

Can't set payment_behavior when creating a new subscription #1689

Closed azazulia closed 4 months ago

azazulia commented 4 months ago

Cashier Stripe Version

15.3.2

Laravel Version

10.48.13

PHP Version

8.3.4

Database Driver & Version

No response

Description

I'm trying to create a new subscription using Cashier. We allow ACH payments, so I want to set "payment_behavior: 'default_incomplete'" as per the stripe documentation here https://docs.stripe.com/billing/subscriptions/ach-debit. When I pass this as a parameter to $user->billable->newSubscription()->create(), it doesn't affect the behavior and the subscription is marked as active even while the ACH payment is pending. Is this a capability of Laravel that I'm implementing incorrectly or is it not possible?

Steps To Reproduce

Set up a new subscription:

$user->newSubscription('type', 'id')
    ->create(
        'payment method, 
        [],
        [
            'payment_behavior' => 'default_incomplete',
            'default_payment_method' => $paymentMethod->id,
            'automatic_tax' => ['enabled' => true],
        ]
    );
driesvints commented 4 months ago

You don't need to pass that at all because it's the default behaviour:

https://github.com/laravel/cashier-stripe/blob/15.x/src/Concerns/InteractsWithPaymentBehavior.php#L14

azazulia commented 4 months ago

If that's supposed to be the default behavior, is it possible something isn't working? My subscriptions are being marked as "active" while the first payments are still pending.

driesvints commented 4 months ago

Try using ignoreIncompletePayments to keep the subscription incomplete while the payments are pending. The default behaviour of Cashier is to always immediately activate the subscription so the customer has access to its features. This is more of a design decision and ignoreIncompletePayments allows you to keep it inactive.

$user->newSubscription('type', 'id')
    ->ignoreIncompletePayments()
    ->create(
        'payment method, 
        [],
        [
            'default_payment_method' => $paymentMethod->id,
            'automatic_tax' => ['enabled' => true],
        ]
    );

I see this isn't documented yet so if you want we'd appreciate a PR to the docs if you're up for that 👍

azazulia commented 4 months ago

It looks like this is marking my pending ACH payments as incomplete instead of pending, which is causing them to never resolve.

driesvints commented 4 months ago

@azazulia as opposed to the tutorial you posted I see that you're providing a payment method up front. I believe this probably isn't the way to go about ACH payments and that you need to collect payment details afterwards. Could you try out the exact steps from the tutorial? You can omit the payment method from ->create(

azazulia commented 4 months ago

Are you saying a user will need to enter their payment information each time they create a subscription? We have our platform set up so that users can enter and save ACH payment methods, similar to here: https://docs.stripe.com/payments/ach-debit/set-up-payment

driesvints commented 4 months ago

No, I'm just following the tutorial from Stripe. I also think it should be possible to re-use an ACH payment method.

But if you re-use an already set up ACH payment method like you suggest isn't it normal that the subscription is activated immediately?

azazulia commented 4 months ago

I don’t think so, as the payment can be marked as “pending” for a few days while the transfer is processed and could fail for reasons like insufficient funds. I’m looking to have the subscription remain inactive until the payment processes. The bank account has already been verified, but the payment still needs to be moved from pending to complete.

driesvints commented 4 months ago

@azazulia I unfortunately currently do not know why things are wrong for you and don't have the time to deep dive into this. It's most likely best that you attempt to contact Stripe support and if you figure out the exact reasons, circle back here. Then we can look into a solution for Cashier.