#nukesforbreakfast_error
1 messages ยท Page 1 of 1 (latest)
๐ 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.
- rccausey_billing-passfees, 7 hours ago, 16 messages
- nukesforbreakfast_best-practices, 1 day ago, 15 messages
๐ 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",
stripe.error.InvalidRequestError: Request req_K9jmmBTYVsVwbC: Received unknown parameter: payment_method
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
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"}
)
I also don't know where this payment_method parameter is coming from. There's no such parameter on the create or modify customer API docs:
Request logs in order:
req_6dZc7WnWtO6ZfTreq_Jl7GvfpmAVBt8Vreq_11DDitV252fRkKreq_K9jmmBTYVsVwbC
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}}",
}
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.
That's because stripe_create_customer is not passing the payment_method param: https://docs.stripe.com/api/customers/create#create_customer-payment_method
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"
ah I see, it's only available at customer creation time, not update time.
yes
let me try that
ah yes, that worked! Thanks for clarifying that I have to retrieve the test card to get the actual ID.
Happy to help ๐
that information might be good to add to the docs. I didn't see it there when I looked.
which pages were you looking at?
Ah I see, it's actually here: https://docs.stripe.com/billing/customer#manage-customers
oh, so I don't actually need to retrieve the actual ID?