laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.38k stars 679 forks source link

Calling updateDefaultPaymentMethod() with the customer's payment method #746

Closed u01jmg3 closed 5 years ago

u01jmg3 commented 5 years ago

Hello,

Previously for one off invoice payments I could do:

$user->createAsStripeCustomer();
$user->updateCard($request->stripeToken);

I see this has changed and from your Charges test you must now call updateDefaultPaymentMethod().

$user->createAsStripeCustomer();
$user->updateDefaultPaymentMethod('pm_card_visa');

What is the recommended way to determine the customer's payment method? Using the request? I see you have hard coded the method pm_card_visa in every test.

(Apologies if this is more of a question but it came up during my upgrade to v10.)

driesvints commented 5 years ago

Hey @u01jmg3, no problem. In Cashier 10 it's possible to attach multiple payment methods to a customer. You can retrieve the default billing payment method with with the defaultPaymentMethod method: https://laravel.com/docs/5.8/billing#retrieving-payment-methods

Does that answers your question? Let me know if anything is unclear in the docs/upgrade guide.

u01jmg3 commented 5 years ago

What happens if the customer is brand new? My use case is customers paying for a conference who may never have used our site before and may never again. They stop by, register for a conference and then pay. They're then invoiced immediately.

Already came across these in your docs:

$user->paymentMethods(); // null
$user->defaultPaymentMethod(); // null

// dd($request->all());
// "_token"          => "Q......................................."
// "stripeToken"     => "tok_........................"
// "stripeTokenType" => "card"
// "stripeEmail"     => "user@land.com"

(To note I am testing using the Stripe test card details (4242 etc.).)

driesvints commented 5 years ago

That's strange because $user->paymentMethods(); should return an exception when you try to access it as a non-Stripe customer.

I'm not sure what you're asking though. Your original example above is the correct one. It's the same thing you had to do with the token based api only now with the payment methods api.

  1. Create as a stripe customer
  2. Add a default payment method
  3. Use invoiceFor method to generate an invoice for whatever you want to invoice your customer for. (make sure you handle SCA if you're in the EU)
driesvints commented 5 years ago

@u01jmg3 I see you updated your message and I see you're still using the old token based API. In Cashier 10 everything's moved to the new Payment Methods API. This is noted here and you can read more about how to store payment methods here. Let me know if that's clear or not.

u01jmg3 commented 5 years ago

Thanks @driesvints - you've put me on the right track.

Otienoh commented 5 years ago

@u01jmg3 Did you figure this out?