/** * 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'); } } } } } } } } }
/** * 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 testVerificationIsLatestVerification() { $creditCard = Braintree_CreditCard::factory(array('verifications' => array(array('id' => '123', 'createdAt' => DateTime::createFromFormat('Ymd', '20121212')), array('id' => '932', 'createdAt' => DateTime::createFromFormat('Ymd', '20121215')), array('id' => '456', 'createdAt' => DateTime::createFromFormat('Ymd', '20121213'))))); $this->assertEquals('932', $creditCard->verification->id); }
/** * 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); }
function testMaskedNumber() { $creditCard = Braintree_CreditCard::factory(array('bin' => '123456', 'last4' => '7890')); $this->assertEquals('123456******7890', $creditCard->maskedNumber); }
/** * 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'); } } } } }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function getConfigDataProvider() { return ['no_vault' => ['config_data' => ['isActive' => true, 'getClientToken' => self::CLIENT_TOKEN, 'is3dSecureEnabled' => true, 'useVault' => false, 'getCountrySpecificCardTypeConfig' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'getBraintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js'], 'vault_data' => [], 'token_nonce_map' => [], 'expected_result' => ['payment' => ['braintree' => ['clientToken' => self::CLIENT_TOKEN, 'useVault' => false, 'canSaveCard' => false, 'show3dSecure' => true, 'storedCards' => [], 'selectedCardToken' => null, 'creditCardExpMonth' => self::TODAY_MONTH, 'creditCardExpYear' => self::TODAY_YEAR, 'countrySpecificCardTypes' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'availableCardTypes' => $this->availableCardTypes, 'braintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js', 'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL]]]], 'vault_with_stored_cards' => ['config_data' => ['isActive' => true, 'getClientToken' => self::CLIENT_TOKEN, 'is3dSecureEnabled' => false, 'useVault' => true, 'getCountrySpecificCardTypeConfig' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'getBraintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js'], 'vault_data' => ['currentCustomerStoredCards' => [\Braintree_CreditCard::factory(['token' => 'token1', 'bin' => '4218', 'last4' => '1001', 'cardType' => 'Visa', 'default' => false]), \Braintree_CreditCard::factory(['token' => 'token2', 'bin' => '5555', 'last4' => '1054', 'cardType' => 'Master Card', 'default' => 1])]], 'token_nonce_map' => [['token1', 'nonce1'], ['token2', 'nonce2']], 'expected_result' => ['payment' => ['braintree' => ['clientToken' => self::CLIENT_TOKEN, 'useVault' => true, 'canSaveCard' => true, 'show3dSecure' => false, 'storedCards' => [['token' => 'token1', 'maskedNumber' => '4218******1001 - Visa', 'selected' => false, 'type' => 'VI'], ['token' => 'token2', 'maskedNumber' => '5555******1054 - Master Card', 'selected' => 1, 'type' => 'MA']], 'selectedCardToken' => 'token2', 'creditCardExpMonth' => self::TODAY_MONTH, 'creditCardExpYear' => self::TODAY_YEAR, 'countrySpecificCardTypes' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'availableCardTypes' => $this->availableCardTypes, 'braintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js', 'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL]]]], 'vault_with_stored_cards_3dsecure' => ['config_data' => ['isActive' => true, 'getClientToken' => self::CLIENT_TOKEN, 'is3dSecureEnabled' => true, 'useVault' => true, 'getCountrySpecificCardTypeConfig' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'getBraintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js'], 'vault_data' => ['currentCustomerStoredCards' => [\Braintree_CreditCard::factory(['token' => 'token1', 'bin' => '4218', 'last4' => '1001', 'cardType' => 'Visa', 'default' => false]), \Braintree_CreditCard::factory(['token' => 'token2', 'bin' => '5555', 'last4' => '1054', 'cardType' => 'Master Card', 'default' => 1])]], 'token_nonce_map' => [['token1', 'nonce1'], ['token2', 'nonce2']], 'expected_result' => ['payment' => ['braintree' => ['clientToken' => self::CLIENT_TOKEN, 'useVault' => true, 'canSaveCard' => true, 'show3dSecure' => true, 'storedCards' => [['token' => 'token1', 'maskedNumber' => '4218******1001 - Visa', 'selected' => false, 'type' => 'VI'], ['token' => 'token2', 'maskedNumber' => '5555******1054 - Master Card', 'selected' => 1, 'type' => 'MA']], 'selectedCardToken' => 'token2', 'creditCardExpMonth' => self::TODAY_MONTH, 'creditCardExpYear' => self::TODAY_YEAR, 'countrySpecificCardTypes' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'availableCardTypes' => $this->availableCardTypes, 'braintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js', 'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL]]]], 'vault_with_no_stored_cards' => ['config_data' => ['isActive' => true, 'getClientToken' => self::CLIENT_TOKEN, 'is3dSecureEnabled' => true, 'useVault' => true, 'getCountrySpecificCardTypeConfig' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'getBraintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js'], 'vault_data' => ['currentCustomerStoredCards' => []], 'token_nonce_map' => [['token1', 'nonce1'], ['token2', 'nonce2']], 'expected_result' => ['payment' => ['braintree' => ['clientToken' => self::CLIENT_TOKEN, 'useVault' => false, 'canSaveCard' => true, 'show3dSecure' => true, 'storedCards' => [], 'selectedCardToken' => null, 'creditCardExpMonth' => self::TODAY_MONTH, 'creditCardExpYear' => self::TODAY_YEAR, 'countrySpecificCardTypes' => ['US' => ['VI', 'AE', 'MA']], 'isFraudDetectionEnabled' => true, 'isCcDetectionEnabled' => true, 'availableCardTypes' => $this->availableCardTypes, 'braintreeDataJs' => 'https://js.braintreegateway.com/v1/braintree-data.js', 'ajaxGenerateNonceUrl' => self::PAYMENT_NONCE_GENERATION_URL]]]]]; }
/** * generic method for validating incoming gateway responses * * creates a new Braintree_CreditCard 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_Address return new Braintree_Result_Successful(Braintree_CreditCard::factory($response['creditCard'])); } else { if (isset($response['apiErrorResponse'])) { return new Braintree_Result_Error($response['apiErrorResponse']); } else { throw new Braintree_Exception_Unexpected("Expected address or apiErrorResponse"); } } }