#shainkey
1 messages · Page 1 of 1 (latest)
Hi there,
When creating a Subscription, it represents a recurring payment, so the renewal payement is don automatically.
what key we need to pass ?
If you price_id is monthly recurring price, then every month a payment attempt will be achieved
I invite you to take a look at this full guide for that:
https://stripe.com/docs/billing/subscriptions/build-subscriptions
Yes that price_id is monthly recurring price.
stripe.Subscription.create(
customer="{{CUSTOMER_ID}}",
items=[
{
"price_data": {
"currency": "USD",
"product": "{{PRODUCT_ID}}",
"recurring": {"interval": "month", "interval_count": 3},
"unit_amount": 1000,
},
"quantity": 1,
},
],
)
Like this one we need to pass
Good then, the renewal is done automatically by the Subscription object. I invite you to take a look at the official guide using Subscriptions in the meanwhile
or just pass the priceId like you previously did
okay
how we can test in local it is working or not
can i give custom date to expire Subs in 1 hour or something for testing purpose
You can use Stripe Test Clocks, in order to simulate advancing time and test the subscription renewal:
https://stripe.com/docs/billing/testing/test-clocks
okay let me check
Thank you so much
Np!
Hello @unique vale
I have created test clock but not showing when it will expire. I have given 4:10 PST time
Can u please confirm me on this point
You're using collection_method: 'send_invoice' so we won't automatically attempt payment(s). Your customer needs to explicitly pay those invoices
So which collection_method i need to use to auto payment
The default, charge_automatically
stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],
payment_behavior="default_incomplete",
collection_method="charge_automatically",
days_until_due=30,
)
is it fine ?
You can just remove that parameter really, charge_automatically is the default: https://stripe.com/docs/api/subscriptions/create#create_subscription-collection_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
okay
payment_behavior
what does it mean when we passing this key in Subscription creation. If i remove this param it is showing this customer has no attached payment source or default payment method
if i pass
payment_behavior="default_incomplete",
Then instead of showing active subscription. It is showing "incomplete" status
Well, is there a payment method associated with the customer?
Yes
Can you share the sub_xxx?
sub_1M1q64A1AvSnwwTvkc2VN15G
What is it exactly you're trying to test?
There's no default payment method set on the customer: https://dashboard.stripe.com/test/customers/cus_MlMpnstpgizBgA
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
So there's no way for us to attempt an initial payment
Let me explain step-by-step
Lets say i have create three product in stripe that have recurring monthly payment. Now, i want to use this subs from my side. From BE i create payment intent after that create subscription object to check what kind of subs user is taking from FE. for that, i am just sending price id to create subscription in stripe and pass the customer id correct, Now when i pass this object
stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],)
It is showing me error This customer does not no attached payment source or default payment method. But when i pass payment_behavior="default_incomplete",
It is working fine but showing incomplete status in subscription instead of showing Active.But in invoice tab it is showing payment link when i did the payment from here. Then it will show active status. But i need auto payment For resolving this issue, i pass 2 key collection_method="send_invoice",
days_until_due=30,
It is working fine in this case.
But i am not sure it is correct way or not.
for testing purpose i just want to test that subscription will expire after 1 hour or 30mnt.
So, I will update the code on server. That's it i want
and it will auto renew as previous subs what the user have
?
From BE i create payment intent after that create subscription object
Why are you creating a Payment Intent and a Subscription?
It is showing me error This customer does not no attached payment source or default payment method.
Yep, thats' expected: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_behavior
It is working fine but showing incomplete status in subscription instead of showing Active
Yep, again expected. If there's an initial payment due for the subscription then it will beincompleteuntil that payment is made. Then it'll transition toactive(assuming payment succeeds). Please read: https://stripe.com/docs/billing/subscriptions/overview#subscription-lifecycle
What you need to do is this: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#collect-payment
Get the payment_intent from the initial invoice generated from the subscription and attempt payment of it in your front-end with Stripe.js
Its for made payment from APP
Because without creating payment intent that payment card screen is not visible
It is, if you follow the guide I just linked