예제 #1
0
 /**
  * create signatures for different call types
  * @ignore
  */
 public static function init()
 {
     self::$_createCustomerSignature = array(self::$_transparentRedirectKeys, array('customer' => Braintree_Customer::createSignature()));
     self::$_updateCustomerSignature = array(self::$_transparentRedirectKeys, 'customerId', array('customer' => Braintree_Customer::updateSignature()));
     self::$_transactionSignature = array(self::$_transparentRedirectKeys, array('transaction' => Braintree_Transaction::createSignature()));
     self::$_createCreditCardSignature = array(self::$_transparentRedirectKeys, array('creditCard' => Braintree_CreditCard::createSignature()));
     self::$_updateCreditCardSignature = array(self::$_transparentRedirectKeys, 'paymentMethodToken', array('creditCard' => Braintree_CreditCard::updateSignature()));
 }
 function testCreate_fromPaymentMethodToken()
 {
     $customer = Braintree_Customer::createNoValidate();
     $card = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
     $result = Braintree_PaymentMethodNonce::create($card->token);
     $this->assertTrue($result->success);
     $this->assertNotNull($result->paymentMethodNonce);
     $this->assertNotNull($result->paymentMethodNonce->nonce);
 }
예제 #3
0
 function testUpdateSignature_doesNotAlterOptionsInCreditCardUpdateSignature()
 {
     Braintree_Customer::updateSignature();
     foreach (Braintree_CreditCard::updateSignature() as $key => $value) {
         if (is_array($value) and array_key_exists('options', $value)) {
             $this->assertEquals(array('makeDefault', 'verificationMerchantAccountId', 'verifyCard'), $value['options']);
         }
     }
 }
예제 #4
0
 function create_card($card_info)
 {
     $result = Braintree_CreditCard::create($card_info);
     if ($result->success === true) {
         # Generated credit card token
         return $result->creditCard->token;
     }
     $this->_parse_errors($result);
     return false;
 }
예제 #5
0
 private function _createPaymentToken($postFormData, $customerId)
 {
     $ccNumber = $postFormData['Order']['cc_number'];
     $ccHolderName = $postFormData['Order']['cc_holder_name'];
     $expiration = str_split($postFormData['Order']['cc_expiration'], 2);
     $expirationMonth = $expiration[0];
     $expirationYear = $expiration[2];
     $cvv = $postFormData['Order']['cc_cvv'];
     $payment = Braintree_CreditCard::create(['number' => $ccNumber, 'cardholderName' => $ccHolderName, 'expirationMonth' => $expirationMonth, 'expirationYear' => $expirationYear, 'cvv' => $cvv, 'customerId' => $customerId]);
     return $payment->creditCard->token;
 }
예제 #6
0
 public function saveCreditCard()
 {
     $send_array = $this->options['creditCard'];
     if (isset($this->options['billing'])) {
         $send_array['billingAddress'] = $this->options['billing'];
     }
     if (isset($this->options['customerId'])) {
         $send_array['customerId'] = $this->options['customerId'];
     }
     $result = Braintree_CreditCard::create($send_array);
     if ($result->success) {
         return array('status' => true, 'result' => $result);
     } else {
         return array('status' => false, 'result' => $result);
     }
 }
예제 #7
0
 function test_GatewayRespectsMakeDefault()
 {
     $result = Braintree_Customer::create();
     $this->assertTrue($result->success);
     $customerId = $result->customer->id;
     $result = Braintree_CreditCard::create(array('customerId' => $customerId, 'number' => '4111111111111111', 'expirationDate' => '11/2099'));
     $this->assertTrue($result->success);
     $clientToken = Braintree_ClientToken::generate(array("customerId" => $customerId, "options" => array("makeDefault" => true)));
     $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
     $response = Braintree_HttpClientApi::post('/client_api/nonces.json', json_encode(array("credit_card" => array("number" => "4242424242424242", "expirationDate" => "11/2099"), "authorization_fingerprint" => $authorizationFingerprint, "shared_customer_identifier" => "fake_identifier", "shared_customer_identifier_type" => "testing")));
     $this->assertEquals(201, $response["status"]);
     $customer = Braintree_Customer::find($customerId);
     $this->assertEquals(2, count($customer->creditCards));
     foreach ($customer->creditCards as $creditCard) {
         if ($creditCard->last4 == "4242") {
             $this->assertTrue($creditCard->default);
         }
     }
 }
 /**
  * Deletes a record via the API
  *
  * @param   object  $model
  * @param   mixed   $conditions
  * @return  bool
  */
 public function delete(Model $model, $conditions = null)
 {
     $ids = $this->_getIdsToBeDeleted($model, $conditions);
     if ($ids === false) {
         return false;
     }
     $entity = $this->_getModelEntity($model);
     if (!empty($ids)) {
         foreach ($ids as $id) {
             try {
                 switch ($entity) {
                     case 'Customer':
                         Braintree_Customer::delete($id);
                         break;
                     case 'Transaction':
                         $this->showError(__('Transactions cannot be deleted', true));
                         return false;
                         break;
                     case 'CreditCard':
                         Braintree_CreditCard::delete($id);
                         break;
                     case 'Address':
                         $exploded = explode('|', $id);
                         if (count($exploded) != 2) {
                             return false;
                         }
                         list($customer_id, $address_id) = $exploded;
                         Braintree_Address::delete($customer_id, $address_id);
                         break;
                     default:
                         return false;
                         break;
                 }
             } catch (Exception $e) {
                 $this->showError(print_r($e, true));
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * 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);
 }
예제 #10
0
 function testErrorsOnFindWithWhitespaceCharacterArgument()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree_CreditCard::find('\\t');
 }
예제 #11
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');
                 }
             }
         }
     }
 }
 function testDelete_worksWithCreditCards()
 {
     $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
     $customer = Braintree_Customer::createNoValidate();
     $creditCardResult = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/2011', 'token' => $paymentMethodToken));
     $this->assertTrue($creditCardResult->success);
     Braintree_PaymentMethod::delete($paymentMethodToken);
     $this->setExpectedException('Braintree_Exception_NotFound');
     Braintree_PaymentMethod::find($paymentMethodToken);
     integrationMerchantConfig();
 }
 function testUpdateCreditCardFromTransparentRedirect()
 {
     $customer = Braintree_Customer::create(array('firstName' => 'Mike', 'lastName' => 'Jonez'))->customer;
     $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => Braintree_Test_CreditCardNumbers::$masterCard, 'expirationMonth' => '10', 'expirationYear' => '10'))->creditCard;
     $params = array('credit_card' => array('number' => Braintree_Test_CreditCardNumbers::$visa));
     $trParams = array('paymentMethodToken' => $creditCard->token, 'creditCard' => array('expirationMonth' => '11', 'expirationYear' => '11'));
     $trData = Braintree_TransparentRedirect::updateCreditCardData(array_merge($trParams, array("redirectUrl" => "http://www.example.com")));
     $queryString = Braintree_TestHelper::submitTrRequest(Braintree_TransparentRedirect::url(), $params, $trData);
     Braintree_TransparentRedirect::confirm($queryString);
     $creditCard = Braintree_CreditCard::find($creditCard->token);
     $this->assertequals('401288', $creditCard->bin);
     $this->assertequals('1881', $creditCard->last4);
     $this->assertequals('11/2011', $creditCard->expirationDate);
 }
예제 #14
0
 function deleteCard($token, $token_id)
 {
     $OSCOM_Db = Registry::get('Db');
     Braintree_Configuration::environment(MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live' ? 'production' : 'sandbox');
     Braintree_Configuration::merchantId(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID);
     Braintree_Configuration::publicKey(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY);
     Braintree_Configuration::privateKey(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY);
     try {
         Braintree_CreditCard::delete($token);
     } catch (Exception $e) {
     }
     return $OSCOM_Db->delete('customers_braintree_tokens', ['id' => $token_id, 'customers_id' => $_SESSION['customer_id'], 'braintree_token' => $token]) === 1;
 }
예제 #15
0
 public function vaultCreditCard()
 {
     $token = $this->creditCardDetails->token;
     if (empty($token)) {
         return null;
     } else {
         return Braintree_CreditCard::find($token);
     }
 }
예제 #16
0
 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);
 }
 function test_rangeNode_amount()
 {
     $customer = Braintree_Customer::createNoValidate();
     $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Jane Everywoman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
     $t_1000 = Braintree_Transaction::saleNoValidate(array('amount' => '1000.00', 'paymentMethodToken' => $creditCard->token));
     $t_1500 = Braintree_Transaction::saleNoValidate(array('amount' => '1500.00', 'paymentMethodToken' => $creditCard->token));
     $t_1800 = Braintree_Transaction::saleNoValidate(array('amount' => '1800.00', 'paymentMethodToken' => $creditCard->token));
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->greaterThanOrEqualTo('1700')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1800->id, $collection->firstItem()->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->lessThanOrEqualTo('1250')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1000->id, $collection->firstItem()->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->between('1100', '1600')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1500->id, $collection->firstItem()->id);
 }
예제 #18
0
 function updateCreditCardViaTr($regularParams, $trParams)
 {
     $trData = Braintree_TransparentRedirect::updateCreditCardData(array_merge($trParams, array("redirectUrl" => "http://www.example.com")));
     return Braintree_TestHelper::submitTrRequest(Braintree_CreditCard::updateCreditCardUrl(), $regularParams, $trData);
 }
예제 #19
0
 function testUpdateAndMakeDefault()
 {
     $customer = Braintree_Customer::createNoValidate();
     $creditCardResult = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12'));
     $this->assertTrue($creditCardResult->success);
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE')));
     $createResult = Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce));
     $this->assertTrue($createResult->success);
     $updateResult = Braintree_PayPalAccount::update($createResult->paymentMethod->token, array('options' => array('makeDefault' => true)));
     $this->assertTrue($updateResult->success);
     $this->assertTrue($updateResult->paypalAccount->isDefault());
 }
예제 #20
0
 public function executePaypal()
 {
     $this->user = $this->getUser()->getRaykuUser();
     $this->userId = $this->user->getId();
     if (sfWebRequest::POST === $this->getRequest()->getMethod() && $this->hasRequestParameter('submit_card')) {
         $expiration = substr($this->getRequestParameter('expiry_date'), 0, 2) . '/' . substr($this->getRequestParameter('expiry_date'), -2);
         require_once $_SERVER['DOCUMENT_ROOT'] . '/braintree_environment.php';
         $result = Braintree_Customer::create(array('firstName' => $this->user->getName(), 'lastName' => '', 'creditCard' => array('cardholderName' => $this->getRequestParameter('realname'), 'number' => $this->getRequestParameter('credit_card'), 'cvv' => $this->getRequestParameter('cvv'), 'expirationDate' => $expiration, 'options' => array('verifyCard' => true))));
         error_log($result->customer->creditCards[0]->token, 0);
         if (!$result->success) {
             $this->error = 'Your credit card is invalid.';
             //return sfView::SUCCESS;
         } else {
             //should only save last 4 digit
             $this->user->setCreditCard(substr($this->getRequestParameter('credit_card'), -4));
             $this->user->setCreditCardToken($result->customer->creditCards[0]->token);
             $this->user->save();
             //return sfView::SUCCESS;
         }
     }
     if (sfWebRequest::POST === $this->getRequest()->getMethod() && $this->hasRequestParameter('pay_balance')) {
         $this->points = $this->user->getPoints();
         $this->token = $this->user->getCreditCardToken();
         if ($this->points < 0) {
             $amount = '' . $this->points * -1;
             require_once $_SERVER['DOCUMENT_ROOT'] . '/braintree_environment.php';
             $result = Braintree_CreditCard::sale($this->token, array('amount' => $amount, 'credit_card' => array()));
             // error_log($result->customer->creditCards[0]->token, 0);
             if (!$result->success) {
                 //error_log("invalid", 0);
                 $this->error = 'Your credit card is invalid.';
             } else {
                 //should pay all balance
                 $this->user->setPoints(0);
                 $this->user->save();
             }
         }
     }
     $this->token = $this->user->getCreditCardToken();
     $this->cardNum = $this->user->getCreditCard();
     return sfView::SUCCESS;
 }
예제 #21
0
 function deleteCard($token, $token_id)
 {
     global $customer_id;
     Braintree_Configuration::environment(MODULE_PAYMENT_BRAINTREE_CC_TRANSACTION_SERVER == 'Live' ? 'production' : 'sandbox');
     Braintree_Configuration::merchantId(MODULE_PAYMENT_BRAINTREE_CC_MERCHANT_ID);
     Braintree_Configuration::publicKey(MODULE_PAYMENT_BRAINTREE_CC_PUBLIC_KEY);
     Braintree_Configuration::privateKey(MODULE_PAYMENT_BRAINTREE_CC_PRIVATE_KEY);
     try {
         Braintree_CreditCard::delete($token);
     } catch (Exception $e) {
     }
     tep_db_query("delete from customers_braintree_tokens where id = '" . (int) $token_id . "' and customers_id = '" . (int) $customer_id . "' and braintree_token = '" . tep_db_prepare_input(tep_db_input($token)) . "'");
     return tep_db_affected_rows() === 1;
 }
예제 #22
0
 function testUpdate_canUpdatePaymentMethodToken()
 {
     $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
     $plan = Braintree_SubscriptionTestHelper::triallessPlan();
     $subscription = Braintree_Subscription::create(array('paymentMethodToken' => $oldCreditCard->token, 'price' => '54.99', 'planId' => $plan['id']))->subscription;
     $newCreditCard = Braintree_CreditCard::createNoValidate(array('number' => '5105105105105100', 'expirationDate' => '05/2010', 'customerId' => $oldCreditCard->customerId));
     $result = Braintree_Subscription::update($subscription->id, array('paymentMethodToken' => $newCreditCard->token));
     $this->assertTrue($result->success);
     $this->assertEquals($newCreditCard->token, $result->subscription->paymentMethodToken);
 }
 function testUpdateSignature()
 {
     $expected = array('cardholderName', 'cvv', 'number', 'expirationDate', 'expirationMonth', 'expirationYear', 'token', array('options' => array('makeDefault', 'verificationMerchantAccountId', 'verifyCard')), array('billingAddress' => array('firstName', 'lastName', 'company', 'countryCodeAlpha2', 'countryCodeAlpha3', 'countryCodeNumeric', 'countryName', 'extendedAddress', 'locality', 'region', 'postalCode', 'streetAddress', array('options' => array('updateExisting')))));
     $this->assertEquals($expected, Braintree_CreditCard::UpdateSignature());
 }
예제 #24
0
 public function createCard($data)
 {
     $result = Braintree_CreditCard::create($data);
     if ($result->success) {
         return array('success' => 1, 'payment_method_token' => $result->creditCard->token);
     } else {
         return array('success' => 0, 'validation_errors' => $result->errors->deepAll());
     }
 }
예제 #25
0
파일: Customer.php 프로젝트: nstungxd/F2CA5
 /**
  * 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);
 }
예제 #26
0
 function testUpdate_canUpdatePaymentMethodWithPaymentMethodNonce()
 {
     $oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
     $plan = Braintree_SubscriptionTestHelper::triallessPlan();
     $subscription = Braintree_Subscription::create(array('paymentMethodToken' => $oldCreditCard->token, 'price' => '54.99', 'planId' => $plan['id']))->subscription;
     $customerId = Braintree_Customer::create()->customer->id;
     $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "customerId" => $oldCreditCard->customerId, "share" => true));
     $result = Braintree_Subscription::update($subscription->id, array('paymentMethodNonce' => $nonce));
     $this->assertTrue($result->success);
     $newCreditCard = Braintree_CreditCard::find($result->subscription->paymentMethodToken);
     $this->assertEquals("1111", $newCreditCard->last4);
     $this->assertNotEquals($oldCreditCard->last4, $newCreditCard->last4);
 }
예제 #27
0
 function testUnknownCardTypeIndicators()
 {
     $customer = Braintree_Customer::createNoValidate();
     $result = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::UNKNOWN, 'expirationDate' => '05/12', 'options' => array('verifyCard' => true)));
     $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid);
     $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated);
     $this->assertEquals(Braintree_CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll);
     $this->assertEquals(Braintree_CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit);
     $this->assertEquals(Braintree_CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare);
     $this->assertEquals(Braintree_CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial);
     $this->assertEquals(Braintree_CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance);
     $this->assertEquals(Braintree_CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank);
 }
예제 #28
0
 /**
  * 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");
         }
     }
 }
 /**
  * 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');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
예제 #30
0
 /**
  * @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]]]]];
 }