function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate() { $customer = Braintree_Customer::createNoValidate(); $firstToken = 'paypal-account-' . strval(rand()); $secondToken = 'paypal-account-' . strval(rand()); $firstNonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'consent-code', 'token' => $firstToken))); $firstResult = Braintree_PaymentMethod::create(array('paymentMethodNonce' => $firstNonce, 'customerId' => $customer->id)); $this->assertTrue($firstResult->success); $firstPaypalAccount = $firstResult->paymentMethod; $secondNonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'consent-code', 'token' => $secondToken))); $secondResult = Braintree_PaymentMethod::create(array('paymentMethodNonce' => $secondNonce, 'customerId' => $customer->id)); $this->assertTrue($secondResult->success); $secondPaypalAccount = $firstResult->paymentMethod; $updateResult = Braintree_PaymentMethod::update($firstToken, array('token' => $secondToken)); $this->assertFalse($updateResult->success); $resultErrors = $updateResult->errors->deepAll(); $this->assertEquals("92906", $resultErrors[0]->code); }
foreach ($postData as $key => $value) { $postValue = explode("=", $value); $_POST[$postValue[0]] = $postValue[1]; } unset($_POST['data']); } $result = Braintree_Transaction::sale(array('amount' => $_POST['amt'], 'paymentMethodToken' => $_POST['token'])); echo "<div style='height:300px; overflow-y:scroll; background-color:#fff;'> <h3>API response</h3>"; echo json_encode($result, JSON_PRETTY_PRINT); echo "</div>"; } else { if ($_POST['_act'] == 'updatePaymentMethod') { if (isset($_POST['billingAddressId']) & $_POST['billingAddressId'] != "") { $updateResult = Braintree_PaymentMethod::update($_POST['token'], array('billingAddressId' => $_POST['billingAddressId'])); } else { $updateResult = Braintree_PaymentMethod::update($_POST['token'], array('billingAddress' => array('streetAddress' => $_POST['streetAddress'], 'options' => array('updateExisting' => $_POST['updateExisting'])))); } print_r($updateResult); } else { if ($_POST['_act'] == 'findPaymentMethod') { $paymentMethod = Braintree_PaymentMethod::find($_POST['token']); print_r($paymentMethod); } else { if ($_POST['_act'] == 'deletePaymentMethod') { $search = (string) $_POST['token']; $file = './data/token.txt'; $contents = file_get_contents($file); echo $contents = str_replace($_POST['token'], trim((string) $_POST['token'] . "_DELETED\r\n"), $contents); file_put_contents($file, $contents); $paymentMethod = Braintree_PaymentMethod::delete($_POST['token']); print_r($paymentMethod);
$nonce = filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING); $result = Braintree_Customer::update($un . "_FITNESS", array('creditCard' => array('paymentMethodNonce' => $nonce, 'options' => array('updateExistingToken' => $payToken)))); if ($result->success) { $successful = true; $cardn = $result->customer->creditCards[0]->maskedNumber; $expd = $result->customer->creditCards[0]->expirationDate; } else { $error_msg = 'Update failed:'; foreach ($result->errors->deepAll() as $error) { $error_msg .= $error->code . ": " . $error->message . '<br>'; } echo $error_msg . '<br><br><input type="button" value="Submit" onClick="doChangeBill();">'; exit; } } else { $result = Braintree_PaymentMethod::update($payToken, array('billingAddress' => array('postalCode' => $zip, 'options' => array('updateExisting' => true)), 'expirationDate' => $expd)); if ($result->success) { $successful = true; $cardn = $result->paymentMethod->maskedNumber; } else { $error_msg = 'Update failed:'; foreach ($result->errors->deepAll() as $error) { $error_msg .= $error->code . ": " . $error->message . '<br>'; } echo $error_msg . '<br><br><input type="button" value="Submit" onClick="doChangeBill();">'; exit; } } if ($successful) { // Update in Database if ($stmt = $mysqli->prepare("UPDATE members SET " . "FName='" . $fname . "', " . "LName='" . $lname . "', " . "Street='" . $street . "', " . "City='" . $city . "', " . "State='" . $state . "', " . "Zip='" . $zip . "', " . "Phone='" . $phone . "'" . " WHERE id = ?")) {
/** * @param string $token * @param array $attribs * @return \Braintree_Result_Successful|\Braintree_Result_Error */ public function update($token, array $attribs) { return \Braintree_PaymentMethod::update($token, $attribs); }
public function setDefaultCard() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $token = $_POST['token']; $id_user = $_POST['id_user']; $user = new UserModel(); $user->getByID($id_user); $updateResult = Braintree_PaymentMethod::update($token, ['options' => ['makeDefault' => true]]); if ($updateResult) { $user->braintree_id = $token; $user->save(); $json["status_code"] = 1; $json['results']['message'] = "Success"; echo json_encode($json); die; } else { Generic::errorMsg("Failed to set Default"); } }