添加信用卡可成功返回但未保存CC:Braintree PHP API

时间:2018-09-30 20:51:27

标签: php api codeigniter braintree braintree-sandbox

我计划通过我的系统更新默认信用卡,但我读到here,这是不可能的,它应该只是新创建的信用卡。我正在关注this文档。我的沙盒帐户中有2种付款方式。

这是我的代码:

function create_cc($customer_id, $attributes){
    //Array ( [token] => j699th [cvv] => 222 [number] => 4005519200000004 [expirationMonth] => 12 [expirationYear] => 22 ) 

    $result = Braintree_Configuration::gateway()->paymentMethodNonce()->create($attributes['token']);

    return Braintree_Configuration::gateway()->paymentMethod()->create([
    'customerId' => $customer_id,
    'paymentMethodNonce' => $result->paymentMethodNonce->nonce,
    'cvv' => $attributes['cvv'],
    'number' => $attributes['number'],
    'expirationMonth' => $attributes['expirationMonth'],
    'expirationYear' => $attributes['expirationYear'],
    'options' => [
        'makeDefault' => true,
        'verifyCard' => true
      ]
    ]);

}

调用上面的函数时,它返回true,因此我希望Braintree中的Payment Methods为3。但是,当我重新加载页面时,我仍然获得2种付款方式。我确保数组数据中有paymentMethodNonce'enter image description here

更新:

沙箱:它必须是“ fake-valid-nonce”,而不是实际的。

生产:无法正常工作。

这是我的代码:

function create_cc($customer_id, $attributes){
    $nonce = '';
    if($this->environment == 'production'){
        $result = $this->gateway->paymentMethodNonce()->create($this->create_client_token());//$this->gateway->paymentMethodNonce()->create($this->create_client_token());
        $nonce = $result->paymentMethodNonce->nonce;
    } else if($this->environment == 'sandbox'){
        $nonce = 'fake-valid-nonce';
    }

    return $this->gateway->paymentMethod()->create([
    'customerId' => $customer_id,
    'paymentMethodNonce' => $nonce,
    //'cvv' => $attributes['cvv'],
    'number' => $attributes['number'],
    'expirationMonth' => $attributes['expirationMonth'],
    'expirationYear' => $attributes['expirationYear'],
    'options' => [
        'makeDefault' => true,
        'failOnDuplicatePaymentMethod' => true,
        //'verifyCard' => true
      ]
    ]);
}

我可能做错了什么?

0 个答案:

没有答案