2

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 my config/services.php and added the SDK calls to my AppServiceProvider.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?

dbr
  • 1,037
  • 14
  • 34

1 Answers1

1

This was a bug in the Billable trait. Have been fixed on July 15th '17, you can read about the bug and the fix: https://github.com/laravel/cashier-braintree/commit/f0c133860d175a30676eedbab8d2345a59432910

You're in the way: the problem was with the braintree_id attribute being null when calling $this->paymentMethod().

Just launch a composer update on your project.

ARemesal
  • 2,923
  • 5
  • 24
  • 23
  • Thank you for your reply. I've moved on from this but I would need to get back to my code to see how I've fixed this as it was some time ago. – dbr Jul 31 '17 at 13:40