public function testHandlesUnknownPaymentMethodResponses() { $response = ['unkownPaymentMethod' => ['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 CreditCard or PayPalAccount object * and encapsulates it inside a Result\Successful object, or * encapsulates a Errors object inside a Result\Error * alternatively, throws an Unexpected exception if the response is invalid. * * @ignore * @param array $response gateway response values * @return Result\Successful|Result\Error * @throws Exception\Unexpected */ private function _verifyGatewayResponse($response) { if (isset($response['creditCard'])) { return new Result\Successful(CreditCard::factory($response['creditCard']), 'paymentMethod'); } else { if (isset($response['paypalAccount'])) { return new Result\Successful(PayPalAccount::factory($response['paypalAccount']), "paymentMethod"); } else { if (isset($response['coinbaseAccount'])) { return new Result\Successful(CoinbaseAccount::factory($response['coinbaseAccount']), "paymentMethod"); } else { if (isset($response['applePayCard'])) { return new Result\Successful(ApplePayCard::factory($response['applePayCard']), "paymentMethod"); } else { if (isset($response['androidPayCard'])) { return new Result\Successful(AndroidPayCard::factory($response['androidPayCard']), "paymentMethod"); } else { if (isset($response['amexExpressCheckoutCard'])) { return new Result\Successful(AmexExpressCheckoutCard::factory($response['amexExpressCheckoutCard']), "paymentMethod"); } else { if (isset($response['europeBankAccount'])) { return new Result\Successful(EuropeBankAccount::factory($response['europeBankAccount']), "paymentMethod"); } else { if (isset($response['venmoAccount'])) { return new Result\Successful(VenmoAccount::factory($response['venmoAccount']), "paymentMethod"); } else { if (isset($response['apiErrorResponse'])) { return new Result\Error($response['apiErrorResponse']); } else { if (is_array($response)) { return new Result\Successful(UnknownPaymentMethod::factory($response), "paymentMethod"); } else { throw new Exception\Unexpected('Expected payment method or apiErrorResponse'); } } } } } } } } } } }