dbr
dbr

Reputation: 1047

Laravel 5.3, Cashier - Braintree - Single Charges

I followed the Laravel docs to implement the Cashier but I can't get it to work.

In short:

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?

Upvotes: 2

Views: 527

Answers (1)

ARemesal
ARemesal

Reputation: 2963

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.

Upvotes: 1

Related Questions