我必须使用 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;
当我尝试运行此代码时,我收到错误 -
信用卡必须包含number,paymentMethodNonce或venmoSdkPaymentMethodCode。
我的要求是更新信用卡信息而不输入卡号。
是否可以在没有信用卡号的情况下更新信用卡?
答案 0 :(得分: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'
]);