/**
  * generic method for validating incoming gateway responses
  *
  * creates a new Braintree_CreditCard or Braintree_PayPalAccount 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['creditCard'])) {
         // return a populated instance of Braintree_CreditCard
         return new Braintree_Result_Successful(Braintree_CreditCard::factory($response['creditCard']), "paymentMethod");
     } else {
         if (isset($response['paypalAccount'])) {
             // return a populated instance of Braintree_PayPalAccount
             return new Braintree_Result_Successful(Braintree_PayPalAccount::factory($response['paypalAccount']), "paymentMethod");
         } else {
             if (isset($response['coinbaseAccount'])) {
                 // return a populated instance of Braintree_CoinbaseAccount
                 return new Braintree_Result_Successful(Braintree_CoinbaseAccount::factory($response['coinbaseAccount']), "paymentMethod");
             } else {
                 if (isset($response['applePayCard'])) {
                     // return a populated instance of Braintree_ApplePayCard
                     return new Braintree_Result_Successful(Braintree_ApplePayCard::factory($response['applePayCard']), "paymentMethod");
                 } else {
                     if (isset($response['androidPayCard'])) {
                         // return a populated instance of Braintree_AndroidPayCard
                         return new Braintree_Result_Successful(Braintree_AndroidPayCard::factory($response['androidPayCard']), "paymentMethod");
                     } else {
                         if (isset($response['europeBankAccount'])) {
                             // return a populated instance of Braintree_EuropeBankAccount
                             return new Braintree_Result_Successful(Braintree_EuropeBankAccount::factory($response['europeBankAccount']), "paymentMethod");
                         } else {
                             if (isset($response['apiErrorResponse'])) {
                                 return new Braintree_Result_Error($response['apiErrorResponse']);
                             } else {
                                 if (is_array($response)) {
                                     return new Braintree_Result_Successful(Braintree_UnknownPaymentMethod::factory($response), "paymentMethod");
                                 } else {
                                     throw new Braintree_Exception_Unexpected('Expected payment method or apiErrorResponse');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
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);
 }
Пример #3
0
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new Braintree_CreditCard or Braintree_PayPalAccount 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 static function _verifyGatewayResponse($response)
 {
     if (isset($response['creditCard'])) {
         // return a populated instance of Braintree_CreditCard
         return new Braintree_Result_Successful(Braintree_CreditCard::factory($response['creditCard']), "paymentMethod");
     } else {
         if (isset($response['paypalAccount'])) {
             // return a populated instance of Braintree_PayPalAccount
             return new Braintree_Result_Successful(Braintree_PayPalAccount::factory($response['paypalAccount']), "paymentMethod");
         } else {
             if (isset($response['apiErrorResponse'])) {
                 return new Braintree_Result_Error($response['apiErrorResponse']);
             } else {
                 if (is_array($response)) {
                     return Braintree_UnknownPaymentMethod::factory($response);
                 } else {
                     throw new Braintree_Exception_Unexpected('Expected credit card, paypal account or apiErrorResponse');
                 }
             }
         }
     }
 }
Пример #4
0
 function testSale_createsASaleUsingGivenToken()
 {
     $nonce = Braintree_Test_Nonces::$paypalFuturePayment;
     $customer = Braintree_Customer::createNoValidate(array('paymentMethodNonce' => $nonce));
     $paypalAccount = $customer->paypalAccounts[0];
     $result = Braintree_PayPalAccount::sale($paypalAccount->token, array('amount' => '100.00'));
     $this->assertTrue($result->success);
     $this->assertEquals('100.00', $result->transaction->amount);
     $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
     $this->assertEquals($paypalAccount->token, $result->transaction->paypalDetails->token);
 }
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new Braintree_PayPalAccount 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['paypalAccount'])) {
         // return a populated instance of Braintree_PayPalAccount
         return new Braintree_Result_Successful(Braintree_PayPalAccount::factory($response['paypalAccount']));
     } else {
         if (isset($response['apiErrorResponse'])) {
             return new Braintree_Result_Error($response['apiErrorResponse']);
         } else {
             throw new Braintree_Exception_Unexpected('Expected paypal account or apiErrorResponse');
         }
     }
 }
Пример #6
0
 function testErrorsOnFindWithWhitespaceCharacterArgument()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree_PayPalAccount::find('\\t');
 }