#jovan_subscription-trial
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1227301486699216991
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- jovan_paymentelement-country, 18 hours ago, 32 messages
This is my code when creating a subscription
// Create a subscription with 30 days trial
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
'payment_behavior' => 'default_incomplete',
'payment_settings' => [
'save_default_payment_method' => 'on_subscription',
'payment_method_types' => ['card'],
],
'expand' => ['pending_setup_intent'],
// 'metadata' => $metadata
]);
jovan_subscription-trial
@peak tide there isn't really an easy way to do that. What you can do is create the SetupIntent first, wait for it to succeed and only then create the Subscription.
So I need to use this first to get the client secret?
https://docs.stripe.com/api/setup_intents/create
yep
Is this the right documentation suitable for my needs?
https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
How do you create a subscription with setupIntent attached?
you don't, it doesn't really make sense to do that
Is this also suitable for after setupIntent has been created?
// Create a subscription with 30 days trial
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
'payment_behavior' => 'default_incomplete',
'payment_settings' => [
'save_default_payment_method' => 'on_subscription',
'payment_method_types' => ['card'],
],
'expand' => ['pending_setup_intent'],
// 'metadata' => $metadata
]);
You create a SetupIntent, confirm it to collect card/payment method details and attach it to a Customer, then you create a Subscription with that PaymentMethod pm_123 as the default. No need to do anything else
Ohhhh so you need the payment method
How do you create a subscription with an existing payment method?
https://docs.stripe.com/api/subscriptions/create has default_payment_method as a parameter. Or you set the defaut on the Customer: https://docs.stripe.com/billing/subscriptions/payment-methods-setting
// Create a subscription with 30 days trial
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'default_payment_method' => $PAYMENT_METHOD
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
]);
Is this enough?
yes
Okay I'll try it out
Is the automatic_payment_methods unnecessary here?
$setupIntent = $this->stripe->setupIntents->create([
'customer' => $customer->id,
'automatic_payment_methods' => ['enabled' => true],
'payment_method_types' => ['card'],
]);
I have Credit/Debit, Google Play, and Link
Is it okay to remove the customer item here?
// Create a subscription with 30 days trial
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'default_payment_method' => $PAYMENT_METHOD
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
]);
since I already have a default_payment_method ?
Hello! I'm taking over and catching up...
automatic_payment_methods may or may not be optional depending on your API version. It also conflicts with payment_method_types. The idea is that you either specify specific payment_method_types or you use automatic_payment_methods (the ones enabled in your Dashboard).
The Customer can't be removed, since the Payment Method in question belongs to that Customer.
What will happen if I don't attached a customer on create setupintent?
$setupIntent = $this->stripe->setupIntents->create([
'payment_method_types' => ['card'],
]);
Then only create a customer when it is ready to create a subscription
// Create a subscription with 30 days trial
// Create a customer
$customer = $this->createCustomer($fields['name'], $fields['business_email']);
$subscription = $this->stripe->subscriptions->create([
'customer' => $customer->id,
'default_payment_method' => $PAYMENT_METHOD
'items' => [
[
'price' => $_ENV['STARTER_PLAN'],
'quantity' => $fields['client_allowed_members']
]
],
'trial_period_days' => 30,
]);
Is that possible?
Or is it really necessary to attach a customer when creating a setupIntent?
Yeah, you can create a Setup Intent without a Customer and add the Customer later.
Okay, I'll try it out and get back to you.
Sounds good!
I think it's not possible:
"The customer does not have a payment method with the ID pm_1P3igjFB7z3o5hlIBQERWhTZ. The payment method must be attached to the customer."
Let's back up a bit. What's the flow you're trying to build at a high level?
I want to verify if the card is legit or not before creating a subscription. To do this, this is my current flow:
- Create SetupIntent
- confirmSetup()
- Create Customer
[
'email' => "$email",
'name' => "$name",
]
);
- Create Subscription
Our service has a free 30-day trial and we want to automatically charge the customer after trial ended.
I guess I should attach the payment method to a customer first?
What I recommend you do is create the Customer, create a Setup Intent for them, confirm that, then create the Subscription. If the Setup Intent fails you can use the same Customer for a second Setup Intent.