function testHandlesUnknownPaymentMethodResponses()
 {
     $response = array('unkownPaymentMethod' => array('token' => 'SOME_TOKEN', 'default' => true));
     $unknownPaymentMethodObject = Braintree_UnknownPaymentMethod::factory($response);
     $this->assertEquals('SOME_TOKEN', $unknownPaymentMethodObject->token);
     $this->assertTrue($unknownPaymentMethodObject->isDefault());
     $this->assertEquals('https://assets.braintreegateway.com/payment_method_logo/unknown.png', $unknownPaymentMethodObject->imageUrl);
 }
 /**
  * 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');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 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');
                 }
             }
         }
     }
 }