#nukesforbreakfast_error

1 messages ยท Page 1 of 1 (latest)

stone deltaBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1501392090016256113

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

cinder sluice
#

๐Ÿ‘‹ hi there, please give me a moment to catch up on the question

#

You'd need to pass the payment_method parameter too

#

So the request you'd want to make should look like this:

 email: 'test@email.com',
 invoice_settings: {
    default_payment_method: "pm_card_visa", 
  },
 payment_method: "pm_card_visa", 
round fjord
#

stripe.error.InvalidRequestError: Request req_K9jmmBTYVsVwbC: Received unknown parameter: payment_method

cinder sluice
#

Oh because you're updating a specific customer object ; would it be possible for you create a new test customer with the snippet above? It's more straight-forward.
Otherwise, you'd need to attach "pm_card_visa" to cus_USprKjSEIchPoy first using https://docs.stripe.com/api/payment_methods/attach, then after that set it as default using invoice_settings.default_payment_method

round fjord
#

I already am attaching it and then updating it.

#
subscription_start_time = timezone.now()
# Create the test clock.
test_clock = stripe_create_test_clock(
    name="test_update_subscription_cancel_at_no_final_month_proration",
    frozen_time=int(subscription_start_time.timestamp()),
)


# Create the customer.
customer = stripe_create_customer(
    name="test_update_subscription_cancel_at_no_final_month_proration", test_clock=test_clock.id
)
# Attach the test payment method using Stripe's build in testing payment methods.
# https://docs.stripe.com/testing?testing-method=payment-methods#cards
stripe_client.PaymentMethod.attach("pm_card_visa", customer=customer.id)
# Update the customer to have this as their default payment method.
customer = stripe_client.Customer.modify(
    customer.id, invoice_settings={"default_payment_method": "pm_card_visa"}
)
#

Request logs in order:

  • req_6dZc7WnWtO6ZfT
  • req_Jl7GvfpmAVBt8V
  • req_11DDitV252fRkK
  • req_K9jmmBTYVsVwbC
cinder sluice
#

I see, thanks for sharing your code snippet.

At this section: stripe_client.PaymentMethod.attach("pm_card_visa", customer=customer.id) โ€” when the payment method is attached, the customer's payment method already takes the form of a new payment method ID (which is why you saw pm_1TTu1AA9yDCrR6n1j55ABG5A)

So if you're attaching payment method to a customer first then setting them as default later, you'd need to add an additional step in between to lookup the customer's payment method to obtain the actual pm_ ID by using https://docs.stripe.com/api/payment_methods/customer_list

Once you obtain the actual Payment MethodID (e.g. it should have random characters after the pm_ prefix, like pm_1TTu1AA9yDCrR6n1j55ABG5A, and not pm_card_visa ), passing the following should work

invoice_settings: {
    default_payment_method: "{{actual payment method ID}}", 
  }
round fjord
#

how can I create this customer with the default payment method already attached?

#

every time I try, I get the error that the payment method isn't attached to the customer.

#
# Retrieve the test payment method.
# https://docs.stripe.com/testing?testing-method=payment-methods#cards
payment_method = stripe_client.PaymentMethod.retrieve("pm_card_visa")
# Create the customer.
customer = stripe_create_customer(
    name="test_update_subscription_cancel_at_no_final_month_proration",
    test_clock=test_clock.id,
    invoice_settings={"default_payment_method": payment_method.id},
)
#

stripe.error.InvalidRequestError: Request req_xaoN4QLNjPMB3K: The customer does not have a payment method with the ID pm_1TTuTfA9yDCrR6n14QvzbM02. The payment method must be attached to the customer.

cinder sluice
#

You're currently only setting a default payment method when creating the customer

#

the customer creation call should look like this if you want to attach pm and set it as default in 1 step

email: 'test@email.com', 
  name: "test name", 
  invoice_settings: {
    default_payment_method: "pm_card_visa", 
  },
   payment_method: "pm_card_visa"
round fjord
#

ah I see, it's only available at customer creation time, not update time.

cinder sluice
#

yes

round fjord
#

let me try that

#

ah yes, that worked! Thanks for clarifying that I have to retrieve the test card to get the actual ID.

cinder sluice
#

Happy to help ๐Ÿ™‚

round fjord
#

that information might be good to add to the docs. I didn't see it there when I looked.

cinder sluice
#

which pages were you looking at?

cinder sluice
round fjord
#

oh, so I don't actually need to retrieve the actual ID?