Добавление кредитной карты возвращает успех, но CC не сохранен: PHP API Braintree - PullRequest
0 голосов
/ 30 сентября 2018

Я планирую обновить кредитную карту по умолчанию через мою систему, но я прочитал здесь , что это невозможно и что это должна быть только что созданная кредитная карта.Я следую за этой документацией.У меня есть 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, поэтому я ожидаю, что Методы оплаты будут равны 3 вBraintree.Но когда я перезагружаю страницу, я все равно получаю 2 способа оплаты.Я удостоверился, что у меня есть paymentMethodNonce' в моих данных массива.enter image description here

ОБНОВЛЕНИЕ:

Песочница: она должна быть фиктивной, а не фактической.

Производство: не работает.

Вот мой код:

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

Что я могу делать не так?

...