public function testFind_exposesNullThreeDSecureInfoIfNoneExists() { $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonce_for_new_card(["creditCard" => ["number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"]]); $foundNonce = Braintree\PaymentMethodNonce::find($nonce); $info = $foundNonce->threeDSecureInfo; $this->assertEquals($nonce, $foundNonce->nonce); $this->assertNull($info); }
public function test_paypalAccountEmail() { $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE'))); $customerId = 'UNIQUE_CUSTOMER_ID-' . strval(rand()); $customerResult = Braintree\Customer::create(array('paymentMethodNonce' => $nonce, 'id' => $customerId)); $this->assertTrue($customerResult->success); $customer = $customerResult->customer; $collection = Braintree\Customer::search(array(Braintree\CustomerSearch::id()->is($customer->id), Braintree\CustomerSearch::paypalAccountEmail()->is('*****@*****.**'))); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($customer->id, $collection->firstItem()->id); }
public function testCanExchangeNonceForEuropeBankAccount() { $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'altpay_merchant', 'publicKey' => 'altpay_merchant_public_key', 'privateKey' => 'altpay_merchant_private_key')); $result = $gateway->customer()->create(); $this->assertTrue($result->success); $customer = $result->customer; $clientApi = new HttpClientApi($gateway->config); $nonce = $clientApi->nonceForNewEuropeanBankAccount(array("customerId" => $customer->id, "sepa_mandate" => array("locale" => "de-DE", "bic" => "DEUTDEFF", "iban" => "DE89370400440532013000", "accountHolderName" => "Bob Holder", "billingAddress" => array("streetAddress" => "123 Currywurst Way", "extendedAddress" => "Lager Suite", "firstName" => "Wilhelm", "lastName" => "Dix", "locality" => "Frankfurt", "postalCode" => "60001", "countryCodeAlpha2" => "DE", "region" => "Hesse")))); $result = $gateway->paymentMethod()->create(array("customerId" => $customer->id, "paymentMethodNonce" => $nonce)); $this->assertTrue($result->success); $paymentMethod = $result->paymentMethod; $account = $gateway->paymentMethod()->find($paymentMethod->token); $this->assertEquals($paymentMethod->token, $account->token); $this->assertEquals($account->bic, "DEUTDEFF"); }
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); } } }
public function testDelete() { $paymentMethodToken = 'PAYPALToken-' . 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]); Braintree\PayPalAccount::delete($paymentMethodToken); $this->setExpectedException('Braintree\\Exception\\NotFound'); Braintree\PayPalAccount::find($paymentMethodToken); }
public function testFromNonce_ReturnsErrorWhenNonceIsConsumed() { $customer = Braintree\Customer::createNoValidate(); $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonce_for_new_card(array("credit_card" => array("number" => "4009348888881881", "expirationMonth" => "11", "expirationYear" => "2099"), "customerId" => $customer->id)); Braintree\CreditCard::fromNonce($nonce); $this->setExpectedException('Braintree\\Exception\\NotFound', "consumed"); Braintree\CreditCard::fromNonce($nonce); }
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); }
public function testHandlesEuropeBankAccounts() { $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'altpay_merchant', 'publicKey' => 'altpay_merchant_public_key', 'privateKey' => 'altpay_merchant_private_key']); $result = $gateway->customer()->create(); $this->assertTrue($result->success); $customer = $result->customer; $clientApi = new HttpClientApi($gateway->config); $nonce = $clientApi->nonceForNewEuropeanBankAccount(["customerId" => $customer->id, "sepa_mandate" => ["locale" => "de-DE", "bic" => "DEUTDEFF", "iban" => "DE89370400440532013000", "accountHolderName" => "Bob Holder", "billingAddress" => ["streetAddress" => "123 Currywurst Way", "extendedAddress" => "Lager Suite", "firstName" => "Wilhelm", "lastName" => "Dix", "locality" => "Frankfurt", "postalCode" => "60001", "countryCodeAlpha2" => "DE", "region" => "Hesse"]]]); $transactionResult = $gateway->transaction()->sale(["customerId" => $customer->id, "paymentMethodNonce" => $nonce, "merchantAccountId" => "fake_sepa_ma", "amount" => 100]); $this->assertTrue($transactionResult->success); $collection = $gateway->transaction()->search([Braintree\TransactionSearch::customerId()->is($customer->id), Braintree\TransactionSearch::europeBankAccountIban()->is("DE89370400440532013000")]); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($transactionResult->transaction->id, $collection->firstItem()->id); }
public function testDelete_worksWithPayPalAccounts() { $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand()); $customer = Braintree\Customer::createNoValidate(); $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken))); $paypalAccountResult = Braintree\PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce)); $this->assertTrue($paypalAccountResult->success); Braintree\PaymentMethod::delete($paymentMethodToken); $this->setExpectedException('Braintree\\Exception\\NotFound'); Braintree\PaymentMethod::find($paymentMethodToken); }
public function testUpdate_doesNotWorkWithOnetimePayPalNonce() { $customerResult = Braintree\Customer::create(['creditCard' => ['number' => '5105105105105100', 'expirationDate' => '05/12', 'options' => ['makeDefault' => true]]]); $paypalAccountToken = 'PAYPALToken-' . strval(rand()); $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['access_token' => 'PAYPAL_ACCESS_TOKEN', 'token' => $paypalAccountToken, 'options' => ['makeDefault' => true]]]); $result = Braintree\Customer::update($customerResult->customer->id, ['paymentMethodNonce' => $nonce]); $this->assertFalse($result->success); $errors = $result->errors->forKey('customer')->forKey('paypalAccount')->errors; $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_VAULT_ONE_TIME_USE_PAYPAL_ACCOUNT, $errors[0]->code); }
public function testCreate_withPayPalHandlesBadUnvalidatedNonces() { $http = new HttpClientApi(Braintree\Configuration::$global); $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['access_token' => 'PAYPAL_ACCESS_TOKEN', 'consent_code' => 'PAYPAL_CONSENT_CODE']]); $result = Braintree\Transaction::sale(['amount' => Braintree\Test\TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => true]]); $this->assertFalse($result->success); $errors = $result->errors->forKey('transaction')->forKey('paypalAccount')->errors; $this->assertEquals(Braintree\Error\Codes::PAYPAL_ACCOUNT_CANNOT_HAVE_BOTH_ACCESS_TOKEN_AND_CONSENT_CODE, $errors[0]->code); }