#Nadiya

1 messages · Page 1 of 1 (latest)

pliant pecanBOT
vapid yew
#

👋 happy to help

#

what can I help you with

north wharf
#

i just tried payment_behavior = error_if_incomplete
but, that doesn't help

#

it just start the subscription right away with free trial without adding payment method

vapid yew
#

I'm not sure if changing the payment_behavior would be the way to go here

#

the key to solving your issue depends on what events you're listening to in the webhooks

#

if we don't want to change the subscription creation workflow you have now

north wharf
#

there are few webhook events i'm currently listening to (including subscription.created and updated), but how come this is about webhooks?

#
            'customer' => $user->stripe_id,
            'items' => [[
                'price' => $price->stripe_price,
            ]],
            'payment_behavior' => 'error_if_incomplete',
            'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
            'trial_period_days' => (int) config('constants.FREE_TRIAL_DAYS') ?? null,
            'expand' => ['latest_invoice.payment_intent'],
        ]);```
This is my current code looks like
vapid yew
#

instead of giving your customer access to your product on customer.subscription.created event

#

you can start the trial on invoice.paid

north wharf
#

actually, they don't need to be paid. we just want to save the card only, and start the subscription with free trial after adding pm

#

do you think i should use setupIntents?

vapid yew
#

are the free trial days covering one whole billing cycle?

north wharf
#

yes

#

its monthly billing, but the free trial days can be up to 90

vapid yew
#

ok this means that the first invoice would be 0

#

and instead of using latest_invoice.payment_intent.client_secret you can use pending_setup_intent.client_secret

north wharf
#

let me try, thank you

#

"This property cannot be expanded (pending_setup_intent.client_secret)."

#

i've got the above error message

vapid yew
#

the property is pending_setup_intent

#

the client_secret is similar to the one you use from latest_invoice.payment_intent

#

what you need to do here is actually expanding on both properties

#

'expand' => ['latest_invoice.payment_intent', 'pending_setup_intent']

#

and then based on which of these is null you would send to your front end a hash like
{ client_secret: '....', type: 'payment'|'setup'}

north wharf
#

well. that seems to work, but let me make some test payment with that client secret.
will it charge money?

vapid yew
#

and based on the type your front end will call either confirmPayment or confirmSetup

north wharf
#

ah i see

north wharf
vapid yew
#

yes sure let me know if you need any more help