【问题标题】:Can we update the credit card detail using braintree update method without card number of the user?我们可以在没有用户卡号的情况下使用 Braintree 更新方法更新信用卡详细信息吗?
【发布时间】:2017-05-20 00:28:16
【问题描述】:

我必须在我的项目中使用 braintree 更新方法更新用户的信用卡信息。

我的控制器更新卡的代码段如下-

case 'update':
                $expirationMonth = $this->input->post('expiration_month');
                $expirationYear = $this->input->post('expiration_year');
                if (!empty($expirationMonth) && !empty($expirationYear)) {
                    if (date('Y') > $expirationYear) {
                        die('expired');
                    } else if ($expirationYear == date('Y')) {
                        if (date('m') > $expirationMonth)
                            die('expired');
                    }
                }
                $cardId = $this->input->post('cardId');
                $cardNumber = $this->input->post('card_num');
                $streetAddress = $this->input->post('street_add');
                $cardCity = $this->input->post('card_city');
                $cardState = $this->input->post('card_state');
                $postalCode = $this->input->post('postal_code');
                $customerId = $this->input->post('customer_id');
                $vaultToken = $this->input->post('vault_token'); 
                $cvvCode = $this->input->post('cvv_code');
                $data['default_status'] = $this->input->post('default_status');
                $data['card_type'] = $this->input->post('cardType');
                $this->load->library("braintreelib");
                $result = Braintree_Customer::update($customerId, array(
                //we can create a credit card at the same time
                'creditCard' => array(
                    //'cardholderName' => $this->input->post('cardholder_name'),
                    //'number' => $cardNumber,
                    'expirationMonth' => $expirationMonth,
                    'expirationYear' => $expirationYear,
                    'cvv' => $cvvCode,
                    'billingAddress' => array(
                        /* Optional Information you can supply */
                        'streetAddress' => $streetAddress,
                        'locality' => $cardCity,
                        'region' => getUsStateName($cardState)->abbrev,
                        'postalCode' => $postalCode,
                    ),
                    'options' => array('verifyCard' => true)
                )
                ));
                if (isset($cardId)) {
                  if($result->success){ 
                    $this->load->model('updatedetails_model');
                    if($data['default_status']){
                        $this->common->saveDetails(TBL_RS_PAYMENTDETAILS, array('default_status' => 0, 'card_type' => $cardType), array('currentuserid' => $currentUserId, 'currentroleid' => $this->input->post('roleId')));
                    }    
                    $cardDetailId = $this->updatedetails_model->addedit_carddetails($data, $cardId); 
                    if (!$cardDetailId) {
                        echo 'error';
                        exit;
                    }
                   }else{
                     foreach ($result->errors->deepAll() as $error) {
                        $errorFound = $error->message . "<br />";
                     }
                     //echo $errorFound ;
                     echo $errorFound;
                     exit;
                   } 
                } else {
                    echo 'invalidcarddetails';
                    exit;
                }
                $details['carddetails'] = $this->profile->getUserCardDetailsByUserId($currentUserId);
                foreach($details['carddetails'] as $index => $value){
                    $paymentMethod = Braintree_PaymentMethod::find(base64_decode($value->vault_token));
                    $details['carddetails'][$index]->lastDigit = $paymentMethod->last4;
                    $details['carddetails'][$index]->cardType = $paymentMethod->cardType;
                    $details['carddetails'][$index]->cardholderName = ucfirst($paymentMethod->cardholderName);
                }
                $this->data['carddetails'] = $details['carddetails'];
                echo $b = $this->load->view('operatorCardListing', $this->data, TRUE);
                break;

当我尝试运行此代码时,我收到了错误 -

信用卡必须包含号码、paymentMethodNonce 或 venmoSdkPaymentMethodCode。

我的要求是更新信用卡信息,不输入卡号。

没有信用卡号可以更新卡吗?

【问题讨论】:

  • 您希望具体更新哪些付款方式?
  • 您是否尝试将客户卡更新为没有编号的卡?如果是这样我认为不可能,因为当您添加购物车时,它基本上确认了它。为什么不直接删除卡?

标签: paypal codeigniter-2 braintree


【解决方案1】:

全面披露:我在 Braintree 工作。如果您还有任何问题,请随时联系support

您无需指定信用卡号即可更新信用卡。 Braintree 建议使用 payment method functions instead of the credit card object 执行此操作,以帮助您避免在您的网站上处理原始信用卡数据。

在您发布的代码中,您拨打的是客户更新电话,而不是信用卡更新电话。当您拨打客户更新电话时,您将发送一系列信用卡。 Braintree 将尝试通过将该数组中的卡片添加到客户记录中来更新客户。客户更新调用不会向网关发送客户卡应该更新的信号。而不是客户更新调用,您将希望使用 [付款方式更新调用][pm_upadte]。

要仅更新卡的一部分,例如仅更改到期日期或 CVV,您可以使用 nonce 付款方式。通过tokenizing only the details that you want to change 创建一个付款方式nonce。一旦你有一个只引用你想要更改的细节的随机数,你可以将它传递给payment method update call。这就是它在 php 中的样子:

$result = Braintree_PaymentMethod::update('the_token', [
    'paymentMethodNonce' => 'nonce_from_your_client'
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-08
    • 2020-04-24
    • 2017-05-06
    • 2014-09-19
    • 2017-05-07
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    相关资源
    最近更新 更多