#bugkiller.

1 messages ยท Page 1 of 1 (latest)

steep bridgeBOT
opal flax
#

Hi

#

We talked about this yesterday

ashen lark
#

how are you?

#

can we talk once more?

opal flax
#

Sure

ashen lark
#
stripe.Customer.modify(
                customer_id,
                invoice_settings={"default_payment_method": setup_intent.payment_method},
            )
opal flax
#

Yeah that's how

#

So what issue are you facing

ashen lark
#

so I can make it as default payment method when user adds card

#

but my question is

#
cards = stripe.PaymentMethod.list(
          customer=stripe_customer.id,
          type="card",
                )
#

I'm getting all cards with thsi api and it's listed in our website

#

so I'd like to know if user wants to make one of it as default payment method

#

what api should I use?

opal flax
#

You're using the one for treasury flows above

#

So needs to be this:

  "cus_123",
  type="card",
)```
ashen lark
#

what's the difference?

opal flax
#

The difference is that the one you're using is for treasury flows. You can read the description in the api spec

ashen lark
#

stripe.Customer.list_payment_methods
stripe.PaymentMethod.list
between these 2

opal flax
#

I still don't understand your question though. Just use that endpoint to list cards and give the customer the choiec on which to select

ashen lark
#

stripe.PaymentMethod.list

#

here this doesn't give me payment method id

#

stripe.Customer.modify(
customer_id,
invoice_settings={"default_payment_method": setup_intent.payment_method},
)

#

here I need to pass it

#

Id of the payment method is like "pm_...." right?

opal flax
#

yeah

ashen lark
#

ah, it has.

#

my fault.

#

I only got "card" obeject form array of payment method

#

it dind't have it

#

got it.

#

Thanks a lot and sorry for a dummy question.

opal flax
#

No problem!

ashen lark
#

one more question to be clear.

#

because I might use wrong api as you see above ๐Ÿ˜„

opal flax
#

Sure what is it?

ashen lark
#

how to delete card from customer then

#

stripe.PaymentMethod.detach(card_id)

#

tried with this but I think this is wrong because it's not related to customer

opal flax
#

That's correct. There's not really a way to delete a payment method, but detaching is what you want. It effectively deletes it. Detaching from a customer makes it unusable

ashen lark
#

yeah, but my question is

#

stripe.PaymentMethod.detach(card_id)

#

this doesn't have anything about detaching from whcih customer..

opal flax
#

Well a payment method can only be attached to 1 customer

#

So it doesn't matter

#

We internally know which customer it's attached to already

ashen lark
#

so I don't need to care on it

#

just call detach api right?

opal flax
#

If the goal is to detach it from the customer and make it unusable, yeah

ashen lark
#

cards = stripe.Customer.list_payment_methods(
AttributeError: type object 'Customer' has no attribute 'list_payment_methods'

#

?

opal flax
#

You might be using an old version of the sdk

#

Which version of stripe-python do you have?

ashen lark
#

stripe==2.56.0

opal flax
#

Ok try upgrading to 5.5.0 (latest)

ashen lark
#

it will not break many stuff right ๐Ÿ˜„

opal flax
#

Is this a new integration or a large existing one?

ashen lark
#

existing one

#

hi

opal flax
#

Ah then yeah don't upgrade unless you've done thorough testing/review of breaking changes

#

That's an old version so I'm not sure the syntax for listing a customer's payment methods

#

Maybe you did have it right on that version

ashen lark
#

I already upgraded. we need to afford because too many version change on it

#

again, for origin question

#

list payment method will give id like "pm_.." right?

#

correct?

#

but for me, "id" is like "card_.."

#

Can I pass this id to modify customer's default payment method??

opal flax
#

Yeah it lists both cards and pms

#

yes you can

ashen lark
#

how?

opal flax
#

Recommend you just try it

ashen lark
#

your api asks for passing payment id and what I have is card id

#

so confusing

opal flax
#

Cards are the older version

#

Our api has changed and we recommend creating payment methods now not cards

#

But you can still use the older card objects

ashen lark
#

I'm testing for my migration

#

so not using old api

#

session = stripe.checkout.Session.create(
payment_method_types=['card'],
mode='setup',
customer=stripe_customer.id,
# setup_intent_data={
# },
success_url=os.getenv('BACKEND_HOST') + '/api/execute-add-card-stripe-session/?session_id={CHECKOUT_SESSION_ID}',
cancel_url=os.getenv('BACKEND_HOST') + '/api/cancel-add-card-stripe-session/'
)

#

card is added with this code

#

Am I wrong?

#

it's been added by creating checkout session as above code

#

and it's added 'card'

ashen lark
#

?

#

your api example shows id="pm_..."
in my test, id is always "card_..."

opal flax
#

You can still pass card id to be default payment method

#

Your integration is fine

#

Can you paste that card id from your screenshot actually? Want to check something

ashen lark
#

this is test mode so test cards

#

424242424242..

#

and

#

5555 5555 5555 4444

#

do you need anything else more?

opal flax
#

Those aren't card id's

ashen lark
#

or card id?

opal flax
ashen lark
#

card_1NKfFGBTGnRwDyDi4ha0QQg6

#

pm_1Nai48BTGnRwDyDiWRrUFEKI

#

once user makes subscription with card, it will be added to customer by dfault right?

#

I think that case "id" will be "card_." not "pm_."

#

as I think

opal flax
#

Ok. So looks like Stripe Checkout still creates Card objects not PaymentMethod objecst

#

That's fine though, Card objects can still be set as default PM for subscriptions

ashen lark
#

for me, for customer (not for subscription

opal flax
#

What do you mean?

ashen lark
#

not for
default payment method for subscription
it's for
default payment method for customer (stripe customer)

#

saying my purpose.

opal flax
#

What's your question?

ashen lark
#

"That's fine though, Card objects can still be set as default PM for subscriptions"

#

you siad can still be set as default PM for subscription

#

we can set default payment method for subscription level, or customer level

#

so what I want is customer level

#

so just tackling your message to know exactly

opal flax
#

Have you tried it?

#

Recommend testing things out yourself first

ashen lark
#

yes, of course. but asked your document says 'id of payment method'

#

so don't wanted to pass card id there

#

if your doc is like 'id of payment method OR card id" then I would tried without asking ๐Ÿ™‚

#

now trying

#

will let you know soon result

#

Yeah, it works. thanks. I've recommended you to update your doc

#

thanks for your help again

opal flax
#

No problem. That's helpful feedback