/**
  * 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');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  */
 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);
     $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
 }