public function testCreate_withExistingBillingAddress()
 {
     $customer = Braintree\Customer::createNoValidate();
     $existingAddress = Braintree\Address::createNoValidate(array('customerId' => $customer->id, 'firstName' => 'John'));
     $result = Braintree\CreditCard::create(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12', 'billingAddressId' => $existingAddress->id));
     $this->assertTrue($result->success);
     $address = $result->creditCard->billingAddress;
     $this->assertEquals($existingAddress->id, $address->id);
     $this->assertEquals('John', $address->firstName);
 }
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new Address object and encapsulates
  * it inside a Result\Successful object, or
  * encapsulates an Errors object inside a Result\Error
  * alternatively, throws an Unexpected exception if the response is invalid
  *
  * @ignore
  * @param array $response gateway response values
  * @return object Result\Successful or Result\Error
  * @throws Exception\Unexpected
  */
 private function _verifyGatewayResponse($response)
 {
     if (isset($response['address'])) {
         // return a populated instance of Address
         return new Result\Successful(Address::factory($response['address']));
     } else {
         if (isset($response['apiErrorResponse'])) {
             return new Result\Error($response['apiErrorResponse']);
         } else {
             throw new Exception\Unexpected("Expected address or apiErrorResponse");
         }
     }
 }
示例#3
0
 public function testFindErrorsOnWhitespaceOnlyCustomerId()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\Address::find('  ', '123');
 }
 public function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
 {
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonce_for_new_card(['credit_card' => ['number' => '4111111111111111', 'expirationMonth' => '12', 'expirationYear' => '2020', 'options' => ['validate' => false]]]);
     $address = Braintree\Address::create(['customerId' => $customer->id, 'firstName' => 'Bobby', 'lastName' => 'Tables'])->address;
     $result = Braintree\PaymentMethod::create(['paymentMethodNonce' => $nonce, 'customerId' => $customer->id, 'billingAddressId' => $address->id]);
     $this->assertTrue($result->success);
     $this->assertTrue(is_a($result->paymentMethod, 'Braintree\\CreditCard'));
     $token = $result->paymentMethod->token;
     $foundCreditCard = Braintree\CreditCard::find($token);
     $this->assertTrue(NULL != $foundCreditCard);
     $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName);
     $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName);
 }
示例#5
0
 public function testUpdateNoValidate()
 {
     $customer = Braintree\Customer::createNoValidate();
     $createdAddress = Braintree\Address::createNoValidate(['customerId' => $customer->id, 'firstName' => 'Old First', 'lastName' => 'Old Last', 'company' => 'Old Company', 'streetAddress' => '1 E Old St', 'extendedAddress' => 'Apt Old', 'locality' => 'Old Chicago', 'region' => 'Old Region', 'postalCode' => 'Old Postal', 'countryName' => 'United States of America']);
     $address = Braintree\Address::updateNoValidate($customer->id, $createdAddress->id, ['firstName' => 'New First', 'lastName' => 'New Last', 'company' => 'New Company', 'streetAddress' => '1 E New St', 'extendedAddress' => 'Apt New', 'locality' => 'New Chicago', 'region' => 'New Region', 'postalCode' => 'New Postal', 'countryName' => 'Mexico']);
     $this->assertEquals('New First', $address->firstName);
     $this->assertEquals('New Last', $address->lastName);
     $this->assertEquals('New Company', $address->company);
     $this->assertEquals('1 E New St', $address->streetAddress);
     $this->assertEquals('Apt New', $address->extendedAddress);
     $this->assertEquals('New Chicago', $address->locality);
     $this->assertEquals('New Region', $address->region);
     $this->assertEquals('New Postal', $address->postalCode);
     $this->assertEquals('Mexico', $address->countryName);
 }
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  * @return void
  */
 protected function _initialize($customerAttribs)
 {
     // set the attributes
     $this->_attributes = $customerAttribs;
     // map each address into its own object
     $addressArray = [];
     if (isset($customerAttribs['addresses'])) {
         foreach ($customerAttribs['addresses'] as $address) {
             $addressArray[] = Address::factory($address);
         }
     }
     $this->_set('addresses', $addressArray);
     // map each creditCard into its own object
     $creditCardArray = [];
     if (isset($customerAttribs['creditCards'])) {
         foreach ($customerAttribs['creditCards'] as $creditCard) {
             $creditCardArray[] = CreditCard::factory($creditCard);
         }
     }
     $this->_set('creditCards', $creditCardArray);
     // map each coinbaseAccount into its own object
     $coinbaseAccountArray = [];
     if (isset($customerAttribs['coinbaseAccounts'])) {
         foreach ($customerAttribs['coinbaseAccounts'] as $coinbaseAccount) {
             $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
         }
     }
     $this->_set('coinbaseAccounts', $coinbaseAccountArray);
     // map each paypalAccount into its own object
     $paypalAccountArray = [];
     if (isset($customerAttribs['paypalAccounts'])) {
         foreach ($customerAttribs['paypalAccounts'] as $paypalAccount) {
             $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
         }
     }
     $this->_set('paypalAccounts', $paypalAccountArray);
     // map each applePayCard into its own object
     $applePayCardArray = [];
     if (isset($customerAttribs['applePayCards'])) {
         foreach ($customerAttribs['applePayCards'] as $applePayCard) {
             $applePayCardArray[] = ApplePayCard::factory($applePayCard);
         }
     }
     $this->_set('applePayCards', $applePayCardArray);
     // map each androidPayCard into its own object
     $androidPayCardArray = [];
     if (isset($customerAttribs['androidPayCards'])) {
         foreach ($customerAttribs['androidPayCards'] as $androidPayCard) {
             $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
         }
     }
     $this->_set('androidPayCards', $androidPayCardArray);
     $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
 }
示例#7
0
 public function saveAddress()
 {
     $sendArray = $this->options['billing'];
     if (isset($this->options['customerId'])) {
         $sendArray['customerId'] = $this->options['customerId'];
     }
     $result = Address::create($sendArray);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }
示例#8
0
 public function testUpdate_withNewCreditCardAndExistingBillingAddress()
 {
     $customer = Braintree\Customer::create()->customer;
     $address = Braintree\Address::create(['customerId' => $customer->id, 'firstName' => 'Dan'])->address;
     $result = Braintree\Customer::update($customer->id, ['creditCard' => ['number' => '4111111111111111', 'expirationDate' => '11/14', 'billingAddressId' => $address->id]]);
     $billingAddress = $result->customer->creditCards[0]->billingAddress;
     $this->assertEquals($address->id, $billingAddress->id);
     $this->assertEquals('Dan', $billingAddress->firstName);
 }
 public function testSale_withBillingAddressId()
 {
     $customer = Braintree\Customer::create(['firstName' => 'Mike', 'creditCard' => ['cardholderName' => 'The Cardholder', 'number' => Braintree\Test\CreditCardNumbers::$visa, 'expirationDate' => '05/12']])->customer;
     $address = Braintree\Address::create(['customerId' => $customer->id, 'streetAddress' => '123 Fake St.'])->address;
     $result = Braintree\Transaction::sale(['amount' => '100.00', 'customerId' => $customer->id, 'billingAddressId' => $address->id]);
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals('123 Fake St.', $transaction->billingDetails->streetAddress);
     $this->assertEquals($address->id, $transaction->billingDetails->id);
 }