#iwynos_adi
1 messages ยท Page 1 of 1 (latest)
Followup from @vernal monolith
https://stripe.com/docs/billing/subscriptions/trials
we are unable to generate a client_secret when creating a subscription with a trial_period
Subscriptions with a trial will not have a PaymentIntent on their first invoice but the subscription itself will have a SetupIntent in itspending_setup_intentproperty
https://stripe.com/docs/api/subscriptions/object#subscription_object-pending_setup_intent
So you can use that intent to save your user's payment info
our goal is to get the user to provide their payment info at time of creating the subscription even if there is a free trial period we are offering
``$subs_obj = $stripe->subscriptions->create([
'customer' => $stripe_cust_id,
'items' => [
[
'price_data' => [
'unit_amount' => $transaction_amt* 100, //usd to cent
'currency' => $transaction_currency,
'product' => $transaction_pro, //'prod_ODkeMOLt9GkaPZ'
'recurring' => ['interval' => $transaction_period], //'month'
],
],
],
'payment_behavior' => 'default_incomplete',
'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
]);
$client_secret_key = $stripe->subscriptions->retrieve(
$subs_obj->id,
['expand' => ['latest_invoice.payment_intent']]
)->latest_invoice->payment_intent->client_secret;``
see the code above @river pumice please
This is what I use to get client_secret_key when there there is no need of a trail period
Yep, it looks like what I said was relevant
You are trying to access a payment intent that does not exist
Will the client_secret inside the pending_setup_intent will work( which i got after expanding pending_setup_intent)
Yes, though your client will likely have to make a slightly different call than it is currently making
Like if you are using confirmPayment on the client you will need to use confirmSetup instead
Can you help me with sample code or a supporting doc for the same
This is what I am getting when I expand pending_setup_intent
But I am unable to extract client_secret
The 6th property listed in that screenshot is the client_secret, you should be able to use it as normal
Also you can expand pending_setup_intent in your subscription creation request to get the client secret back as part of the initial call https://stripe.com/docs/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I am not able to extract client_secret help me out
๐ When you say not able to, are you seeing an error or something else? More details would help
It gives me a null value
$subs_obj->id,
['expand' => ['pending_setup_intent']]
);
return $stripe_json->pending_setup_intent->client_secret; ```
Try printing $stripe_json , does pending_setup_intent exist there?
what happens if you print out $stripe_json -> pending_setup_intent
Are you seeing an obiect?
Yes
This is what I get
Try printing out the whole string before you return it
$stripe_json->pending_setup_intent->client_secret
returns null
how about $stripe_json->pending_setup_intent->id?
same it also returns me null
One sec
And then can you provide the request ID when you retrieve the Subscription. See: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Where I can see the subscription list which has been setup under the trail period
?
Not sure what you mean by that exactly
You want to see your trialing Subscriptions in the Dashboard?
yes
Don't think you can filter for just trialing but you can see the ones that are active by going to https://dashboard.stripe.com/test/subscriptions and then looking at the status badge