public function testGatewayGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
 {
     $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key']);
     $result = $gateway->settlementBatchSummary()->generate('2000-01-01');
     $this->assertTrue($result->success);
     $this->assertEquals(0, count($result->settlementBatchSummary->records));
 }
 public function testGateway_VersionDefaultsToTwo()
 {
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $encodedClientToken = $gateway->clientToken()->generate();
     $clientToken = base64_decode($encodedClientToken);
     $version = json_decode($clientToken)->version;
     $this->assertEquals(2, $version);
 }
Esempio n. 3
0
 public function testBadPaymentMethods()
 {
     $gateway = new Braintree\Gateway(array('clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret'));
     $result = $gateway->merchant()->create(array('email' => '*****@*****.**', 'countryCodeAlpha3' => 'USA', 'paymentMethods' => ['fake_money']));
     $this->assertEquals(false, $result->success);
     $errors = $result->errors->forKey('merchant')->onAttribute('paymentMethods');
     $this->assertEquals(Braintree\Error\Codes::MERCHANT_ACCOUNT_PAYMENT_METHODS_ARE_INVALID, $errors[0]->code);
 }
 public function testGateway_searchEmpty()
 {
     $query = array();
     $query[] = Braintree\CreditCardVerificationSearch::creditCardCardholderName()->is('Not Found');
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $collection = $gateway->creditCardVerification()->search($query);
     $this->assertEquals(0, $collection->maximumCount());
 }
Esempio n. 5
0
 /**
  * @expectedException Braintree\Exception\Configuration
  * @expectedExceptionMessage needs to be set (or accessToken needs to be passed to Braintree\Gateway).
  */
 public function testConfigGetsAssertedValid()
 {
     Braintree\Configuration::environment('development');
     //Braintree\Configuration::merchantId('integration_merchant_id');
     Braintree\Configuration::publicKey('integration_public_key');
     Braintree\Configuration::privateKey('integration_private_key');
     $gateway = new Braintree\Gateway(Braintree\Configuration::$global);
     $gateway->addOn();
 }
 public function testGatewayCreate()
 {
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $result = $gateway->merchantAccount()->create(self::$validParams);
     $this->assertEquals(true, $result->success);
     $merchantAccount = $result->merchantAccount;
     $this->assertEquals(Braintree\MerchantAccount::STATUS_PENDING, $merchantAccount->status);
     $this->assertEquals("sandbox_master_merchant_account", $merchantAccount->masterMerchantAccount->id);
 }
Esempio n. 7
0
 public function testCreateWithAccessToken()
 {
     $credentials = Test\Braintree\OAuthTestHelper::createCredentials(['clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret', 'merchantId' => 'integration_merchant_id']);
     $gateway = new Braintree\Gateway(['accessToken' => $credentials->accessToken]);
     $result = $gateway->customer()->create(['firstName' => 'Mike', 'lastName' => 'Jones']);
     $this->assertEquals(true, $result->success);
     $customer = $result->customer;
     $this->assertEquals('Mike', $customer->firstName);
     $this->assertEquals('Jones', $customer->lastName);
     $this->assertNotNull($customer->merchantId);
 }
 public function testGatewayCreate()
 {
     $customer = Braintree\Customer::createNoValidate();
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $result = $gateway->creditCard()->create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12'));
     $this->assertTrue($result->success);
     $this->assertEquals($customer->id, $result->creditCard->customerId);
     $this->assertEquals('510510', $result->creditCard->bin);
     $this->assertEquals('5100', $result->creditCard->last4);
     $this->assertEquals('Cardholder', $result->creditCard->cardholderName);
     $this->assertEquals('05/2012', $result->creditCard->expirationDate);
 }
Esempio n. 9
0
 public function testGatewayCreate()
 {
     $customer = Braintree\Customer::createNoValidate();
     $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key']);
     $result = $gateway->address()->create(['customerId' => $customer->id, 'streetAddress' => '1 E Main St', 'locality' => 'Chicago', 'region' => 'IL', 'postalCode' => '60622']);
     $this->assertTrue($result->success);
     $address = $result->address;
     $this->assertEquals('1 E Main St', $address->streetAddress);
     $this->assertEquals('Chicago', $address->locality);
     $this->assertEquals('IL', $address->region);
     $this->assertEquals('60622', $address->postalCode);
 }
 public function testGatewayCreate_fromVaultedCreditCardNonce()
 {
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonce_for_new_card(array('credit_card' => array('number' => '4111111111111111', 'expirationMonth' => '11', 'expirationYear' => '2099'), 'share' => true));
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $result = $gateway->paymentMethod()->create(array('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 testGatewayFind()
 {
     $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]);
     $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key']);
     $foundPayPalAccount = $gateway->paypalAccount()->find($paymentMethodToken);
     $this->assertSame('*****@*****.**', $foundPayPalAccount->email);
     $this->assertSame($paymentMethodToken, $foundPayPalAccount->token);
     $this->assertNotNull($foundPayPalAccount->imageUrl);
 }
 public function testGatewayCreate_whenSuccessful()
 {
     $creditCard = SubscriptionHelper::createCreditCard();
     $plan = SubscriptionHelper::triallessPlan();
     $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key']);
     $result = $gateway->subscription()->create(['paymentMethodToken' => $creditCard->token, 'planId' => $plan['id']]);
     Test\Helper::assertPrintable($result);
     $this->assertTrue($result->success);
     $subscription = $result->subscription;
     $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
     $this->assertEquals(0, $subscription->failureCount);
     $this->assertEquals($plan['id'], $subscription->planId);
     $this->assertEquals(Test\Helper::defaultMerchantAccountId(), $subscription->merchantAccountId);
     $this->assertEquals(Braintree\Subscription::ACTIVE, $subscription->status);
 }
 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");
 }
