如何在 braintree 付款方式中更新客户
How to update customer in braintree payment method
我在yii2 rest中集成了braintree方法api Using this reference.。我想更新客户,但出现以下错误:
Missing argument 2 for Braintree\Customer::update()
下面是我的代码:
$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;
我在栈里怎么传参?
这是这个特定扩展的问题。请参阅 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
更清晰。
更新: 要覆盖组件,创建自己的 class 从 bryglen 的扩展,例如将它放在 common/components
文件夹中,以防使用高级应用程序。
namespace common\components;
class Braintree extends \bryglen\braintree\Braintree
{
public function call($command, $method, $values)
{
// Override logic here
}
}
然后将扩展名 class 替换为您在配置中自定义的名称:
'components' => [
'braintree' => [
'class' => 'common\components\Braintree',
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key',
],
],
我在yii2 rest中集成了braintree方法api Using this reference.。我想更新客户,但出现以下错误:
Missing argument 2 for Braintree\Customer::update()
下面是我的代码:
$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;
我在栈里怎么传参?
这是这个特定扩展的问题。请参阅 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
更清晰。
更新: 要覆盖组件,创建自己的 class 从 bryglen 的扩展,例如将它放在 common/components
文件夹中,以防使用高级应用程序。
namespace common\components;
class Braintree extends \bryglen\braintree\Braintree
{
public function call($command, $method, $values)
{
// Override logic here
}
}
然后将扩展名 class 替换为您在配置中自定义的名称:
'components' => [
'braintree' => [
'class' => 'common\components\Braintree',
'environment' => 'sandbox',
'merchantId' => 'your_merchant_id',
'publicKey' => 'your_public_key',
'privateKey' => 'your_private_key',
],
],