【问题标题】:How to update customer in braintree payment method如何在 Braintree 支付方式中更新客户
【发布时间】:2016-06-10 05:41:55
【问题描述】:

我已经在 yii2 rest api Using this reference. 中集成了 Braintree 方法。我想更新客户,但出现以下错误:

缺少 Braintree\Customer::update() 的参数 2

下面是我的代码:

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

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

                            ]);
                        print_r($response); die;

我是栈在这里如何传递参数?

【问题讨论】:

标签: yii2 braintree


【解决方案1】:

这是这个特定扩展的问题。请参阅 Github 上的 this issue

问题 OP 建议进行此修复:

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);
    }
}

虽然扩展作者建议这样做:

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

无论哪种方式,您都需要用自己的方式覆盖此组件并应用补丁。

请注意,应用程序中的代码量很小(一个文件中有 64 行),因此您可以创建自己的包装器或找到更好的包装器,因为此问题仍未解决。

也许直接使用braintree_php 方法会比神奇的call 更清晰。

更新:要覆盖组件,请创建自己的从 bryglen 扩展的类,例如将其放在 common/components 文件夹中,以防使用高级应用程序。

namespace common\components;

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

然后将扩展类名称替换为配置中的自定义名称:

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

【讨论】:

  • 您能否指导我或提供任何提示如何覆盖此组件,因为我是 yii2 的新手。谢谢
  • @Arunendra 我用更详细的说明更新了答案。
猜你喜欢
  • 2023-03-14
  • 2015-10-10
  • 2016-11-05
  • 2018-01-06
  • 2019-03-26
  • 2013-01-05
  • 2014-12-29
  • 1970-01-01
  • 2015-04-03
相关资源
最近更新 更多