Esempio n. 14
0
 public function nonceForNewEuropeanBankAccount($options)
 {
     $clientTokenOptions = ['sepaMandateType' => 'business', 'sepaMandateAcceptanceLocation' => 'Rostock, Germany'];
     if (array_key_exists("customerId", $options)) {
         $clientTokenOptions["customerId"] = $options["customerId"];
         unset($options["customerId"]);
     }
     $gateway = new Braintree\Gateway($this->_config);
     $clientToken = json_decode(base64_decode($gateway->clientToken()->generate($clientTokenOptions)));
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $response = $this->post('/client_api/v1/sepa_mandates/', json_encode($options));
     if ($response["status"] == 201 || $response["status"] == 202) {
         $body = json_decode($response["body"]);
         return $body->europeBankAccounts[0]->nonce;
     } else {
         throw new Exception(var_dump($response));
     }
 }
 public function testGatewayCreateTransactionFromTransparentRedirect()
 {
     $params = array('transaction' => array('customer' => array('first_name' => 'First'), 'credit_card' => array('number' => '5105105105105100', 'expiration_date' => '05/12')));
     $trParams = array('transaction' => array('type' => Braintree\Transaction::SALE, 'amount' => '100.00'));
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $trData = $gateway->transparentRedirect()->transactionData(array_merge($trParams, array("redirectUrl" => "http://www.example.com")));
     $queryString = Test\Helper::submitTrRequest($gateway->transparentRedirect()->url(), $params, $trData);
     $result = $gateway->transparentRedirect()->confirm($queryString);
     $this->assertTrue($result->success);
     $this->assertEquals('100.00', $result->transaction->amount);
     $this->assertEquals(Braintree\Transaction::SALE, $result->transaction->type);
     $this->assertEquals(Braintree\Transaction::AUTHORIZED, $result->transaction->status);
     $creditCard = $result->transaction->creditCardDetails;
     $this->assertEquals('US', $creditCard->customerLocation);
     $this->assertEquals('05/2012', $creditCard->expirationDate);
     $this->assertEquals('510510******5100', $creditCard->maskedNumber);
     $customer = $result->transaction->customerDetails;
     $this->assertequals('First', $customer->firstName);
 }
Esempio n. 16
0
 public function testGatewayAll_returnsAllDiscounts()
 {
     $newId = strval(rand());
     $discountParams = array("amount" => "100.00", "description" => "some description", "id" => $newId, "kind" => "discount", "name" => "php_discount", "neverExpires" => "false", "numberOfBillingCycles" => "1");
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
     $http->post($path, array("modification" => $discountParams));
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $discounts = $gateway->discount()->all();
     foreach ($discounts as $discount) {
         if ($discount->id == $newId) {
             $actualDiscount = $discount;
         }
     }
     $this->assertNotNull($actualDiscount);
     $this->assertEquals($discountParams["amount"], $actualDiscount->amount);
     $this->assertEquals($discountParams["id"], $actualDiscount->id);
     $this->assertEquals($discountParams["kind"], $actualDiscount->kind);
 }
Esempio n. 17
0
 public function testGatewayAll_returnsAllAddOns()
 {
     $newId = strval(rand());
     $addOnParams = ["amount" => "100.00", "description" => "some description", "id" => $newId, "kind" => "add_on", "name" => "php_add_on", "neverExpires" => "false", "numberOfBillingCycles" => "1"];
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
     $http->post($path, ["modification" => $addOnParams]);
     $gateway = new Braintree\Gateway(['environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key']);
     $addOns = $gateway->addOn()->all();
     foreach ($addOns as $addOn) {
         if ($addOn->id == $newId) {
             $actualAddOn = $addOn;
         }
     }
     $this->assertNotNull($actualAddOn);
     $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
     $this->assertEquals($addOnParams["description"], $actualAddOn->description);
     $this->assertEquals($addOnParams["id"], $actualAddOn->id);
 }
