OAuthTestHelper.php 922 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Test\Braintree;
  3. use Braintree;
  4. class OAuthTestHelper
  5. {
  6. public static function createGrant($gateway, $params)
  7. {
  8. $http = new Braintree\Http($gateway->config);
  9. $http->useClientCredentials();
  10. $response = $http->post('/oauth_testing/grants', ['grant' => $params]);
  11. return $response['grant']['code'];
  12. }
  13. public static function createCredentials($params)
  14. {
  15. $gateway = new Braintree\Gateway([
  16. 'clientId' => $params['clientId'],
  17. 'clientSecret' => $params['clientSecret']
  18. ]);
  19. $code = OAuthTestHelper::createGrant($gateway, [
  20. 'merchant_public_id' => $params['merchantId'],
  21. 'scope' => 'read_write'
  22. ]);
  23. $credentials = $gateway->oauth()->createTokenFromCode([
  24. 'code' => $code,
  25. 'scope' => 'read_write',
  26. ]);
  27. return $credentials;
  28. }
  29. }