#dev123-sub-pm
1 messages · Page 1 of 1 (latest)
hello, so I think I know what the issue is
you attached a PaymentMethod to the Customer
is that right
Hello, thanks for trying to help me. In my dashboard the cutomer have a payment. When I create a subscription I send theis code :
$response=$stripe->subscriptions->create([
'customer' => $custId,
'items' => [
['price' => $priceId, ],
],
// 'default_payment_method' =>'',
]);
but I have a return like :
Uncaught (Status 400) (Request req_l9ITt9cHWysafi) This customer has no attached payment source or default payment method.
so yeah the answer is the commented out line in your code
you said = "you attached a PaymentMethod to the Customer" => I didn't attach by API, it is in the dashborad
you have a customer who has a PaymentMethod attached, but you need to pass that PaymentMethod ID under
```default_payment_method: 'pm_123'`
yes however it is, it is attached to the Customer but it is NOT the default on the Customer
exactly
no we're saying different things
I think you misunderstood me
I gave you the answer to your question
your customer has a PaymentMethod. Attached only, not default.
So when you create a Subscription, you need to tell the API what PaymentMethod you want to use, from that customer
which you have commented out
yes, understand, but in the API specification => default_payment_method is optional. But seem to be required. So If I put theis :
'default_payment_method' =>'card',
I have a return :
Uncaught (Status 400) (Request req_svooHZ2mJS6ApX) No such PaymentMethod: 'card'
you need to pass the PaymentMethod ID like I showed you here
default_payment_method: 'pm_123'`
it is optional only if your customer has a invoice_settings.default_payment_method set on the Customer object, yours does not
no
you already have a PaymentMethod on the Customer
you have say pm_123455 on the Customer cus_123
you just need to pass it
in your API request
ok,
my problem is to get the pm_123455 from the client. I have understand I can do it with sqomething like :
for($a=0;$a<count($response->data);$a++){
if($debug==1) echo '$a='.$a;
$id=$response->data[$a]->id;
$email=$response->data[$a]->email;
if($debug==1) echo ' id => '.$id;
if($debug==1) echo ' email => '.$email;
if($debug==1) echo ' - - - - - - ';
if($email==$_SESSION['idMail'] && $trouve==false) {
$custId=$id;
$paiementDefaut=$response->data[$a]->default_source;
$trouve=true;
}
}
I check all clients and when eMail =eMail I caught the payement defaut source from data. Do you think it is correct ? thank a lot !
I don't really grasp that code so hard to say
ok,
why are you listing and looping with a $a variable?
I check from the list of clients what is the client_id
I found, i take the payment default_source. That is correct ?
If I found, I take the payment default_source. That is correct ?
sorry, yes customer
So why do you loop over any customer? Don't know which customer they are already?
I check from the $stripe->customers->all all the customer. If eMail= $_SESSION['idMail'] i take the id and the paiement
so you're listing every single customer to find thecurrent customer by email?
Yes, I don't have the customer_id in session or DB. So yes I check for all and check eMail first
I am developping a backOffice, with subscriptions. At this moment the customer perhaps didn't already been connected with stripe. So I don't have his stripe customer_id
but I understand that my problem is to get the payment ID at this step and pass it to the create subscription step. So,
$paiementDefaut=$response->data[$a]->default_source;
doesn't work.
I see you are right that the default_payment_method comme from the invoice_settings object
I will go on hollidays....😆
really you should be caching this in your database
you really shouldn't really even rely on email
ok you must be right . But I go step by step as I am a newbie in stripe
This is because in my system the e-mail = the client_id. But I can store the stripe client_id , it's not a big problem.
https://stripe.com/docs/api/customers/list#list_customers-email have you seen that parameter?
that would let you get the customer (though it's a list)
yes, very good, thank for this,👍 before I get 1M customers...
I mean now I would say
Okay so now, what's blocking you? You seem to look at default_source, why? This is multi-years old and deprecated and my colleague was talking to you about default payment method
But if I create a new subscription and the client have no already an invoice ? How to pass the default_payment_method in subscription ? We don't need it ?
default_source is deprecated, I didn't know that. Ok
How to pass the default_payment_method in subscription ?
https://stripe.com/docs/api/subscriptions/create#create_subscription-default_payment_method
do you have an old integration? Is it brand new?
It is a brand new
okay so yeah never use default source, never use tokens
did you start with our canonical doc? Like we have detailed end to end docs: https://stripe.com/docs/billing/integration-builder
but then you wouldn't use default_source
we explain exactly how to create a subscription, collect card details client-side, etc.
So I understand before create a subscription you have to create a paiement with the priceId that correspond to a product which is a subscription
absolutely not
The flow usually is this
1/ Create a Subscription on the right Price
2/ Confirm the underlying PaymentIntent client-side
Sorry if we misunderstand. I am french and sometimes is difficult to me.
1/ Create a Subscription on the right Price => I have created 3 products with subscription. It is right ?
all good, Stripe can appear quite complex
I don't know, do you want 3 products at once on one subscription?
yes it is complex, but it does the job when we have understand
No there are 3 subscriptions possible
the client want to buy one of them only
So I have developped a paymentIntend ( ie checkout payment ) and it works
after that I created a subscription for this customer and for this product
and it works,
but in reality my problem is to give the user the possibility to cancel this subscription when i want.
So I was trying to get the subscription_id. And I just understand for my test I disable the payment step. This give me the error of payment method.
Because I disabled the paiement step (for test) before the subscription. So i didn't work like that.
sorry => but in reality my problem is to give the user the possibility to cancel this subscription when He want.
In fact my problem is to have the correct subscriptionçId to cancel it
yeah I'm sorry it really doesn't make sense
Checkout can start the subscription for you already
there's no reason to "developer a payment intent via Checkout"
Checkout would accept the first payment and start a subscription at the same time for you
there's no reason to "developer a payment intent via Checkout" =< I wanted to says simply checkOut
sure but there's no reason to accept a payment via Checkout
why accept the first payment and then try to start a subscription?
Checkout would accept the first payment and start a subscription at the same time for you ==> right, yes that what I seen. But perhaps an misundersatnding from me. I understand now it'is not necessary to create a subscription again after a paiement. thank👍
okay so in theory you don't need to do anything after Checkout!
it even sets the right default payment method
Yes clear now,
I will put that aside for tonight, I understood my mistake. Tomorrow I will see why I am not correctly recovering the subscription ID in the event of a cancellation, but certainly I created 2 subscription at time
Thank you again for your help and the wonderful job you do 😉