function testCustomerIdNotEqual()
 {
     $first = Braintree_Address::factory(array('customerId' => 'c1', 'id' => 'a1'));
     $second = Braintree_Address::factory(array('customerId' => 'not c1', 'id' => 'a1'));
     $this->assertFalse($first->isEqual($second));
     $this->assertFalse($second->isEqual($first));
 }
 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);
 }
Beispiel #3
0
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  * @return none
  */
 protected function _initialize($customerAttribs)
 {
     // set the attributes
     $this->_attributes = $customerAttribs;
     // map each address into its own object
     $addressArray = array();
     if (isset($customerAttribs['addresses'])) {
         foreach ($customerAttribs['addresses'] as $address) {
             $addressArray[] = Braintree_Address::factory($address);
         }
     }
     $this->_set('addresses', $addressArray);
     // map each creditCard into its own object
     $creditCardArray = array();
     if (isset($customerAttribs['creditCards'])) {
         foreach ($customerAttribs['creditCards'] as $creditCard) {
             $creditCardArray[] = Braintree_CreditCard::factory($creditCard);
         }
     }
     $this->_set('creditCards', $creditCardArray);
     // map each coinbaseAccount into its own object
     $coinbaseAccountArray = array();
     if (isset($customerAttribs['coinbaseAccounts'])) {
         foreach ($customerAttribs['coinbaseAccounts'] as $coinbaseAccount) {
             $coinbaseAccountArray[] = Braintree_CoinbaseAccount::factory($coinbaseAccount);
         }
     }
     $this->_set('coinbaseAccounts', $coinbaseAccountArray);
     // map each paypalAccount into its own object
     $paypalAccountArray = array();
     if (isset($customerAttribs['paypalAccounts'])) {
         foreach ($customerAttribs['paypalAccounts'] as $paypalAccount) {
             $paypalAccountArray[] = Braintree_PayPalAccount::factory($paypalAccount);
         }
     }
     $this->_set('paypalAccounts', $paypalAccountArray);
     // map each applePayCard into its own object
     $applePayCardArray = array();
     if (isset($customerAttribs['applePayCards'])) {
         foreach ($customerAttribs['applePayCards'] as $applePayCard) {
             $applePayCardArray[] = Braintree_applePayCard::factory($applePayCard);
         }
     }
     $this->_set('applePayCards', $applePayCardArray);
     // map each androidPayCard into its own object
     $androidPayCardArray = array();
     if (isset($customerAttribs['androidPayCards'])) {
         foreach ($customerAttribs['androidPayCards'] as $androidPayCard) {
             $androidPayCardArray[] = Braintree_AndroidPayCard::factory($androidPayCard);
         }
     }
     $this->_set('androidPayCards', $androidPayCardArray);
 }
 function testCreateSignature()
 {
     $expected = array('customerId', 'paymentMethodNonce', 'token', 'billingAddressId', array('options' => array('makeDefault', 'verifyCard', 'failOnDuplicatePaymentMethod', 'verificationMerchantAccountId')), array('billingAddress' => Braintree_Address::createSignature()));
     $this->assertEquals($expected, Braintree_PaymentMethod::CreateSignature());
 }
 function testUpdate_withNewCreditCardAndExistingBillingAddress()
 {
     $customer = Braintree_Customer::create()->customer;
     $address = Braintree_Address::create(array('customerId' => $customer->id, 'firstName' => 'Dan'))->address;
     $result = Braintree_Customer::update($customer->id, array('creditCard' => array('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);
 }
Beispiel #6
0
 /**
  * sets instance properties from an array of values
  *
  * @access protected
  * @param array $creditCardAttribs array of creditcard data
  * @return none
  */
 protected function _initialize($creditCardAttribs)
 {
     // set the attributes
     $this->_attributes = $creditCardAttribs;
     // map each address into its own object
     $billingAddress = isset($creditCardAttribs['billingAddress']) ? Braintree_Address::factory($creditCardAttribs['billingAddress']) : null;
     $subscriptionArray = array();
     if (isset($creditCardAttribs['subscriptions'])) {
         foreach ($creditCardAttribs['subscriptions'] as $subscription) {
             $subscriptionArray[] = Braintree_Subscription::factory($subscription);
         }
     }
     $this->_set('subscriptions', $subscriptionArray);
     $this->_set('billingAddress', $billingAddress);
     $this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
     $this->_set('maskedNumber', $this->bin . '******' . $this->last4);
 }
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new Braintree_Address object and encapsulates
  * it inside a Braintree_Result_Successful object, or
  * encapsulates a Braintree_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 Braintree_Exception_Unexpected
  */
 private function _verifyGatewayResponse($response)
 {
     if (isset($response['address'])) {
         // return a populated instance of Braintree_Address
         return new Braintree_Result_Successful(Braintree_Address::factory($response['address']));
     } else {
         if (isset($response['apiErrorResponse'])) {
             return new Braintree_Result_Error($response['apiErrorResponse']);
         } else {
             throw new Braintree_Exception_Unexpected("Expected address or apiErrorResponse");
         }
     }
 }
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  * @return none
  */
 protected function _initialize($customerAttribs)
 {
     // set the attributes
     $this->_attributes = $customerAttribs;
     // map each address into its own object
     $addressArray = array();
     if (isset($customerAttribs['addresses'])) {
         foreach ($customerAttribs['addresses'] as $address) {
             $addressArray[] = Braintree_Address::factory($address);
         }
     }
     $this->_set('addresses', $addressArray);
     // map each creditcard into its own object
     $ccArray = array();
     if (isset($customerAttribs['creditCards'])) {
         foreach ($customerAttribs['creditCards'] as $creditCard) {
             $ccArray[] = Braintree_CreditCard::factory($creditCard);
         }
     }
     $this->_set('creditCards', $ccArray);
 }
Beispiel #9
0
 function testUpdateNoValidate()
 {
     $customer = Braintree_Customer::createNoValidate();
     $createdAddress = Braintree_Address::createNoValidate(array('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, array('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);
 }
 public static function updateSignature()
 {
     $billingAddressSignature = Braintree_Address::updateSignature();
     array_push($billingAddressSignature, array('options' => array('updateExisting')));
     return array('billingAddressId', 'cardholderName', 'cvv', 'deviceSessionId', 'expirationDate', 'expirationMonth', 'expirationYear', 'number', 'token', 'venmoSdkPaymentMethodCode', 'deviceData', 'fraudMerchantId', 'paymentMethodNonce', array('options' => array('makeDefault', 'verificationMerchantAccountId', 'verifyCard', 'venmoSdkSession')), array('billingAddress' => $billingAddressSignature));
 }
 function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
 {
     $customer = Braintree_Customer::createNoValidate();
     $nonce = Braintree_HttpClientApi::nonce_for_new_card(array('credit_card' => array('number' => '4111111111111111', 'expirationMonth' => '12', 'expirationYear' => '2020', 'options' => array('validate' => false))));
     $address = Braintree_Address::create(array('customerId' => $customer->id, 'firstName' => 'Bobby', 'lastName' => 'Tables'))->address;
     $result = Braintree_PaymentMethod::create(array('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);
 }
 function testSale_withBillingAddressId()
 {
     $customer = Braintree_Customer::create(array('firstName' => 'Mike', 'creditCard' => array('cardholderName' => 'The Cardholder', 'number' => Braintree_Test_CreditCardNumbers::$visa, 'expirationDate' => '05/12')))->customer;
     $address = Braintree_Address::create(array('customerId' => $customer->id, 'streetAddress' => '123 Fake St.'))->address;
     $result = Braintree_Transaction::sale(array('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);
 }
Beispiel #13
0
 public function saveAddress()
 {
     $send_array = $this->options['billing'];
     if (isset($this->options['customerId'])) {
         $send_array['customerId'] = $this->options['customerId'];
     }
     $result = \Braintree_Address::create($send_array);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }
 function testFindErrorsOnWhitespaceOnlyCustomerId()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree_Address::find('  ', '123');
 }
 /**
  * Deletes a record via the API
  *
  * @param   object  $model
  * @param   mixed   $conditions
  * @return  bool
  */
 public function delete(Model $model, $conditions = null)
 {
     $ids = $this->_getIdsToBeDeleted($model, $conditions);
     if ($ids === false) {
         return false;
     }
     $entity = $this->_getModelEntity($model);
     if (!empty($ids)) {
         foreach ($ids as $id) {
             try {
                 switch ($entity) {
                     case 'Customer':
                         Braintree_Customer::delete($id);
                         break;
                     case 'Transaction':
                         $this->showError(__('Transactions cannot be deleted', true));
                         return false;
                         break;
                     case 'CreditCard':
                         Braintree_CreditCard::delete($id);
                         break;
                     case 'Address':
                         $exploded = explode('|', $id);
                         if (count($exploded) != 2) {
                             return false;
                         }
                         list($customer_id, $address_id) = $exploded;
                         Braintree_Address::delete($customer_id, $address_id);
                         break;
                     default:
                         return false;
                         break;
                 }
             } catch (Exception $e) {
                 $this->showError(print_r($e, true));
                 return false;
             }
         }
     }
     return true;
 }