#dev123-sub-pm

1 messages · Page 1 of 1 (latest)

lusty ivy
#

hello, so I think I know what the issue is

#

you attached a PaymentMethod to the Customer

#

is that right

zealous kayak
#

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.

lusty ivy
#

so yeah the answer is the commented out line in your code

zealous kayak
#

you said = "you attached a PaymentMethod to the Customer" => I didn't attach by API, it is in the dashborad

lusty ivy
#

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

zealous kayak
#

exactly

lusty ivy
#

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

zealous kayak
#

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'

lusty ivy
#

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

zealous kayak
#

ok, right

#

Okay, so I need to recover the customer's default payment? That's right

lusty ivy
#

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

zealous kayak
#

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 !

raven fjord
#

I don't really grasp that code so hard to say

zealous kayak
#

ok,

raven fjord
#

why are you listing and looping with a $a variable?

zealous kayak
#

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 ?

raven fjord
#

what does that mean "the list of client" Do you mean customer?

#

why do you loop?

zealous kayak
#

sorry, yes customer

raven fjord
#

So why do you loop over any customer? Don't know which customer they are already?

zealous kayak
#

I check from the $stripe->customers->all all the customer. If eMail= $_SESSION['idMail'] i take the id and the paiement

raven fjord
#

so you're listing every single customer to find thecurrent customer by email?

zealous kayak
#

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

raven fjord
#

yeah you can't do that

#

what happens where you have 1M customers

zealous kayak
#

I will go on hollidays....😆

raven fjord
#

really you should be caching this in your database

#

you really shouldn't really even rely on email

zealous kayak
#

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.

raven fjord
#

that would let you get the customer (though it's a list)

zealous kayak
#

yes, very good, thank for this,👍 before I get 1M customers...

raven fjord
#

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

zealous kayak
#

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

raven fjord
#

do you have an old integration? Is it brand new?

zealous kayak
#

It is a brand new

raven fjord
#

okay so yeah never use default source, never use tokens

zealous kayak
#

Ok,

#

Yes I follow the canonical doc in first step, and read the docs,

raven fjord
#

but then you wouldn't use default_source

#

we explain exactly how to create a subscription, collect card details client-side, etc.

zealous kayak
#

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

raven fjord
#

absolutely not

#

The flow usually is this

1/ Create a Subscription on the right Price
2/ Confirm the underlying PaymentIntent client-side

zealous kayak
#

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 ?

raven fjord
#

all good, Stripe can appear quite complex

#

I don't know, do you want 3 products at once on one subscription?

zealous kayak
#

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

raven fjord
#

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

zealous kayak
#

there's no reason to "developer a payment intent via Checkout" =< I wanted to says simply checkOut

raven fjord
#

sure but there's no reason to accept a payment via Checkout

#

why accept the first payment and then try to start a subscription?

zealous kayak
#

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👍

raven fjord
#

okay so in theory you don't need to do anything after Checkout!

#

it even sets the right default payment method

zealous kayak
#

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

raven fjord
#

Awesome!

#

Have a great night 🙂

zealous kayak
#

Thank you again for your help and the wonderful job you do 😉