#bmizerany

1 messages Β· Page 1 of 1 (latest)

steep fieldBOT
keen star
#

Hi there, you need to attach the payment method to the customer before setting this payment method as the default_payment_method, this applies even to test pms

fallow falcon
#

Ah okay thank you.

#

Is that the only way in tests? I'm using checkout and this is normally handled by Stripe

#

I guess the answer is to "mimic checkout" in tests?

keen star
#

What do you want to achieve here?

fallow falcon
#

I'd like to write a regression test prove I'm updating the default payment method of a customer to the recent payment method add/updated in a checkout session I sent them through

keen star
#

Checkout page won't prefill the customer's default_payment_method, it'll pre-fill the payment method that the customer used previously in checkout.

fallow falcon
#

right

#

so I have to do taht after

#

which is what I'm attempting to do AND test πŸ™‚

#

I have been able to attach pm_card_us

#

in fact, I was when creating the customer using payment_method=pm_card_us

#

then when I update the customer to set the default payment_method it says it isn't allowed because it is not attached

#

Here is another run of the test:

#

req_Qxp3LHuUnI2Jrr

#

and then:

#

req_SqzGimueH6Dib6

#

the first "attaches" pm_card_us

#

the second attempts to set it as the default

keen star
fallow falcon
#

Isn’t β€˜pm_card_us’ and existing and valid payment id?

#

Iirc the docs say it is

#

@keen star so what does the payment_method param on POST /v1/customers do?

#

If it isn't attaching a payment method, which is what the docs say?

#

BTW I'm not surprised if it doesn't work as advertised or at all, I've found plenty of those in Stripe, but it would be good to know that for sure instead of trying to force it to work

keen star
fallow falcon
#

Here is another run after attaching:

#

req_Eqq4i5wjacjQ3E -> req_OGr8D4itntPTMU -> req_gGTtQWryTXRbM7

#

The attach happens in the 2nd request, and succeeds

#

then fails to acknowledge the pm on the 3rd

keen star
#

The 2nd request gives you a payment method ID ('pm_1Mwdg0CouQWSdzy15Wv7unk5'), and you need to use that ID to attach it to the customer

fallow falcon
#

I am so confused. I thought pm_card_us IS a valid payment method ID

#

so I do not need to attach. It is attached, by default, to all customers old, and yet to be in Test Mode

keen star
#

It is a special test payment method ID.

fallow falcon
#

I know

#

but a payment method ID none the less

#

it seems like the docs could be more clear

keen star
#

Thanks for your feedback.

fallow falcon
#

or prefix the id with testcard_ not pm_

#

but it is accepted in places where pm_s are accepted, just not on default payment method

#

which is odd

#

I think that might be unintended

steep fieldBOT
fallow falcon
#

It would be nice to use it as if it was a valid payment method on a customer that has already attached it... in fact, I did attach it, it's just that it needs to be converted to another ID, which is not normal in production

keen star
#

You can't use pm_card_us in production.

fallow falcon
#

@keen star I am very aware of that

#

My point is that to use pm_card_us in Test I have to do things in test I would not do in production or that even make sense to do in production, which is not what the docs say about how to reason about test cards.

#

The docs imply they are valid attached cards for all customers at all times in test mode

#

so that one does not have to go through the "deprecated" attach API in test mode only. I say "deprecated" because it is documented in the API you and I referenced that it is succeeded by SetupIntents and PaymentIntents, however... those are not "testable" given the nature of PCI, so in tests.. use pm_card_us and friends.

#

I did, and I'm seeing unexpected behavior

#

Based on all of this, it seems like it's a valid bug in Test Mode

#

or the docs are lacking

keen star
#

The docs imply they are valid attached cards for all customers at all times in test mode can you share with me the doc that makes you think that these cards are already attached?

fallow falcon
#

That's the thing.. it seems "implied" because it does not say I have to attach them

https://stripe.com/docs/testing

Use test cards to validate your Stripe integration without moving real money. Test a variety of international scenarios, including successful and declined payments, card errors, disputes, and bank authentication. You can also test non-card payment methods.

#

And they API calls the default payment method a "default_payment_method"

#

so ... pm_card_us as far as one can tell from the docs, a valid payment method

smoky bobcat
#

πŸ‘‹ Taking over this thread, catching up now

fallow falcon
#

anyway... I'll try the converstion from payment method to payment method

#

and see if that fixes it

#

hi @smoky bobcat

keen star
#

Thanks for the feedback, I'll pass along to the docs team and see how we can improve it.

fallow falcon
#

@keen star if you look at the request response, it shows the "converted" pm_ id

#

which is also very confusing

#

this happens before attaching

#

any chance either of you could help me understand what this is for? It doesn't seem to do anything if I set it to a valid payment method. It succeeds even with pm_card_us

keen star
#

I need to go, please let @smoky bobcat know if you need any help

smoky bobcat
#

any chance either of you could help me understand what this is for? It doesn't seem to do anything if I set it to a valid payment method. It succeeds even with pm_card_us
Do you mean the purpose of setting payment_method with pm_card_us in Create Customer API?

fallow falcon
#

Thank you, @keen star !

#

@smoky bobcat Yes. It seems (now that I know the test payment methods need to be resolved to another payment method in test mode vs live) that setting payment method on create customer is just a "shortcut" for attach and resolve?

smoky bobcat
#

This is to attach a payment method to a customer. In general, we recommend using https://stripe.com/docs/api/payment_methods/attach?lang=curl#customer_attach_payment_method to attach a payment method to the customer. It allows multiple payment methods saved onto the customer

fallow falcon
#

I have a test proving payment_method does something, not nothing.

#

The whole confustion here is that pm_card_us and friends are called Payment Methods, but that are just cards

#

just pm_s per se

#

and nowhere in the docs about test cards does it say they have to be attached

#

that I could find

#

there is no where that says I have to resolve a test card to a new pm_123 either

#

anyway... I've got a test working even though it's not representative of what is actually happening in live mode. thank you both.