public function testAuthorizationWithConfig() { $config = new Braintree\Configuration(['environment' => 'development', 'merchant_id' => 'integration_merchant_id', 'publicKey' => 'badPublicKey', 'privateKey' => 'badPrivateKey']); $http = new Braintree\Http($config); $result = $http->_doUrlRequest('GET', $config->baseUrl() . '/merchants/integration_merchant_id/customers'); $this->assertEquals(401, $result['status']); }
public static function createGrant($gateway, $params) { $http = new Braintree\Http($gateway->config); $http->useClientCredentials(); $response = $http->post('/oauth_testing/grants', array('grant' => $params)); return $response['grant']['code']; }
public function testLoggingDuration() { $logger = new CurlAuditLogger(); $config = new Braintree\Configuration(['environment' => 'development', 'merchant_id' => 'integration_merchant_id', 'publicKey' => 'badPublicKey', 'privateKey' => 'badPrivateKey', 'logger' => $logger]); $http = new Braintree\Http($config); $http->_doUrlRequest('GET', $config->baseUrl() . '/merchants/integration_merchant_id/customers'); $this->assertLessThanOrEqual(1, $logger->getDuration()); }
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); }
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); }
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); }
public function testSearch_daysPastDue() { $creditCard = SubscriptionHelper::createCreditCard(); $triallessPlan = SubscriptionHelper::triallessPlan(); $subscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id']])->subscription; $http = new Braintree\Http(Braintree\Configuration::$global); $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due'; $http->put($path, ['daysPastDue' => 5]); $found = false; $collection = Braintree\Subscription::search([Braintree\SubscriptionSearch::daysPastDue()->between(2, 10)]); foreach ($collection as $item) { $found = true; $this->assertTrue($item->daysPastDue <= 10); $this->assertTrue($item->daysPastDue >= 2); } $this->assertTrue($found); }
/** * sends the create request to the gateway * @ignore * @param string $subPath * @param array $params * @return mixed */ private function _doCreate($subPath, $params) { $fullPath = $this->_config->merchantPath() . $subPath; $response = $this->_http->post($fullPath, $params); return $this->_verifyGatewayResponse($response); }
public static function create3DSVerification($merchantAccountId, $params) { $http = new Braintree\Http(Braintree\Configuration::$global); $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_verification/' . $merchantAccountId; $response = $http->post($path, array('threeDSecureVerification' => $params)); return $response['threeDSecureVerification']['threeDSecureToken']; }
public function testRetryCharge_WithAmount() { $subscription = SubscriptionHelper::createSubscription(); $http = new Braintree\Http(Braintree\Configuration::$global); $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due'; $http->put($path); $result = Braintree\Subscription::retryCharge($subscription->id, 1000); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals(1000, $transaction->amount); $this->assertNotNull($transaction->processorAuthorizationCode); $this->assertEquals(Braintree\Transaction::SALE, $transaction->type); $this->assertEquals(Braintree\Transaction::AUTHORIZED, $transaction->status); }
public function test_rangeNode_settledAt() { $transaction = Braintree\Transaction::saleNoValidate(['amount' => '1000.00', 'creditCard' => ['number' => '4111111111111111', 'expirationDate' => '05/12'], 'options' => ['submitForSettlement' => true]]); $http = new Braintree\Http(Braintree\Configuration::$global); $path = Braintree\Configuration::$global->merchantPath() . '/transactions/' . $transaction->id . '/settle'; $http->put($path); $transaction = Braintree\Transaction::find($transaction->id); $twenty_min_ago = date_create("now -20 minutes", new DateTimeZone("UTC")); $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC")); $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC")); $collection = Braintree\Transaction::search([Braintree\TransactionSearch::id()->is($transaction->id), Braintree\TransactionSearch::settledAt()->between($twenty_min_ago, $ten_min_ago)]); $this->assertEquals(0, $collection->maximumCount()); $collection = Braintree\Transaction::search([Braintree\TransactionSearch::id()->is($transaction->id), Braintree\TransactionSearch::settledAt()->between($ten_min_ago, $ten_min_from_now)]); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($transaction->id, $collection->firstItem()->id); }
public static function generate3DSNonce($params) { $http = new Braintree\Http(Braintree\Configuration::$global); $path = Braintree\Configuration::$global->merchantPath() . '/three_d_secure/create_nonce/' . self::threeDSecureMerchantAccountId(); $response = $http->post($path, $params); return $response['paymentMethodNonce']['nonce']; }