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 ?