#shainkey
1 messages · Page 1 of 1 (latest)
Do you mean that you want to create the payment method first, then set the payment method into the subscription?
yes
how we can get the payment method id
stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],
payment_behavior="default_incomplete",
collection_method="charge_automatically",
)
This is my subscription function
here payment is showing successful
But subscription status is showing incomplete also also invoice status is open.
I want that Subscription as active and invoice as paid after making paymnet from app side in test mode
subs_id = sub_1M2rCNA1AvSnwwTvu9TNWfBC
pi=pi_3M2rCNA1AvSnwwTv0pv9SMWj
The Payment Intent is independent from the subscription and it will not be included in the subscription object. You shouldn't use Payment Intent like this for a subscription.
The recommended approach will be creating a subscription first, then use the PaymentIntent in the subscription for the payment. Only when the payment is succeeded, then you provision the service to the customer: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
payment_behavior='default_incomplete',
payment_settings={'save_default_payment_method': 'on_subscription'},
expand=['latest_invoice.payment_intent'],
what does it mean here
is it possible to handle all things from BE side only ?
for ex:
if frontend create payment intent at that time we are filling the card details and they are sending user_id. I filter customer id and price id for that susbcription from my side and created according
its already working fine in all cases except the status one.
For ex: if i made the payment from Fronetend side.
its showing successful , also at that time only subscription status showing incomplete and invoice as open. If i send
collection_method="send_invoice" that time it is showing active but invoice status is open. I go to manually in invoice and there is an payment link after click on that link we need to fill the card details. then it is showing as paid. But i don't want to do this because i already made the payment
When you create a subscription, it will create a PaymentIntent for you for your customer to make the payment
Subscription comes with its own PaymentIntent for the first payment
If you create a PaymentIntent first, then create a subscription, there will be two PaymentIntents
So we don't need this one in that case
paymentIntent = stripe.PaymentIntent.create(
amount=amount,
currency="USD",
payment_method_types=["card"],
customer=customer['id'],
)
Yes, you're right!
You should use the PaymentIntent created by the subscription for customer to make the payment as described in the doc here: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
okay let me check
In this case how we open that payment screen
Because it asking for payment intent at that time
we call that api to create subscription intent
stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
]
)
It will automatically create payment intent ?
Yes, PaymentIntent is created automatically. You can refer to the step here: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#create-subscription
You'll need to expand 'latest_invoice.payment_intent' during subscription creation and get the payment intent client secret from subscription.latest_invoice.payment_intent.client_secret to pass back to your frontend
can we pass
payment_method_types=["card"],
currency="USD"
in the subscription creating function
The currency will use the one from price set under items, so you can't set the currency.
For payment method types, it can be set under payment_settings.payment_method_types in subscription creation: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_settings-payment_method_types
okay
i am not getting payment_intent here
subs = stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],
payment_behavior="default_incomplete",
collection_method="charge_automatically",
# days_until_due=30,
)
payment_intent_id = subs.payment_intent
sub_1M2sSxA1AvSnwwTvCpquyTvU
You didn't expand latest_invoice.payment_intent in your subscription creation request
Can you share the error? Payment intent will only be included in response with expand
You'll need to add expand=['latest_invoice.payment_intent'] in your subscription creation request
okay
I'd recommend reading the code example here: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#create-subscription
And ensure the necessary parameters are included
You also miss payment_settings={'save_default_payment_method': 'on_subscription'}
Without saving the payment method as default on the subscription, future recurring payments won't be charged
can i remove this one
payment_behavior="default_incomplete",
because we don't want to create invoice link to paid the payment. It will be payment through FE
Subscription will always create an invoice. Only when collection_method is set to send_invoice, then the payment invoice link will be sent to the customer. With collection_method='charge_automatically', invoice payment link won't be sent
okay got it
So no need to that key
payment_behavior="default_incomplete",
payment_behavior may be needed to determine how you would like the subscription to be activated: https://stripe.com/docs/api/subscriptions/create#create_subscription-payment_behavior
If it's not set, the default payment_behavior will be allow_incomplete
Yes
i already checked this one
But when i sent to default_incomplete
it is showing open invoice status
But i don't need that one because we are making payment from frontend
it should show paid when the payemnt happens successfully
Every subscription generates an invoice regardless the setting of payment_behavior
However, it's not required to make the payment using the invoice payment link
You can use the PaymentIntent under the invoice to make the payment at your frontend
It's in the exact same link that I shared with you in the past few messages: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements
I'd recommend reading the doc and follow step by step. It shows you how to make a subscription payment with Payment Element (not using invoice link)
If i remove that payment_behaviour
showing this error
This customer has no attached payment source or default payment method.
Why do you remove payment_behavior?
Sorry by mistake
I have attached now
subs = stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],
payment_behavior="allow_incomplete",
collection_method="charge_automatically",
payment_settings={'save_default_payment_method': 'on_subscription'},
expand=['latest_invoice.payment_intent'],
# days_until_due=30,
)
why it is showing cancel payment
This customer has no attached payment source or default payment method.
it will work when FE make the payment from card correct ?
I tested only fro BE now its giving me error
This customer has no attached payment source or default payment method.
Can you elaborate on this? What exactly do you mean by 'cancel payment'?
Can you share sub_xxx?
Its likely that the Payment Intent associated with the initial invoice just needs confirming on your front-end: https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements#complete-payment
let me check
will confirm u next 5-10mnt
You likely need to pass payment_behavior: 'default_incomplete' if your Customer does not have a default PM set
okay
i am checking
sub_1M2uTRA1AvSnwwTv9gyUw5V3
why screenshot is opening and suddenly closed and payment happens but not showing success
subs = stripe.Subscription.create(
customer=customer['id'],
items=[
{"price": price_id},
],
payment_behavior="default_incomplete",
collection_method="charge_automatically",
payment_settings={'save_default_payment_method': 'on_subscription'},
expand=['latest_invoice.payment_intent'],
)
why screenshot is opening and suddenly closed
I'm not sure what that means, could you elaborate?
Actually
when FE trying to click on make payment button that card details opening and suddenly closed not able to enter any details
first time we need to make payment from FE
could you share some screenshots/recordings/code of the frontend?
yes sure
also check logs. I assume you are using a mobile app(you didn't say), but check logcat/iOS logs to see what happened.
thanks, that helps a small bit. It's an iOS app using PaymentSheet.
any code you can share and what have you found investigating the logs of the app?
Yes
checking update u asap
any reason why its happening
is anything we need to pass to open paymentSheet ?
I can't help since you're not giving me any information to work with unfortuantely.
please provide the information I asked for(the exact code you're using in the app and information on what you found when you looked for logs in the app)
let me send u the logs
following this doc
https://stripe.com/docs/payments/accept-a-payment#add-server-endpoint
thanks, still waiting for useful information unfortunately so I can't really add anything.
going to close this thread for now @manic tiger as it's been over an hour without progress