Esempio n. 18
0
 public function testGatewayAll_returnsAllPlans()
 {
     $newId = strval(rand());
     $params = array("id" => $newId, "billingDayOfMonth" => "1", "billingFrequency" => "1", "currencyIsoCode" => "USD", "description" => "some description", "name" => "php test plan", "numberOfBillingCycles" => "1", "price" => "1.00", "trialPeriod" => "false");
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . '/plans/create_plan_for_tests';
     $http->post($path, array("plan" => $params));
     $gateway = new Braintree\Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $plans = $gateway->plan()->all();
     foreach ($plans as $plan) {
         if ($plan->id == $newId) {
             $actualPlan = $plan;
         }
     }
     $this->assertNotNull($actualPlan);
     $this->assertEquals($params["billingDayOfMonth"], $actualPlan->billingDayOfMonth);
     $this->assertEquals($params["billingFrequency"], $actualPlan->billingFrequency);
     $this->assertEquals($params["currencyIsoCode"], $actualPlan->currencyIsoCode);
     $this->assertEquals($params["description"], $actualPlan->description);
     $this->assertEquals($params["name"], $actualPlan->name);
     $this->assertEquals($params["numberOfBillingCycles"], $actualPlan->numberOfBillingCycles);
     $this->assertEquals($params["price"], $actualPlan->price);
 }
Esempio n. 19
0
 public function testTransactionsCanBeCreatedWithSharedParams()
 {
     $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;
     $address = $partnerMerchantGateway->address()->create(['customerId' => $customer->id, 'firstName' => 'Dan', 'lastName' => 'Smith'])->address;
     $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' => 'read_write,shared_vault_transactions']);
     $credentials = $oauthAppGateway->oauth()->createTokenFromCode(['code' => $code]);
     $oauthAccesTokenGateway = new Braintree\Gateway(['accessToken' => $credentials->accessToken]);
     $result = $oauthAccesTokenGateway->transaction()->sale(['amount' => '100.00', 'sharedPaymentMethodToken' => $creditCard->token, 'sharedCustomerId' => $customer->id, 'sharedShippingAddressId' => $address->id, 'sharedBillingAddressId' => $address->id]);
     $this->assertEquals($result->transaction->shippingDetails->firstName, $address->firstName);
     $this->assertEquals($result->transaction->billingDetails->firstName, $address->firstName);
 }
Esempio n. 20
0
 public function testComputeSignature()
 {
     $gateway = new Braintree\Gateway(array('clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret'));
     $urlToSign = 'http://localhost:3000/oauth/connect?business%5Bname%5D=We+Like+Spaces&client_id=client_id%24development%24integration_client_id';
     $signature = $gateway->oauth()->computeSignature($urlToSign);
     $this->assertEquals("a36bcf10dd982e2e47e0d6a2cb930aea47ade73f954b7d59c58dae6167894d41", $signature);
 }
Esempio n. 21
0
 public function testInvalidCurrencyForMultiCurrency()
 {
     $gateway = new Braintree\Gateway(['clientId' => 'client_id$development$signup_client_id', 'clientSecret' => 'client_secret$development$signup_client_secret']);
     $result = $gateway->merchant()->create(['email' => '*****@*****.**', 'countryCodeAlpha3' => 'USA', 'paymentMethods' => ['paypal'], 'currencies' => ['FAKE', 'USD'], 'paypalAccount' => ['clientId' => 'fake_client_id', 'clientSecret' => 'fake_client_secret']]);
     $this->assertEquals(false, $result->success);
     $errors = $result->errors->forKey('merchant')->onAttribute('currencies');
     $this->assertEquals(Braintree\Error\Codes::MERCHANT_CURRENCIES_ARE_INVALID, $errors[0]->code);
 }
 public function testCreateForCurrencyWithDuplicateId()
 {
     $gateway = new Braintree\Gateway(['clientId' => 'client_id$development$signup_client_id', 'clientSecret' => 'client_secret$development$signup_client_secret']);
     $result = $gateway->merchant()->create(['email' => '*****@*****.**', 'countryCodeAlpha3' => 'GBR', 'paymentMethods' => ['credit_card', 'paypal']]);
     $this->assertEquals(true, $result->success);
     $gateway = new Braintree\Gateway(['accessToken' => $result->credentials->accessToken]);
     $merchantAccount = $result->merchant->merchantAccounts[0];
     $result = $gateway->merchantAccount()->createForCurrency(['currency' => "USD", 'id' => $merchantAccount->id]);
     $this->assertEquals(false, $result->success);
     $errors = $result->errors->forKey('merchant')->onAttribute('id');
     $this->assertEquals(Braintree\Error\Codes::MERCHANT_MERCHANT_ACCOUNT_EXISTS_FOR_ID, $errors[0]->code);
 }
 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 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);
 }