/**
  * @param string $subscription_id
  * @param array $customerData
  * @return bool
  * @throws Exception
  */
 public function updatePaymentMethod($subscription_id, $customerData)
 {
     $subscription = Braintree_Subscription::find($subscription_id);
     if (!empty($subscription)) {
         $paymentMethod = Braintree_PaymentMethod::find($subscription->paymentMethodToken);
         if (!empty($paymentMethod)) {
             $result = Braintree_PaymentMethod::update($paymentMethod->token, ['paymentMethodNonce' => $customerData['nonce'], 'options' => ['verifyCard' => true], 'billingAddress' => ['firstName' => $customerData['first_name'], 'lastName' => $customerData['last_name'], 'streetAddress' => $customerData['address'], 'locality' => $customerData['city'], 'region' => $customerData['state'], 'postalCode' => $customerData['zip']]]);
             if ($result->success) {
                 return true;
             } else {
                 foreach ($result->errors->deepAll() as $error) {
                     throw new Exception($error->code . ": " . $error->message . "\n");
                 }
             }
         }
     }
     return false;
 }
 /**
  * Update customer's credit card.
  *
  * @param string $nonce
  *
  * @return bool
  */
 public function updateCard($nonce)
 {
     $customer = $this->asBraintreeCustomer();
     $result = PaymentMethod::update($customer->paymentMethods[0]->token, ['paymentMethodNonce' => $nonce]);
     if ($result->success) {
         $card = $result->paymentMethod;
         $this->card_brand = $card->cardType;
         $this->card_last_four = $card->last4;
         $this->save();
     }
     return false;
 }
 public function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate()
 {
     $customer = Braintree\Customer::createNoValidate();
     $firstToken = 'paypal-account-' . strval(rand());
     $secondToken = 'paypal-account-' . strval(rand());
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $firstNonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'consent-code', 'token' => $firstToken]]);
     $firstResult = Braintree\PaymentMethod::create(['paymentMethodNonce' => $firstNonce, 'customerId' => $customer->id]);
     $this->assertTrue($firstResult->success);
     $firstPaypalAccount = $firstResult->paymentMethod;
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $secondNonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'consent-code', 'token' => $secondToken]]);
     $secondResult = Braintree\PaymentMethod::create(['paymentMethodNonce' => $secondNonce, 'customerId' => $customer->id]);
     $this->assertTrue($secondResult->success);
     $secondPaypalAccount = $firstResult->paymentMethod;
     $updateResult = Braintree\PaymentMethod::update($firstToken, ['token' => $secondToken]);
     $this->assertFalse($updateResult->success);
     $resultErrors = $updateResult->errors->deepAll();
     $this->assertEquals("92906", $resultErrors[0]->code);
 }
Exemple #4
0
 public function updatePaymentMethod()
 {
     $result = PaymentMethod::update($this->options['paymentMethodToken'], $this->options['paymentMethod']);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }