123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725 |
- <?php
- namespace Test\Integration;
- require_once dirname(__DIR__) . '/Setup.php';
- use Test;
- use Test\Setup;
- use Braintree;
- class PaymentMethodTest extends Setup
- {
- public function testCreate_fromVaultedCreditCardNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099'
- ],
- 'share' => true
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertSame('411111', $result->paymentMethod->bin);
- $this->assertSame('1111', $result->paymentMethod->last4);
- $this->assertNotNull($result->paymentMethod->token);
- $this->assertNotNull($result->paymentMethod->imageUrl);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- }
- public function testGatewayCreate_fromVaultedCreditCardNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099'
- ],
- 'share' => true
- ]);
- $gateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_id',
- 'publicKey' => 'integration_public_key',
- 'privateKey' => 'integration_private_key'
- ]);
- $result = $gateway->paymentMethod()->create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertSame('411111', $result->paymentMethod->bin);
- $this->assertSame('1111', $result->paymentMethod->last4);
- $this->assertNotNull($result->paymentMethod->token);
- $this->assertNotNull($result->paymentMethod->imageUrl);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- }
- public function testCreate_fromFakeApplePayNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$applePayVisa,
- ]);
- $this->assertTrue($result->success);
- $applePayCard = $result->paymentMethod;
- $this->assertNotNull($applePayCard->token);
- $this->assertNotNull($applePayCard->bin);
- $this->assertSame(Braintree\ApplePayCard::VISA, $applePayCard->cardType);
- $this->assertContains("Visa ", $applePayCard->paymentInstrumentName);
- $this->assertContains("Visa ", $applePayCard->sourceDescription);
- $this->assertTrue($applePayCard->default);
- $this->assertContains('apple_pay', $applePayCard->imageUrl);
- $this->assertTrue(intval($applePayCard->expirationMonth) > 0);
- $this->assertTrue(intval($applePayCard->expirationYear) > 0);
- $this->assertSame($customer->id, $applePayCard->customerId);
- }
- public function testCreate_fromFakeAndroidPayProxyCardNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$androidPayDiscover
- ]);
- $this->assertTrue($result->success);
- $androidPayCard = $result->paymentMethod;
- $this->assertNotNull($androidPayCard->token);
- $this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->virtualCardType);
- $this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->cardType);
- $this->assertSame("1117", $androidPayCard->virtualCardLast4);
- $this->assertSame("1117", $androidPayCard->last4);
- $this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCard->sourceCardType);
- $this->assertSame("1111", $androidPayCard->sourceCardLast4);
- $this->assertSame("Discover 1111", $androidPayCard->sourceDescription);
- $this->assertTrue($androidPayCard->default);
- $this->assertContains('android_pay', $androidPayCard->imageUrl);
- $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
- $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
- $this->assertSame($customer->id, $androidPayCard->customerId);
- }
- public function testCreate_fromFakeAndroidPayNetworkTokenNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$androidPayMasterCard
- ]);
- $this->assertTrue($result->success);
- $androidPayCard = $result->paymentMethod;
- $this->assertNotNull($androidPayCard->token);
- $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->virtualCardType);
- $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->cardType);
- $this->assertSame("4444", $androidPayCard->virtualCardLast4);
- $this->assertSame("4444", $androidPayCard->last4);
- $this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCard->sourceCardType);
- $this->assertSame("4444", $androidPayCard->sourceCardLast4);
- $this->assertSame("MasterCard 4444", $androidPayCard->sourceDescription);
- $this->assertTrue($androidPayCard->default);
- $this->assertContains('android_pay', $androidPayCard->imageUrl);
- $this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
- $this->assertTrue(intval($androidPayCard->expirationYear) > 0);
- $this->assertSame($customer->id, $androidPayCard->customerId);
- }
- public function testCreate_fromFakeAmexExpressCheckoutCardNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$amexExpressCheckout
- ]);
- $this->assertTrue($result->success);
- $amexExpressCheckoutCard = $result->paymentMethod;
- $this->assertInstanceOf('Braintree\AmexExpressCheckoutCard', $amexExpressCheckoutCard);
- $this->assertNotNull($amexExpressCheckoutCard->token);
- $this->assertSame(Braintree\CreditCard::AMEX, $amexExpressCheckoutCard->cardType);
- $this->assertSame("341111", $amexExpressCheckoutCard->bin);
- $this->assertSame("12/21", $amexExpressCheckoutCard->cardMemberExpiryDate);
- $this->assertSame("0005", $amexExpressCheckoutCard->cardMemberNumber);
- $this->assertSame("American Express", $amexExpressCheckoutCard->cardType);
- $this->assertNotNull($amexExpressCheckoutCard->sourceDescription);
- $this->assertContains(".png", $amexExpressCheckoutCard->imageUrl);
- $this->assertTrue(intval($amexExpressCheckoutCard->expirationMonth) > 0);
- $this->assertTrue(intval($amexExpressCheckoutCard->expirationYear) > 0);
- $this->assertTrue($amexExpressCheckoutCard->default);
- $this->assertSame($customer->id, $amexExpressCheckoutCard->customerId);
- $this->assertEquals([], $amexExpressCheckoutCard->subscriptions);
- }
- public function testCreate_fromFakeVenmoAccountNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create(array(
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$venmoAccount
- ));
- $this->assertTrue($result->success);
- $venmoAccount = $result->paymentMethod;
- $this->assertInstanceOf('Braintree\VenmoAccount', $venmoAccount);
- $this->assertNotNull($venmoAccount->token);
- $this->assertNotNull($venmoAccount->sourceDescription);
- $this->assertContains(".png", $venmoAccount->imageUrl);
- $this->assertTrue($venmoAccount->default);
- $this->assertSame($customer->id, $venmoAccount->customerId);
- $this->assertEquals(array(), $venmoAccount->subscriptions);
- $this->assertSame("venmojoe", $venmoAccount->username);
- $this->assertSame("Venmo-Joe-1", $venmoAccount->venmoUserId);
- }
- public function testCreate_fromFakeEuropeBankAccountNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $this->setExpectedException('Braintree\Exception\ServerError');
- $result = Braintree\PaymentMethod::create(array(
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$europe
- ));
- }
- public function testCreate_fromUnvalidatedCreditCardNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099',
- 'options' => [
- 'validate' => false
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertSame('411111', $result->paymentMethod->bin);
- $this->assertSame('1111', $result->paymentMethod->last4);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertNotNull($result->paymentMethod->token);
- }
- public function testCreate_fromUnvalidatedFuturePaypalAccountNonce()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'PAYPAL_CONSENT_CODE',
- 'token' => $paymentMethodToken
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertSame('jane.doe@example.com', $result->paymentMethod->email);
- $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- }
- public function testCreate_fromOrderPaymentPaypalAccountNonce()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'intent' => 'order',
- 'payment_token' => 'paypal-payment-token',
- 'payer_id' => 'paypal-payer-id',
- 'token' => $paymentMethodToken,
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertSame('bt_buyer_us@paypal.com', $result->paymentMethod->email);
- $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertNotNull($result->paymentMethod->payerId);
- }
- public function testCreate_fromOrderPaymentPaypalAccountNonceWithPayPalOptionsSnakeCase()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'intent' => 'order',
- 'payment_token' => 'paypal-payment-token',
- 'payer_id' => 'paypal-payer-id',
- 'token' => $paymentMethodToken,
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'options' => [
- 'paypal' => [
- 'payee_email' => 'payee@example.com',
- 'order_id' => 'merchant-order-id',
- 'custom_field' => 'custom merchant field',
- 'description' => 'merchant description',
- 'amount' => '1.23',
- ]
- ],
- ]);
- $this->assertSame('bt_buyer_us@paypal.com', $result->paymentMethod->email);
- $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertNotNull($result->paymentMethod->payerId);
- }
- public function testCreate_fromOrderPaymentPaypalAccountNonceWithPayPalOptionsCamelCase()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'intent' => 'order',
- 'payment_token' => 'paypal-payment-token',
- 'payer_id' => 'paypal-payer-id',
- 'token' => $paymentMethodToken,
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'options' => [
- 'paypal' => [
- 'payeeEmail' => 'payee@example.com',
- 'orderId' => 'merchant-order-id',
- 'customField' => 'custom merchant field',
- 'description' => 'merchant description',
- 'amount' => '1.23',
- 'shipping' => [
- 'firstName' => 'Andrew',
- 'lastName' => 'Mason',
- 'company' => 'Braintree',
- 'streetAddress' => '456 W Main St',
- 'extendedAddress' => 'Apt 2F',
- 'locality' => 'Bartlett',
- 'region' => 'IL',
- 'postalCode' => '60103',
- 'countryName' => 'United States of America',
- 'countryCodeAlpha2' => 'US',
- 'countryCodeAlpha3' => 'USA',
- 'countryCodeNumeric' => '840'
- ],
- ],
- ],
- ]);
- $this->assertSame('bt_buyer_us@paypal.com', $result->paymentMethod->email);
- $this->assertSame($paymentMethodToken, $result->paymentMethod->token);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertNotNull($result->paymentMethod->payerId);
- }
- public function testCreate_fromPayPalRefreshToken()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paypalRefreshToken' => 'PAYPAL_REFRESH_TOKEN',
- ]);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertSame("B_FAKE_ID", $result->paymentMethod->billingAgreementId);
- $this->assertNotNull($result->paymentMethod->payerId);
- }
- public function testCreate_fromPayPalRefreshTokenWithoutUpgrade()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paypalRefreshToken' => 'PAYPAL_REFRESH_TOKEN',
- 'paypalVaultWithoutUpgrade' => true,
- ]);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- $this->assertNull($result->paymentMethod->billingAgreementId);
- }
- public function testCreate_fromAbstractPaymentMethodNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$abstractTransactable,
- ]);
- $this->assertTrue($result->success);
- $this->assertNotNull($result->paymentMethod->token);
- $this->assertSame($customer->id, $result->paymentMethod->customerId);
- }
- public function testCreate_doesNotWorkForUnvalidatedOnetimePaypalAccountNonce()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'access_token' => 'PAYPAL_ACCESS_TOKEN',
- 'token' => $paymentMethodToken
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertFalse($result->success);
- $errors = $result->errors->forKey('paypalAccount')->errors;
- $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
- }
- public function testCreate_handlesValidationErrorsForPayPalAccounts()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'token' => $paymentMethodToken
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertFalse($result->success);
- $errors = $result->errors->forKey('paypalAccount')->errors;
- $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code);
- $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CONSENT_CODE_OR_ACCESS_TOKEN_IS_REQUIRED, $errors[1]->code);
- }
- public function testCreate_allowsPassingDefaultOptionWithNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $card1 = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Cardholder',
- 'number' => '5105105105105100',
- 'expirationDate' => '05/12'
- ])->creditCard;
- $this->assertTrue($card1->isDefault());
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099',
- 'options' => [
- 'validate' => false
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'options' => [
- 'makeDefault' => true
- ]
- ]);
- $card2 = $result->paymentMethod;
- $card1 = Braintree\CreditCard::find($card1->token);
- $this->assertFalse($card1->isDefault());
- $this->assertTrue($card2->isDefault());
- }
- public function testCreate_overridesNonceToken()
- {
- $customer = Braintree\Customer::createNoValidate();
- $firstToken = 'FIRST_TOKEN-' . strval(rand());
- $secondToken = 'SECOND_TOKEN-' . strval(rand());
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'token' => $firstToken,
- 'number' => '4111111111111111',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099',
- 'options' => [
- 'validate' => false
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'token' => $secondToken
- ]);
- $card = $result->paymentMethod;
- $this->assertEquals($secondToken, $card->token);
- }
- public function testCreateWithVerificationAmount()
- {
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4000111111111115',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099',
- ]
- ]);
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'options' => [
- 'verifyCard' => 'true',
- 'verificationAmount' => '5.00',
- ]
- ]);
- $this->assertFalse($result->success);
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
- }
- public function testCreate_respectsVerifyCardAndVerificationMerchantAccountIdWhenIncludedOutsideOfTheNonce()
- {
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4000111111111115',
- 'expirationMonth' => '11',
- 'expirationYear' => '2099',
- ]
- ]);
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'options' => [
- 'verifyCard' => 'true',
- 'verificationMerchantAccountId' => Test\Helper::nonDefaultMerchantAccountId(),
- ]
- ]);
- $this->assertFalse($result->success);
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
- $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
- $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
- $this->assertEquals(Test\Helper::nonDefaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
- }
- public function testCreate_respectsFailOnDuplicatePaymentMethodWhenIncludedOutsideTheNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]);
- $this->assertTrue($result->success);
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]
- ]);
- $updateResult = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'options' => [
- 'failOnDuplicatePaymentMethod' => 'true',
- ]
- ]);
- $this->assertFalse($updateResult->success);
- $resultErrors = $updateResult->errors->deepAll();
- $this->assertEquals("81724", $resultErrors[0]->code);
- }
- public function testCreate_allowsPassingABillingAddressOutsideOfTheNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '12',
- 'expirationYear' => '2020',
- 'options' => [
- 'validate' => false
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddress' => [
- 'streetAddress' => '123 Abc Way'
- ]
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
- $token = $result->paymentMethod->token;
- $foundCreditCard = Braintree\CreditCard::find($token);
- $this->assertTrue(NULL != $foundCreditCard);
- $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
- }
- public function testCreate_overridesTheBillingAddressInTheNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '12',
- 'expirationYear' => '2020',
- 'options' => [
- 'validate' => false
- ],
- 'billingAddress' => [
- 'streetAddress' => '456 Xyz Way'
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddress' => [
- 'streetAddress' => '123 Abc Way'
- ]
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
- $token = $result->paymentMethod->token;
- $foundCreditCard = Braintree\CreditCard::find($token);
- $this->assertTrue(NULL != $foundCreditCard);
- $this->assertEquals('123 Abc Way', $foundCreditCard->billingAddress->streetAddress);
- }
- public function testCreate_doesNotOverrideTheBillingAddressForAVaultedCreditCard()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'customerId' => $customer->id,
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '12',
- 'expirationYear' => '2020',
- 'billingAddress' => [
- 'streetAddress' => '456 Xyz Way'
- ]
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddress' => [
- 'streetAddress' => '123 Abc Way'
- ]
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
- $token = $result->paymentMethod->token;
- $foundCreditCard = Braintree\CreditCard::find($token);
- $this->assertTrue(NULL != $foundCreditCard);
- $this->assertEquals('456 Xyz Way', $foundCreditCard->billingAddress->streetAddress);
- }
- public function testCreate_allowsPassingABillingAddressIdOutsideOfTheNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonce_for_new_card([
- 'credit_card' => [
- 'number' => '4111111111111111',
- 'expirationMonth' => '12',
- 'expirationYear' => '2020',
- 'options' => [
- 'validate' => false
- ]
- ]
- ]);
- $address = Braintree\Address::create([
- 'customerId' => $customer->id,
- 'firstName' => 'Bobby',
- 'lastName' => 'Tables'
- ])->address;
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddressId' => $address->id
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\CreditCard'));
- $token = $result->paymentMethod->token;
- $foundCreditCard = Braintree\CreditCard::find($token);
- $this->assertTrue(NULL != $foundCreditCard);
- $this->assertEquals('Bobby', $foundCreditCard->billingAddress->firstName);
- $this->assertEquals('Tables', $foundCreditCard->billingAddress->lastName);
- }
- public function testCreate_doesNotReturnAnErrorIfCreditCardOptionsArePresentForAPaypalNonce()
- {
- $customer = Braintree\Customer::createNoValidate();
- $originalToken = 'paypal-account-' . strval(rand());
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPaypalAccount([
- 'paypalAccount' => [
- 'consentCode' => 'consent-code',
- 'token' => $originalToken
- ]
- ]);
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'options' => [
- 'verifyCard' => 'true',
- 'failOnDuplicatePaymentMethod' => 'true',
- 'verificationMerchantAccountId' => 'Not a Real Merchant Account Id'
- ]
- ]);
- $this->assertTrue($result->success);
- }
- public function testCreate_ignoresPassedBillingAddressParamsForPaypalAccount()
- {
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPaypalAccount([
- 'paypalAccount' => [
- 'consentCode' => 'PAYPAL_CONSENT_CODE',
- ]
- ]);
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddress' => [
- 'streetAddress' => '123 Abc Way'
- ]
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
- $token = $result->paymentMethod->token;
- $foundPaypalAccount = Braintree\PaypalAccount::find($token);
- $this->assertTrue(NULL != $foundPaypalAccount);
- }
- public function testCreate_ignoresPassedBillingAddressIdForPaypalAccount()
- {
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPaypalAccount([
- 'paypalAccount' => [
- 'consentCode' => 'PAYPAL_CONSENT_CODE',
- ]
- ]);
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id,
- 'billingAddressId' => 'address_id'
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue(is_a($result->paymentMethod, 'Braintree\PaypalAccount'));
- $token = $result->paymentMethod->token;
- $foundPaypalAccount = Braintree\PaypalAccount::find($token);
- $this->assertTrue(NULL != $foundPaypalAccount);
- }
- public function testCreate_acceptsNumberAndOtherCreditCardParameters()
- {
- $customer = Braintree\Customer::createNoValidate();
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => Braintree\Test\Nonces::$transactable,
- 'cardholderName' => 'Jane Doe',
- 'cvv' => '123',
- 'expirationMonth' => '10',
- 'expirationYear' => '24',
- 'number' => '4242424242424242'
- ]);
- $this->assertTrue($result->success);
- $this->assertTrue('Jane Doe' == $result->paymentMethod->cardholderName);
- $this->assertTrue('10' == $result->paymentMethod->expirationMonth);
- $this->assertTrue('2024' == $result->paymentMethod->expirationYear);
- $this->assertTrue('424242' == $result->paymentMethod->bin);
- $this->assertTrue('4242' == $result->paymentMethod->last4);
- }
- public function testFind_returnsCreditCards()
- {
- $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);
- $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
- $this->assertEquals($paymentMethodToken, $foundCreditCard->token);
- $this->assertEquals('510510', $foundCreditCard->bin);
- $this->assertEquals('5100', $foundCreditCard->last4);
- $this->assertEquals('05/2011', $foundCreditCard->expirationDate);
- }
- public function testFind_returnsCreditCardsWithSubscriptions()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => '5105105105105100',
- 'expirationDate' => '05/2011',
- ]);
- $this->assertTrue($creditCardResult->success);
- $subscriptionId = strval(rand());
- Braintree\Subscription::create([
- 'id' => $subscriptionId,
- 'paymentMethodToken' => $creditCardResult->creditCard->token,
- 'planId' => 'integration_trialless_plan',
- 'price' => '1.00'
- ]);
- $foundCreditCard = Braintree\PaymentMethod::find($creditCardResult->creditCard->token);
- $this->assertEquals($subscriptionId, $foundCreditCard->subscriptions[0]->id);
- $this->assertEquals('integration_trialless_plan', $foundCreditCard->subscriptions[0]->planId);
- $this->assertEquals('1.00', $foundCreditCard->subscriptions[0]->price);
- }
- public function testFind_returnsPayPalAccounts()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'PAYPAL_CONSENT_CODE',
- 'token' => $paymentMethodToken
- ]
- ]);
- Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $foundPayPalAccount = Braintree\PaymentMethod::find($paymentMethodToken);
- $this->assertSame('jane.doe@example.com', $foundPayPalAccount->email);
- $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
- }
- public function testFind_returnsApplePayCards()
- {
- $paymentMethodToken = 'APPLE_PAY-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $nonce = Braintree\Test\Nonces::$applePayVisa;
- Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'token' => $paymentMethodToken
- ]);
- $foundApplePayCard = Braintree\PaymentMethod::find($paymentMethodToken);
- $this->assertSame($paymentMethodToken, $foundApplePayCard->token);
- $this->assertInstanceOf('Braintree\ApplePayCard', $foundApplePayCard);
- $this->assertTrue(intval($foundApplePayCard->expirationMonth) > 0);
- $this->assertTrue(intval($foundApplePayCard->expirationYear) > 0);
- }
- public function testFind_returnsAndroidPayCards()
- {
- $paymentMethodToken = 'ANDROID-PAY-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $nonce = Braintree\Test\Nonces::$androidPay;
- Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'token' => $paymentMethodToken
- ]);
- $foundAndroidPayCard = Braintree\PaymentMethod::find($paymentMethodToken);
- $this->assertSame($paymentMethodToken, $foundAndroidPayCard->token);
- $this->assertInstanceOf('Braintree\AndroidPayCard', $foundAndroidPayCard);
- $this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->virtualCardType);
- $this->assertSame("1117", $foundAndroidPayCard->virtualCardLast4);
- $this->assertSame(Braintree\CreditCard::DISCOVER, $foundAndroidPayCard->sourceCardType);
- $this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
- $this->assertSame($customer->id, $foundAndroidPayCard->customerId);
- $this->assertTrue($foundAndroidPayCard->default);
- $this->assertContains('android_pay', $foundAndroidPayCard->imageUrl);
- $this->assertTrue(intval($foundAndroidPayCard->expirationMonth) > 0);
- $this->assertTrue(intval($foundAndroidPayCard->expirationYear) > 0);
- }
- public function testFind_returnsAbstractPaymentMethods()
- {
- $paymentMethodToken = 'ABSTRACT-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $nonce = Braintree\Test\Nonces::$abstractTransactable;
- Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce,
- 'token' => $paymentMethodToken
- ]);
- $foundPaymentMethod = Braintree\PaymentMethod::find($paymentMethodToken);
- $this->assertSame($paymentMethodToken, $foundPaymentMethod-> token);
- }
- public function testFind_throwsIfCannotBeFound()
- {
- $this->setExpectedException('Braintree\Exception\NotFound');
- Braintree\PaymentMethod::find('NON_EXISTENT_TOKEN');
- }
- public function testUpdate_updatesTheCreditCard()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'cardholderName' => 'Original Holder',
- 'customerId' => $customer->id,
- 'cvv' => '123',
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'cardholderName' => 'New Holder',
- 'cvv' => '456',
- 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
- 'expirationDate' => "06/2013"
- ]);
- $this->assertTrue($updateResult->success);
- $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
- $updatedCreditCard = $updateResult->paymentMethod;
- $this->assertSame("New Holder", $updatedCreditCard->cardholderName);
- $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, 0, 6), $updatedCreditCard->bin);
- $this->assertSame(substr(Braintree\Test\CreditCardNumbers::$masterCard, -4), $updatedCreditCard->last4);
- $this->assertSame("06/2013", $updatedCreditCard->expirationDate);
- }
- public function testUpdate_createsANewBillingAddressByDefault()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012",
- 'billingAddress' => [
- 'streetAddress' => '123 Nigeria Ave'
- ]
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'billingAddress' => [
- 'region' => 'IL'
- ]
- ]);
- $this->assertTrue($updateResult->success);
- $updatedCreditCard = $updateResult->paymentMethod;
- $this->assertSame("IL", $updatedCreditCard->billingAddress->region);
- $this->assertSame(NULL, $updatedCreditCard->billingAddress->streetAddress);
- $this->assertFalse($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
- }
- public function testUpdate_updatesTheBillingAddressIfOptionIsSpecified()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012",
- 'billingAddress' => [
- 'streetAddress' => '123 Nigeria Ave'
- ]
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'billingAddress' => [
- 'region' => 'IL',
- 'options' => [
- 'updateExisting' => 'true'
- ]
- ],
- ]);
- $this->assertTrue($updateResult->success);
- $updatedCreditCard = $updateResult->paymentMethod;
- $this->assertSame("IL", $updatedCreditCard->billingAddress->region);
- $this->assertSame("123 Nigeria Ave", $updatedCreditCard->billingAddress->streetAddress);
- $this->assertTrue($creditCard->billingAddress->id == $updatedCreditCard->billingAddress->id);
- }
- public function testUpdate_updatesTheCountryViaCodes()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012",
- 'billingAddress' => [
- 'streetAddress' => '123 Nigeria Ave'
- ]
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'billingAddress' => [
- 'countryName' => 'American Samoa',
- 'countryCodeAlpha2' => 'AS',
- 'countryCodeAlpha3' => 'ASM',
- 'countryCodeNumeric' => '016',
- 'options' => [
- 'updateExisting' => 'true'
- ]
- ],
- ]);
- $this->assertTrue($updateResult->success);
- $updatedCreditCard = $updateResult->paymentMethod;
- $this->assertSame("American Samoa", $updatedCreditCard->billingAddress->countryName);
- $this->assertSame("AS", $updatedCreditCard->billingAddress->countryCodeAlpha2);
- $this->assertSame("ASM", $updatedCreditCard->billingAddress->countryCodeAlpha3);
- $this->assertSame("016", $updatedCreditCard->billingAddress->countryCodeNumeric);
- }
- public function testUpdate_canPassExpirationMonthAndExpirationYear()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'number' => Braintree\Test\CreditCardNumbers::$masterCard,
- 'expirationMonth' => "07",
- 'expirationYear' => "2011"
- ]);
- $this->assertTrue($updateResult->success);
- $this->assertSame($updateResult->paymentMethod->token, $creditCard->token);
- $updatedCreditCard = $updateResult->paymentMethod;
- $this->assertSame("07", $updatedCreditCard->expirationMonth);
- $this->assertSame("07", $updatedCreditCard->expirationMonth);
- $this->assertSame("07/2011", $updatedCreditCard->expirationDate);
- }
- public function testUpdate_verifiesTheUpdateIfOptionsVerifyCardIsTrue()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'cardholderName' => 'Original Holder',
- 'customerId' => $customer->id,
- 'cvv' => '123',
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'cardholderName' => 'New Holder',
- 'cvv' => '456',
- 'number' => Braintree\Test\CreditCardNumbers::$failsSandboxVerification['MasterCard'],
- 'expirationDate' => "06/2013",
- 'options' => [
- 'verifyCard' => 'true'
- ]
- ]);
- $this->assertFalse($updateResult->success);
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
- $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
- }
- public function testUpdate_canPassCustomVerificationAmount()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'cardholderName' => 'Card Holder',
- 'customerId' => $customer->id,
- 'cvv' => '123',
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2020"
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'paymentMethodNonce' => Braintree\Test\Nonces::$processorDeclinedMasterCard,
- 'options' => [
- 'verifyCard' => 'true',
- 'verificationAmount' => '2.34'
- ]
- ]);
- $this->assertFalse($updateResult->success);
- $this->assertEquals(Braintree\Result\CreditCardVerification::PROCESSOR_DECLINED, $updateResult->creditCardVerification->status);
- $this->assertEquals(NULL, $updateResult->creditCardVerification->gatewayRejectionReason);
- }
- public function testUpdate_canUpdateTheBillingAddress()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'cardholderName' => 'Original Holder',
- 'customerId' => $customer->id,
- 'cvv' => '123',
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => '05/2012',
- 'billingAddress' => [
- 'firstName' => 'Old First Name',
- 'lastName' => 'Old Last Name',
- 'company' => 'Old Company',
- 'streetAddress' => '123 Old St',
- 'extendedAddress' => 'Apt Old',
- 'locality' => 'Old City',
- 'region' => 'Old State',
- 'postalCode' => '12345',
- 'countryName' => 'Canada'
- ]
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'billingAddress' => [
- 'firstName' => 'New First Name',
- 'lastName' => 'New Last Name',
- 'company' => 'New Company',
- 'streetAddress' => '123 New St',
- 'extendedAddress' => 'Apt New',
- 'locality' => 'New City',
- 'region' => 'New State',
- 'postalCode' => '56789',
- 'countryName' => 'United States of America'
- ]
- ]);
- $this->assertTrue($updateResult->success);
- $address = $updateResult->paymentMethod->billingAddress;
- $this->assertSame('New First Name', $address->firstName);
- $this->assertSame('New Last Name', $address->lastName);
- $this->assertSame('New Company', $address->company);
- $this->assertSame('123 New St', $address->streetAddress);
- $this->assertSame('Apt New', $address->extendedAddress);
- $this->assertSame('New City', $address->locality);
- $this->assertSame('New State', $address->region);
- $this->assertSame('56789', $address->postalCode);
- $this->assertSame('United States of America', $address->countryName);
- }
- public function testUpdate_returnsAnErrorIfInvalid()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'cardholderName' => 'Original Holder',
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2012"
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $updateResult = Braintree\PaymentMethod::update($creditCard->token, [
- 'cardholderName' => 'New Holder',
- 'number' => 'invalid',
- 'expirationDate' => "05/2014",
- ]);
- $this->assertFalse($updateResult->success);
- $numberErrors = $updateResult->errors->forKey('creditCard')->onAttribute('number');
- $this->assertEquals("Credit card number must be 12-19 digits.", $numberErrors[0]->message);
- }
- public function testUpdate_canUpdateTheDefault()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult1 = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2009"
- ]);
- $this->assertTrue($creditCardResult1->success);
- $creditCard1 = $creditCardResult1->creditCard;
- $creditCardResult2 = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => "05/2009"
- ]);
- $this->assertTrue($creditCardResult2->success);
- $creditCard2 = $creditCardResult2->creditCard;
- $this->assertTrue($creditCard1->default);
- $this->assertFalse($creditCard2->default);
- $updateResult = Braintree\PaymentMethod::update($creditCard2->token, [
- 'options' => [
- 'makeDefault' => 'true'
- ]
- ]);
- $this->assertTrue($updateResult->success);
- $this->assertFalse(Braintree\PaymentMethod::find($creditCard1->token)->default);
- $this->assertTrue(Braintree\PaymentMethod::find($creditCard2->token)->default);
- }
- public function testUpdate_updatesAPaypalAccountsToken()
- {
- $customer = Braintree\Customer::createNoValidate();
- $originalToken = 'paypal-account-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'consent-code',
- 'token' => $originalToken
- ]
- ]);
- $originalResult = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id
- ]);
- $this->assertTrue($originalResult->success);
- $originalPaypalAccount = $originalResult->paymentMethod;
- $updatedToken = 'UPDATED_TOKEN-' . strval(rand());
- $updateResult = Braintree\PaymentMethod::update($originalPaypalAccount->token, [
- 'token' => $updatedToken
- ]);
- $this->assertTrue($updateResult->success);
- $updatedPaypalAccount = Braintree\PaymentMethod::find($updatedToken);
- $this->assertEquals($originalPaypalAccount->email, $updatedPaypalAccount->email);
- $this->setExpectedException('Braintree\Exception\NotFound', 'payment method with token ' . $originalToken . ' not found');
- Braintree\PaymentMethod::find($originalToken);
- }
- public function testUpdate_canMakeAPaypalAccountTheDefaultPaymentMethod()
- {
- $customer = Braintree\Customer::createNoValidate();
- $creditCardResult = Braintree\CreditCard::create([
- 'customerId' => $customer->id,
- 'number' => Braintree\Test\CreditCardNumbers::$visa,
- 'expirationDate' => '05/2009',
- 'options' => [
- 'makeDefault' => 'true'
- ]
- ]);
- $this->assertTrue($creditCardResult->success);
- $creditCard = $creditCardResult->creditCard;
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'consent-code',
- ]
- ]);
- $originalToken = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $nonce,
- 'customerId' => $customer->id
- ])->paymentMethod->token;
- $updateResult = Braintree\PaymentMethod::update($originalToken, [
- 'options' => [
- 'makeDefault' => 'true'
- ]
- ]);
- $this->assertTrue($updateResult->success);
- $updatedPaypalAccount = Braintree\PaymentMethod::find($originalToken);
- $this->assertTrue($updatedPaypalAccount->default);
- }
- public function testUpdate_returnsAnErrorIfATokenForAccountIsUsedToAttemptAnUpdate()
- {
- $customer = Braintree\Customer::createNoValidate();
- $firstToken = 'paypal-account-' . strval(rand());
- $secondToken = 'paypal-account-' . strval(rand());
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $firstNonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'consent-code',
- 'token' => $firstToken
- ]
- ]);
- $firstResult = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $firstNonce,
- 'customerId' => $customer->id
- ]);
- $this->assertTrue($firstResult->success);
- $firstPaypalAccount = $firstResult->paymentMethod;
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $secondNonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'consent-code',
- 'token' => $secondToken
- ]
- ]);
- $secondResult = Braintree\PaymentMethod::create([
- 'paymentMethodNonce' => $secondNonce,
- 'customerId' => $customer->id
- ]);
- $this->assertTrue($secondResult->success);
- $secondPaypalAccount = $firstResult->paymentMethod;
- $updateResult = Braintree\PaymentMethod::update($firstToken, [
- 'token' => $secondToken
- ]);
- $this->assertFalse($updateResult->success);
- $resultErrors = $updateResult->errors->deepAll();
- $this->assertEquals("92906", $resultErrors[0]->code);
- }
- 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();
- }
- public function testDelete_worksWithPayPalAccounts()
- {
- $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
- $customer = Braintree\Customer::createNoValidate();
- $http = new HttpClientApi(Braintree\Configuration::$global);
- $nonce = $http->nonceForPayPalAccount([
- 'paypal_account' => [
- 'consent_code' => 'PAYPAL_CONSENT_CODE',
- 'token' => $paymentMethodToken
- ]
- ]);
- $paypalAccountResult = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $nonce
- ]);
- $this->assertTrue($paypalAccountResult->success);
- Braintree\PaymentMethod::delete($paymentMethodToken, ['revokeAllGrants' => false]);
- $this->setExpectedException('Braintree\Exception\NotFound');
- Braintree\PaymentMethod::find($paymentMethodToken);
- }
- public function testGrant_returnsASingleUseNonce()
- {
- $partnerMerchantGateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_public_id',
- 'publicKey' => 'oauth_app_partner_user_public_key',
- 'privateKey' => 'oauth_app_partner_user_private_key'
- ]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Joe',
- 'lastName' => 'Brown'
- ])->customer;
- $creditCard = $partnerMerchantGateway->creditCard()->create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Adam Davis',
- 'number' => '4111111111111111',
- 'expirationDate' => '05/2009'
- ])->creditCard;
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token);
- $this->assertTrue($grantResult->success);
- $result = Braintree\Transaction::sale([
- 'amount' => '100.00',
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertTrue($result->success);
- $secondResult = Braintree\Transaction::sale([
- 'amount' => '100.00',
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertFalse($secondResult->success);
- }
- public function testGrant_returnsANonceThatIsNotVaultable()
- {
- $partnerMerchantGateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_public_id',
- 'publicKey' => 'oauth_app_partner_user_public_key',
- 'privateKey' => 'oauth_app_partner_user_private_key'
- ]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Joe',
- 'lastName' => 'Brown'
- ])->customer;
- $creditCard = $partnerMerchantGateway->creditCard()->create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Adam Davis',
- 'number' => '4111111111111111',
- 'expirationDate' => '05/2009'
- ])->creditCard;
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, ['allow_vaulting' => false]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Bob',
- 'lastName' => 'Rob'
- ])->customer;
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertFalse($result->success);
- }
- public function testGrant_returnsANonceThatIsVaultableSnakeCase()
- {
- $partnerMerchantGateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_public_id',
- 'publicKey' => 'oauth_app_partner_user_public_key',
- 'privateKey' => 'oauth_app_partner_user_private_key'
- ]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Joe',
- 'lastName' => 'Brown'
- ])->customer;
- $creditCard = $partnerMerchantGateway->creditCard()->create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Adam Davis',
- 'number' => '4111111111111111',
- 'expirationDate' => '05/2009'
- ])->creditCard;
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, ['allow_vaulting' => true]);
- $customer = Braintree\Customer::create([
- 'firstName' => 'Bob',
- 'lastName' => 'Rob'
- ])->customer;
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertTrue($result->success);
- }
- public function testGrant_returnsANonceThatIsVaultableCamelCase()
- {
- $partnerMerchantGateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_public_id',
- 'publicKey' => 'oauth_app_partner_user_public_key',
- 'privateKey' => 'oauth_app_partner_user_private_key'
- ]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Joe',
- 'lastName' => 'Brown'
- ])->customer;
- $creditCard = $partnerMerchantGateway->creditCard()->create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Adam Davis',
- 'number' => '4111111111111111',
- 'expirationDate' => '05/2009'
- ])->creditCard;
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, ['allowVaulting' => true, 'includeBillingPostalCode' => true]);
- $customer = Braintree\Customer::create([
- 'firstName' => 'Bob',
- 'lastName' => 'Rob'
- ])->customer;
- $result = Braintree\PaymentMethod::create([
- 'customerId' => $customer->id,
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertTrue($result->success);
- }
- public function testGrant_raisesAnErrorIfTokenIsNotFound()
- {
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $this->setExpectedException('Braintree\Exception\NotFound');
- $grantResult = $grantingGateway->paymentMethod()->grant("not_a_real_token", false);
- }
- public function testRevoke_rendersANonceUnusable()
- {
- $partnerMerchantGateway = new Braintree\Gateway([
- 'environment' => 'development',
- 'merchantId' => 'integration_merchant_public_id',
- 'publicKey' => 'oauth_app_partner_user_public_key',
- 'privateKey' => 'oauth_app_partner_user_private_key'
- ]);
- $customer = $partnerMerchantGateway->customer()->create([
- 'firstName' => 'Joe',
- 'lastName' => 'Brown'
- ])->customer;
- $creditCard = $partnerMerchantGateway->creditCard()->create([
- 'customerId' => $customer->id,
- 'cardholderName' => 'Adam Davis',
- 'number' => '4111111111111111',
- 'expirationDate' => '05/2009'
- ])->creditCard;
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $grantResult = $grantingGateway->paymentMethod()->grant($creditCard->token, false);
- $revokeResult = $grantingGateway->paymentMethod()->revoke($creditCard->token);
- $this->assertTrue($revokeResult->success);
- $result = Braintree\Transaction::sale([
- 'amount' => '100.00',
- 'paymentMethodNonce' => $grantResult->paymentMethodNonce->nonce
- ]);
- $this->assertFalse($result->success);
- }
- public function testRevoke_raisesAnErrorIfTokenIsNotFound()
- {
- $oauthAppGateway = new Braintree\Gateway([
- 'clientId' => 'client_id$development$integration_client_id',
- 'clientSecret' => 'client_secret$development$integration_client_secret'
- ]);
- $code = Test\Braintree\OAuthTestHelper::createGrant($oauthAppGateway, [
- 'merchant_public_id' => 'integration_merchant_id',
- 'scope' => 'grant_payment_method'
- ]);
- $credentials = $oauthAppGateway->oauth()->createTokenFromCode([
- 'code' => $code,
- ]);
- $grantingGateway = new Braintree\Gateway([
- 'accessToken' => $credentials->accessToken
- ]);
- $this->setExpectedException('Braintree\Exception\NotFound');
- $grantResult = $grantingGateway->paymentMethod()->revoke("not_a_real_token");
- }
- }
|