简体   繁体   中英

Can we update the credit card detail using braintree update method without card number of the user?

I have to update the credit card information of the user in my project using braintree update method.

The code segment of my controller for the updation of the card is below -

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;

When I am trying to run this code, I am getting the error -

Credit card must include number, paymentMethodNonce, or venmoSdkPaymentMethodCode.

My requirement is to update the credit card information without putting the card number.

Is it possible to update the card without credit card number ?

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support .

You are able to update a credit card without specifying a credit card number. Braintree recommends doing this with the payment method functions instead of the credit card object to help you avoid handling raw credit card data on your website.

In the code that you've posted, you're making a customer update call rather than a credit card update call. When you make your customer update call, you're sending an array of credit cards. Braintree will try to update the customer by adding the cards in that array to the customer's record. The customer update call does not signal to the gateway that the cards on the customer should be updated. Rather than a customer update call, you'll want to use a [payment method update call][pm_upadte].

To update only a portion of the card, such as changing only the expiration date or CVV, you can use a payment method nonce. Create a payment method nonce by tokenizing only the details that you want to change . Once you have a nonce that only references the details you want to change, you can pass that into a payment method update call . This is what it might look like in php:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM