== More information == For more detailed information on CreditCards, see {@link http://www.braintreepayments.com/gateway/credit-card-api http://www.braintreepaymentsolutions.com/gateway/credit-card-api}
For more detailed information on CreditCard verifications, see {@link http://www.braintreepayments.com/gateway/credit-card-verification-api http://www.braintreepaymentsolutions.com/gateway/credit-card-verification-api}
Inheritance: extends braintree\Base
 public function testCreate_fromPaymentMethodToken()
 {
     $customer = Braintree\Customer::createNoValidate();
     $card = Braintree\CreditCard::create(['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);
 }
Ejemplo n.º 2
0
 public 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 = Test\Helper::decodedClientToken(array("customerId" => $customerId, "options" => array("makeDefault" => true)));
     $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $response = $http->post('/client_api/v1/payment_methods/credit_cards.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);
         }
     }
 }
Ejemplo n.º 3
0
 public function testUpdateAndMakeDefault()
 {
     $customer = Braintree\Customer::createNoValidate();
     $creditCardResult = Braintree\CreditCard::create(['customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12']);
     $this->assertTrue($creditCardResult->success);
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE']]);
     $createResult = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     $this->assertTrue($createResult->success);
     $updateResult = Braintree\PayPalAccount::update($createResult->paymentMethod->token, ['options' => ['makeDefault' => true]]);
     $this->assertTrue($updateResult->success);
     $this->assertTrue($updateResult->paypalAccount->isDefault());
 }
Ejemplo n.º 4
0
 public function testVerificationIsLatestVerification()
 {
     $creditCard = Braintree\CreditCard::factory(['verifications' => [['id' => '123', 'createdAt' => DateTime::createFromFormat('Ymd', '20121212')], ['id' => '932', 'createdAt' => DateTime::createFromFormat('Ymd', '20121215')], ['id' => '456', 'createdAt' => DateTime::createFromFormat('Ymd', '20121213')]]]);
     $this->assertEquals('932', $creditCard->verification->id);
 }
Ejemplo n.º 5
0
 public function testUnknownCardTypeIndicators()
 {
     $customer = Braintree\Customer::createNoValidate();
     $result = Braintree\CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => 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);
 }
Ejemplo n.º 6
0
 public function testDelete_worksWithCreditCards()
 {
     $paymentMethodToken = 'CREDIT_CARD_TOKEN-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $creditCardResult = Braintree\CreditCard::create(['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);
     self::integrationMerchantConfig();
 }
