Closed carizzapanopio closed 4 years ago
We'll need a little more code here to reproduce the problem.
$user_card_details = $user->defaultPaymentMethod();
var_dump($user_card_details);
var_dump($user_card_details::$owner);
@driesvints
var_dump($user_card_details::$owner);
The owner property isn't accessible indeed. But we can add a getter for it. It's btw the same instance as the $user
property. The paymentMethod
property can be accessed by asStripePaymentMethod
.
Sorry to barge in here. I am experiencing a similar issue with laravel 6 and cashier 10
To create a subscription:
$user = User::find(1);
$user->newSubscription('default', 'premium')->create($paymentMethod);
to get the $paymentMethod
$paymentMethods = $user->paymentMethods();
But as experienced, paymentMethod is a protected property.
Hello @0dp
I was able to access the paymentMethod through this:
$user->defaultPaymentMethod()->asStripePaymentMethod();
Hi @carizzapanopio thanks for pitching in. Unfortunately this approach did not work for me since asStripePaymentMethod is not part of $user?
I feel like a huge looser, because I just wanted to get it to work so I wrote a Guzzle method to fetch the payment_methods id from the customer id 😭
I noticed that $user->defaultPaymentMethod()
returns an object but create() wants a string 🧐
It does hold the paymentmethod🤷♂️
hi @0dp . if you check the contents if $user->defaultPaymentMethod()->asStripePaymentMethod(), this wil return the payment method object. if the create method needs a string, pass the payment method id instead.
$paymentMethod = $user->defaultPaymentMethod()->asStripePaymentMethod();
$user->newSubscription('default', 'premium')->create($paymentMethod->id);
Thanks! This was really helpful 🙏
Sent in a PR for this: https://github.com/laravel/cashier/pull/877
I am getting an error "Cannot access protected property Laravel\Cashier\PaymentMethod::$owner" $user->defaultPaymentMethod() results to this.
However, I couldnt access $owner and $paymentMethod property.
php version: 7.2 laravel: 5.8 laravel cashier: 10.5 stripe-php: 7.14