예제 #1
0
 function testFind_exposesNullThreeDSecureInfoIfNoneExists()
 {
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099")));
     $foundNonce = Braintree_PaymentMethodNonce::find($nonce);
     $info = $foundNonce->threeDSecureInfo;
     $this->assertEquals($nonce, $foundNonce->nonce);
     $this->assertNull($info);
 }
 function test_paypalAccountEmail()
 {
     $http = new Braintree_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);
 }
 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 Braintree_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");
 }
예제 #4
0
 function testCreateCustomerWithCardUsingNonce()
 {
     $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true));
     $result = Braintree_Customer::create(array('creditCard' => array('paymentMethodNonce' => $nonce)));
     $this->assertTrue($result->success);
     $this->assertSame("411111", $result->customer->creditCards[0]->bin);
     $this->assertSame("1111", $result->customer->creditCards[0]->last4);
 }
예제 #5
0
 function testCreateTransactionUsingNonce()
 {
     $nonce = Braintree_HttpClientApi::nonce_for_new_card(array("creditCard" => array("number" => "4111111111111111", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true));
     $result = Braintree_Transaction::sale(array('amount' => '47.00', 'paymentMethodNonce' => $nonce));
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status);
     $this->assertEquals(Braintree_Transaction::SALE, $transaction->type);
     $this->assertEquals('47.00', $transaction->amount);
 }
예제 #6
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_TestHelper::decodedClientToken(array("customerId" => $customerId, "options" => array("makeDefault" => true)));
     $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
     $http = new Braintree_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);
         }
     }
 }
예제 #7
0
 public static function nonceForPayPalAccount($options)
 {
     $clientToken = json_decode(Braintree_TestHelper::decodedClientToken());
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $response = Braintree_HttpClientApi::post('/client_api/v1/payment_methods/paypal_accounts.json', json_encode($options));
     if ($response["status"] == 201 || $response["status"] == 202) {
         $body = json_decode($response["body"], true);
         return $body["paypalAccounts"][0]["nonce"];
     } else {
         throw new Exception(var_dump($response));
     }
 }
예제 #8
0
 public static function nonce_for_new_card($options)
 {
     $clientTokenOptions = array();
     if (array_key_exists("customerId", $options)) {
         $clientTokenOptions["customerId"] = $options["customerId"];
         unset($options["customerId"]);
     }
     $clientToken = json_decode(Braintree_ClientToken::generate($clientTokenOptions));
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $options["shared_customer_identifier"] = "fake_identifier_" . rand();
     $options["shared_customer_identifier_type"] = "testing";
     $response = Braintree_HttpClientApi::post('/client_api/nonces.json', json_encode($options));
     if ($response["status"] != 201) {
         throw new Exception(var_dump($response));
     } else {
         $body = json_decode($response["body"]);
         return $body->nonce;
     }
 }
예제 #9
0
 function testFromNonce_ReturnsErrorWhenNonceIsConsumed()
 {
     $customer = Braintree_Customer::createNoValidate();
     $http = new Braintree_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);
 }
예제 #10
0
 function testUpdate_doesNotWorkWithOnetimePayPalNonce()
 {
     $customerResult = Braintree_Customer::create(array('creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12', 'options' => array('makeDefault' => true))));
     $paypalAccountToken = 'PAYPALToken-' . strval(rand());
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('access_token' => 'PAYPAL_ACCESS_TOKEN', 'token' => $paypalAccountToken, 'options' => array('makeDefault' => true))));
     $result = Braintree_Customer::update($customerResult->customer->id, array('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);
 }
 function testDelete_worksWithPayPalAccounts()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $customer = Braintree_Customer::createNoValidate();
     $nonce = Braintree_HttpClientApi::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);
 }
 function testHandlesEuropeBankAccounts()
 {
     $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 Braintree_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"))));
     $transactionResult = $gateway->transaction()->sale(array("customerId" => $customer->id, "paymentMethodNonce" => $nonce, "merchantAccountId" => "fake_sepa_ma", "amount" => 100));
     $this->assertTrue($transactionResult->success);
     $collection = $gateway->transaction()->search(array(Braintree_TransactionSearch::customerId()->is($customer->id), Braintree_TransactionSearch::europeBankAccountIban()->is("DE89370400440532013000")));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($transactionResult->transaction->id, $collection->firstItem()->id);
 }
 function testHandlesPayPalAccounts()
 {
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('access_token' => 'PAYPAL_ACCESS_TOKEN')));
     $result = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce));
     $this->assertTrue($result->success);
     $paypalDetails = $result->transaction->paypalDetails;
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::paypalPaymentId()->is($paypalDetails->paymentId), Braintree_TransactionSearch::paypalAuthorizationId()->is($paypalDetails->authorizationId), Braintree_TransactionSearch::paypalPayerEmail()->is($paypalDetails->payerEmail)));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($result->transaction->id, $collection->firstItem()->id);
 }
예제 #14
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);
 }
 function testCreate_withPayPalHandlesBadUnvalidatedNonces()
 {
     $nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('access_token' => 'PAYPAL_ACCESS_TOKEN', 'consent_code' => 'PAYPAL_CONSENT_CODE')));
     $result = Braintree_Transaction::sale(array('amount' => Braintree_Test_TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce, 'options' => array('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);
 }
예제 #16
0
 function testFromNonce_ReturnsErrorWhenNonceIsLocked()
 {
     $customer = Braintree_Customer::createNoValidate();
     $clientTokenOptions = array();
     $clientToken = json_decode(Braintree_TestHelper::decodedClientToken($clientTokenOptions));
     $sharedCustomerIdentifier = "fake_identifier_" . rand();
     $options = array("credit_card" => array("number" => "4009348888881881", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true);
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $options["shared_customer_identifier"] = $sharedCustomerIdentifier;
     $options["shared_customer_identifier_type"] = "testing";
     $response = Braintree_HttpClientApi::post('/client_api/v1/payment_methods/credit_cards.json', json_encode($options));
     $this->assertEquals(201, $response["status"]);
     unset($options["credit_card"]);
     $response = Braintree_HttpClientApi::get_cards($options);
     $body = json_decode($response["body"]);
     $nonce = $body->paymentMethods[0]->nonce;
     $this->setExpectedException('Braintree_Exception_NotFound', "locked");
     Braintree_CreditCard::fromNonce($nonce);
 }
예제 #17
0
 function testDelete()
 {
     $paymentMethodToken = 'PAYPALToken-' . strval(rand());
     $customer = Braintree_Customer::createNoValidate();
     $http = new Braintree_HttpClientApi(Braintree_Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken)));
     Braintree_PaymentMethod::create(array('customerId' => $customer->id, 'paymentMethodNonce' => $nonce));
     Braintree_PayPalAccount::delete($paymentMethodToken);
     $this->setExpectedException('Braintree_Exception_NotFound');
     Braintree_PayPalAccount::find($paymentMethodToken);
 }