1
votes

I have integrated braintree method in yii2 rest api Using this reference.. I want to update the customer but I am getting following error:

Missing argument 2 for Braintree\Customer::update()

Below is my code :

 $braintree = Yii::$app->braintree;
       $response = $braintree->call('Customer', 'update','15552090',[                               

                                      'firstName' => 'test-1545',
                                      'lastName' => 'asdf',
                                      'company' => 'New Company',
                                      'email' => '[email protected]',
                                      'phone' => 'new phone',
                                      'fax' => 'new fax',
                                      'website' => 'http://new.example.com'

                            ]);
                        print_r($response); die;

I am stack here how to pass the arguments?

1
Please provide reference to extensions you are using. - arogachev

1 Answers

1
votes

It's a problem of this particular extension. See this issue on Github.

Issue OP recommends this fix:

public function call($command, $method, $values, $values2 = null)
{
    $class = strtr("{class}_{command}", [
        '{class}' => $this->_prefix,
        '{command}' => $command,
    ));

    if ($values2) {
        return call_user_func(array($class, $method), $values, $values2);
    else {
        return call_user_func(array($class, $method), $values);
    }
}

while extension author recommends this:

if (is_array($values)) {
   call_user_func_array(...);
} else {
   call_user_func(...);
}

Either way you need to override this component with your own and apply a patch.

Note that the amount of code in application is small (64 lines in one file) so you can create your own wrapper or find better one because this issue is still not fixed.

And maybe is better to directly use braintree_php methods which will be more clear than magical call.

Update: To override component, create own class extending from bryglen's, place it for example in common/components folder in case of using advanced app.

namespace common\components;

class Braintree extends \bryglen\braintree\Braintree
{
    public function call($command, $method, $values)
    {
        // Override logic here
    }
}

Then replace extension class name with your custom one in config:

'components' => [
    'braintree' => [
        'class' => 'common\components\Braintree',
        'environment' => 'sandbox',
        'merchantId' => 'your_merchant_id',
        'publicKey' => 'your_public_key',
        'privateKey' => 'your_private_key',
    ],
],