Ejemplo n.º 7
0
 public function testUpdate_canUpdatePaymentMethodWithPaymentMethodNonce()
 {
     $oldCreditCard = SubscriptionHelper::createCreditCard();
     $plan = SubscriptionHelper::triallessPlan();
     $subscription = Braintree\Subscription::create(['paymentMethodToken' => $oldCreditCard->token, 'price' => '54.99', 'planId' => $plan['id']])->subscription;
     $customerId = Braintree\Customer::create()->customer->id;
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonce_for_new_card(["creditCard" => ["number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"], "customerId" => $oldCreditCard->customerId, "share" => true]);
     $result = Braintree\Subscription::update($subscription->id, ['paymentMethodNonce' => $nonce]);
     $this->assertTrue($result->success);
     $newCreditCard = Braintree\CreditCard::find($result->subscription->paymentMethodToken);
     $this->assertEquals("1111", $newCreditCard->last4);
     $this->assertNotEquals($oldCreditCard->last4, $newCreditCard->last4);
 }
 /**
  * @param User $user
  * @param $request
  * @return boolean
  */
 public function addCard(User $user, $request)
 {
     $result = BraintreeCreditCard::create(["customerId" => $this->getCustomerId($user), "number" => $request->request->get("number"), "cvv" => $request->request->get("cvv"), "expirationMonth" => $request->request->get("month"), "expirationYear" => $request->request->get("year")]);
     return $result->success;
 }
 /**
  * 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');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * generic method for validating incoming gateway responses
  *
  * creates a new CreditCard 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 a populated instance of Address
         return new Result\Successful(CreditCard::factory($response['creditCard']));
     } elseif (isset($response['apiErrorResponse'])) {
         return new Result\Error($response['apiErrorResponse']);
     } else {
         throw new Exception\Unexpected("Expected address or apiErrorResponse");
     }
 }
 public function test_rangeNode_amount()
 {
     $customer = Braintree\Customer::createNoValidate();
     $creditCard = Braintree\CreditCard::create(['customerId' => $customer->id, 'cardholderName' => 'Jane Everywoman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'])->creditCard;
     $t_1000 = Braintree\Transaction::saleNoValidate(['amount' => '1000.00', 'paymentMethodToken' => $creditCard->token]);
     $t_1500 = Braintree\Transaction::saleNoValidate(['amount' => '1500.00', 'paymentMethodToken' => $creditCard->token]);
     $t_1800 = Braintree\Transaction::saleNoValidate(['amount' => '1800.00', 'paymentMethodToken' => $creditCard->token]);
     $collection = Braintree\Transaction::search([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([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([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);
 }
 public 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 = Test\Helper::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);
 }
Ejemplo n.º 13
0
 /**
  * sets instance properties from an array of values
  *
  * @ignore
  * @access protected
  * @param array $customerAttribs array of customer data
  * @return void
  */
 protected function _initialize($customerAttribs)
 {
     // set the attributes
     $this->_attributes = $customerAttribs;
     // map each address into its own object
     $addressArray = [];
     if (isset($customerAttribs['addresses'])) {
         foreach ($customerAttribs['addresses'] as $address) {
             $addressArray[] = Address::factory($address);
         }
     }
     $this->_set('addresses', $addressArray);
     // map each creditCard into its own object
     $creditCardArray = [];
     if (isset($customerAttribs['creditCards'])) {
         foreach ($customerAttribs['creditCards'] as $creditCard) {
             $creditCardArray[] = CreditCard::factory($creditCard);
         }
     }
     $this->_set('creditCards', $creditCardArray);
     // map each coinbaseAccount into its own object
     $coinbaseAccountArray = [];
     if (isset($customerAttribs['coinbaseAccounts'])) {
         foreach ($customerAttribs['coinbaseAccounts'] as $coinbaseAccount) {
             $coinbaseAccountArray[] = CoinbaseAccount::factory($coinbaseAccount);
         }
     }
     $this->_set('coinbaseAccounts', $coinbaseAccountArray);
     // map each paypalAccount into its own object
     $paypalAccountArray = [];
     if (isset($customerAttribs['paypalAccounts'])) {
         foreach ($customerAttribs['paypalAccounts'] as $paypalAccount) {
             $paypalAccountArray[] = PayPalAccount::factory($paypalAccount);
         }
     }
     $this->_set('paypalAccounts', $paypalAccountArray);
     // map each applePayCard into its own object
     $applePayCardArray = [];
     if (isset($customerAttribs['applePayCards'])) {
         foreach ($customerAttribs['applePayCards'] as $applePayCard) {
             $applePayCardArray[] = ApplePayCard::factory($applePayCard);
         }
     }
     $this->_set('applePayCards', $applePayCardArray);
     // map each androidPayCard into its own object
     $androidPayCardArray = [];
     if (isset($customerAttribs['androidPayCards'])) {
         foreach ($customerAttribs['androidPayCards'] as $androidPayCard) {
             $androidPayCardArray[] = AndroidPayCard::factory($androidPayCard);
         }
     }
     $this->_set('androidPayCards', $androidPayCardArray);
     $this->_set('paymentMethods', array_merge($this->creditCards, $this->paypalAccounts, $this->applePayCards, $this->coinbaseAccounts, $this->androidPayCards));
 }
Ejemplo n.º 14
0
 /**
  * This save credit cart to braintree.
  * @return array
  */
 public function saveCreditCard()
 {
     $sendArray = $this->options['creditCard'];
     if (isset($this->options['billing'])) {
         $sendArray['billingAddress'] = $this->options['billing'];
     }
     if (isset($this->options['customerId'])) {
         $sendArray['customerId'] = $this->options['customerId'];
     }
     $result = CreditCard::create($sendArray);
     if ($result->success) {
         return ['status' => true, 'result' => $result];
     } else {
         return ['status' => false, 'result' => $result];
     }
 }
Ejemplo n.º 15
0
 /**
  * @param string $token
  * @return \Braintree\CreditCard|null
  */
 public function find($token)
 {
     try {
         return CreditCard::find($token);
     } catch (\Exception $e) {
         return null;
     }
 }