I followed the Laravel docs to implement the Cashier but I can't get it to work.
In short:
- made and migrated migrations
- added Billable to my
User.php
model - added keys to my
.env
, referred to them in myconfig/services.php
and added the SDK calls to myAppServiceProvider.php
If needed I can paste the code but it's the same (I checked but you never know) as in the docs.
Now if I try to run the
$user = User::find(2);
$response = $user->charge(15);
dd($response);
in my Controller I get the error:
InvalidArgumentException in CustomerGateway.php line 567:
expected customer id to be set
---
in CustomerGateway.php line 567
at CustomerGateway->_validateId(null) in CustomerGateway.php line 198
at CustomerGateway->find(null) in Customer.php line 106
at Customer::find(null) in Billable.php line 440
at User->asBraintreeCustomer() in Billable.php line 29
at User->charge('15') in MyController.php line 787
It seems to me that the error is here:
at Customer::find(null) in Billable.php line 440
which gives null
for the CustomerGateway
. So here is the code that gets called in line 29 of Billable.php
$customer = $this->asBraintreeCustomer();
public function asBraintreeCustomer()
{
return BraintreeCustomer::find($this->braintree_id);
}
Thanks!
UPDATE
I did dd($this)
in asBraintreeCustomer()
method and got my user. But the braintree_id
attribute is null
.
How do I populate these?
Should I do it manually?