public static function createCredentials($params) { $gateway = new Braintree_Gateway(array('clientId' => $params['clientId'], 'clientSecret' => $params['clientSecret'])); $code = Braintree_OAuthTestHelper::createGrant($gateway, array('merchant_public_id' => $params['merchantId'], 'scope' => 'read_write')); $credentials = $gateway->oauth()->createTokenFromCode(array('code' => $code, 'scope' => 'read_write')); return $credentials; }
function testCreateWithAccessToken() { $credentials = Braintree_OAuthTestHelper::createCredentials(array('clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret', 'merchantId' => 'integration_merchant_id')); $gateway = new Braintree_Gateway(array('accessToken' => $credentials->accessToken)); $result = $gateway->customer()->create(array('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); }
function testCreateTokenFromRefreshToken() { $gateway = new Braintree_Gateway(array('clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret')); $code = Braintree_OAuthTestHelper::createGrant($gateway, array('merchant_public_id' => 'integration_merchant_id', 'scope' => 'read_write')); $refreshToken = $gateway->oauth()->createTokenFromCode(array('code' => $code, 'scope' => 'read_write'))->refreshToken; $result = $gateway->oauth()->createTokenFromRefreshToken(array('refreshToken' => $refreshToken, 'scope' => 'read_write')); $this->assertEquals(true, $result->success); $this->assertNotNull($result->accessToken); $this->assertNotNull($result->refreshToken); $this->assertEquals('bearer', $result->tokenType); $this->assertNotNull($result->expiresAt); }
function testSaleWithAccessToken() { $credentials = Braintree_OAuthTestHelper::createCredentials(array('clientId' => 'client_id$development$integration_client_id', 'clientSecret' => 'client_secret$development$integration_client_secret', 'merchantId' => 'integration_merchant_id')); $gateway = new Braintree_Gateway(array('accessToken' => $credentials->accessToken)); $result = $gateway->transaction()->sale(array('amount' => '100.00', 'creditCard' => array('cardholderName' => 'The Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12'))); $this->assertTrue($result->success); $transaction = $result->transaction; $this->assertEquals(Braintree_Transaction::AUTHORIZED, $transaction->status); $this->assertEquals(Braintree_Transaction::SALE, $transaction->type); $this->assertEquals('100.00', $transaction->amount); $this->assertNotNull($transaction->processorAuthorizationCode); $this->assertEquals('510510', $transaction->creditCardDetails->bin); $this->assertEquals('5100', $transaction->creditCardDetails->last4); $this->assertEquals('The Cardholder', $transaction->creditCardDetails->cardholderName); }