#Nadiya
1 messages · Page 1 of 1 (latest)
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
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
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
instead of giving your customer access to your product on customer.subscription.created event
you can start the trial on invoice.paid
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?
are the free trial days covering one whole billing cycle?
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
let me try, thank you
"This property cannot be expanded (pending_setup_intent.client_secret)."
i've got the above error message
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'}
well. that seems to work, but let me make some test payment with that client secret.
will it charge money?
and based on the type your front end will call either confirmPayment or confirmSetup
ah i see
thank you so much.
will test this
yes sure let me know if you need any more help