#Gesundheit-card-PaymentMethod
1 messages · Page 1 of 1 (latest)
I'm using the "create a subscription through elements" method, and I'm just trying to retrieve the payment method Id from the payment intent
Do you have the id of a payment method you want to get the card for?
yeah, it's a card_xxxx thing right
I was thinking the pm_123 for the payment method
what i'm doing is basically
- get the customer object using the customer's id
- get the customer's
customer.invoice_settings.default_payment_method_id - get the payment intent of the invoice
- get the payment method id of the payment intent
- if the two
payment_method_ids don't match, then update the customer's with the new payment_method_id
am I mistaking payment method for payment_method? I'm starting to feel like they're not the same thing
Sorry for being imprecise
But yes in this case I meant them to be the same thing
Can you give me the value of a customer.invoice_settings.default_payment_method_id that you want to retrieve the original card object for?
And ah this is so you can check the fingerprint right?
exactly (and update to new card if it doesn't match)
that's the hard part. It always return null.
No matter how i try to set it through the dashboard, it's always null.
I don't think it is settable in the dashboard
I think when we talked about the Dashboard before we noticed that that set the default_source correct?
Not necessarily, you can set that field with the API now.
which is what we're doing here -- using the API to get, and set that property if it doens't match
It's not a problem if initially the value is null, since a new customer will always have a null value to that
so the next question is the payment_intent's payment_method is also null for some reason
if you want the PaymentIntent Id
here's a snippet of what i got from the PaymentIntent (thru CLI). This also indicates that the payment_method of the intent is not set, but instead the source is set.
Right, so that is just what the Dashboard does, unfortunately we can't set the invoice_settings.default_payment_method_id property there.
If you use the CLI/API to set it otherwise I think that will fill out the field that you want
I know we discussed setting it and doing this check in webhooks before but you can do it outside of that for your testing right?
i've only implemented
- set it after receiving webhook -- didn't work
- get the customer's payment_method through code -- didn't work
I understand, but that's not the problem here. I am using Stripe.NET to do this = through API.
The chain of problems are:
- The problem here is I cannot get the PaymentIntent's
payment_method - due to (1) , i cannot set the customer's invoice_settings.default_payment_method to a value.
- due to (2), I cannot get the customer's invoice_settings.default_payment_method (it will always be null).
--
On a second thought, maybe it is because the dashboard only allows me to set to the source of a customer, which would lead me to the series of problems
It was never going to work in the first place
And you were talking about setting this in the invoice.paid event right?
yep
You can still use what the Dashboard does I believe
but the subscription is paid using an order of sources. If the dashboard will only set any card to the source instead of payment_method, then i'm never going to get anything from payment_method
The Dashboard still creates a PaymentMethod when you input one. It doesn't get set in that one setting but it will show up if you list the customer's PaymentMethods https://stripe.com/docs/api/payment_methods/list
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So you are only ever setting this via Dashboard? I thought you were taking in payment info initially when setting up the subscriptions correct?
You can create a test PaymentMethod directly in the API and attach the resulting object to your customer https://stripe.com/docs/api/payment_methods/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
but is that how purchasing a subscription will behave?
I can totally use the list to implement the default payment method feature. Just do aggressive housekeeping and keep the list to one element. But that defeats the purpose of having a default_payment_method in the first place
I mean to initially set this
Can you remind me how you are setting up these subscriptions?
I'm just following https://stripe.com/docs/billing/subscriptions/elements
When listening to invoice.paid event, I check whether the billing_reason is subscription_create or manual.
if it's either one of the two, then I also take the PaymentIntent ID to fetch the payment_method.
I take this payment_method and do fingerprint comparison with that of the customer's. The rest you know already
Okay I see. Apologies I see where you specified this and I missed it
So when you get to the step where it wants you to look at invoice_paid or invoice_succeeded and you check that Invoice's PaymentIntent's PaymentMethod, is that null?
yep
as attached here
Interesting. And you are passing the card and billing_details in to the payment_method parameter of your confirmCardPayment call>?
That is a no, because I am currently only testing it through the dashboard, so it didn't go that way.
Right. You've said that. Caught up.
So a quick way to create a subscription that would look like what you will get from the frontend would be use the backend API to create a customer, a PaymentMethod, and then create a Subscription
https://stripe.com/docs/api/customers/create
https://stripe.com/docs/api/paymentmethods/create
https://stripe.com/docs/api/subscriptions/create
creating a customer that's solved
do you mean by i need to explicitly call to create a payment method first, then create the subscription afterwards?
I mean in this test case yes
So because you don't have the frontend you will need to do some other API noodling to get a Subscription set up and paid for similarly
Which actually needs one last bit of detail:
Actually do you know what might be even easier?
We have a sample with elements for creating a subscription, before your frontend is ready you can just use this and swap it out to your subscription plan ids and such https://github.com/stripe-samples/subscription-use-cases/tree/master/fixed-price-subscriptions
OR
You can use checkout to create a subscription https://stripe.com/docs/billing/subscriptions/checkout
Apologies for taking a bit to get there.