#shainkey

1 messages · Page 1 of 1 (latest)

vagrant yachtBOT
snow shale
#

Do you mean that you want to create the payment method first, then set the payment method into the subscription?

manic tiger
#

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

snow shale
#

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

manic tiger
#

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

snow shale
#

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

manic tiger
#

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'],
)

snow shale
#

Yes, you're right!

manic tiger
#

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 ?

snow shale
manic tiger
#

can we pass
payment_method_types=["card"],
currency="USD"
in the subscription creating function

snow shale
manic tiger
#

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

snow shale
#

You didn't expand latest_invoice.payment_intent in your subscription creation request

manic tiger
#

this is my subs_id

#

i expand but showing error

snow shale
#

Can you share the error? Payment intent will only be included in response with expand

manic tiger
#

yes
subs/latest_invoice = 'in_1M2sbhA1AvSnwwTv6pxl7OAW'

#

but

snow shale
#

You'll need to add expand=['latest_invoice.payment_intent'] in your subscription creation request

manic tiger
#

okay

snow shale
#

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

manic tiger
#

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

snow shale
#

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

manic tiger
#

okay got it
So no need to that key
payment_behavior="default_incomplete",

snow shale
#

If it's not set, the default payment_behavior will be allow_incomplete

manic tiger
#

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

snow shale
#

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

manic tiger
#

can u please send me the link for that

#

any reference

snow shale
#

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)

manic tiger
#

If i remove that payment_behaviour
showing this error
This customer has no attached payment source or default payment method.

snow shale
#

Why do you remove payment_behavior?

manic tiger
#

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.

rain robin
#

Can you share sub_xxx?

manic tiger
#

let me check
will confirm u next 5-10mnt

rain robin
#

You likely need to pass payment_behavior: 'default_incomplete' if your Customer does not have a default PM set

manic tiger
#

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'],

        )
magic fulcrum
#

why screenshot is opening and suddenly closed
I'm not sure what that means, could you elaborate?

manic tiger
#

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

magic fulcrum
#

could you share some screenshots/recordings/code of the frontend?

manic tiger
#

yes sure

magic fulcrum
#

also check logs. I assume you are using a mobile app(you didn't say), but check logcat/iOS logs to see what happened.

manic tiger
#

Yes using IOS app

#

can u please check once

magic fulcrum
#

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?

manic tiger
#

Yes
checking update u asap

#

any reason why its happening
is anything we need to pass to open paymentSheet ?

magic fulcrum
#

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)

manic tiger
#

let me send u the logs

magic fulcrum
#

thanks, still waiting for useful information unfortunately so I can't really add anything.

magic fulcrum
#

going to close this thread for now @manic tiger as it's been over an hour without progress