Skip to content

Commit

Permalink
Add custom guzzle client configuration support (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Jan 4, 2024
1 parent e8d03bd commit 064c383
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Checkout/AbstractCheckoutSdkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class AbstractCheckoutSdkBuilder
public function __construct()
{
$this->environment = Environment::sandbox();
$this->httpClientBuilder = new DefaultHttpClientBuilder();
$this->httpClientBuilder = new DefaultHttpClientBuilder([]);
$this->setDefaultLogger();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Checkout/DefaultHttpClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ final class DefaultHttpClientBuilder implements HttpClientBuilderInterface

private $client;

public function __construct()
public function __construct($config)
{
$this->client = new GuzzleHttpClient();
$this->client = new GuzzleHttpClient($config);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Checkout\CheckoutException;
use Checkout\CheckoutSdk;
use Checkout\Common\DocumentType;
use Checkout\DefaultHttpClientBuilder;
use Checkout\Environment;
use Checkout\Issuing\Cardholders\CardholderDocument;
use Checkout\Issuing\Cardholders\CardholderRequest;
Expand Down Expand Up @@ -51,6 +52,10 @@ public function before()
*/
private function createIssuingApi()
{
$configClient = [
"timeout" => 60
];

return CheckoutSdk::builder()
->oAuth()
->clientCredentials(
Expand All @@ -63,6 +68,7 @@ private function createIssuingApi()
OAuthScope::$issuingControlsRead,
OAuthScope::$issuingControlsWrite])
->environment(Environment::sandbox())
->httpClientBuilder(new DefaultHttpClientBuilder($configClient))
->build();
}

Expand Down
17 changes: 14 additions & 3 deletions test/Checkout/Tests/SandboxTestFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Checkout\Common\Address;
use Checkout\Common\Country;
use Checkout\Common\Phone;
use Checkout\DefaultHttpClientBuilder;
use Checkout\Environment;
use Checkout\OAuthScope;
use Checkout\Payments\Payer;
Expand Down Expand Up @@ -47,6 +48,9 @@ abstract class SandboxTestFixture extends TestCase
*/
protected function init($platformType)
{
$configClient = [
"timeout" => 60
];
$this->logger = new Logger("checkout-sdk-test-php");
$this->logger->pushHandler(new StreamHandler("php://stderr"));
$this->logger->pushHandler(new StreamHandler("checkout-sdk-test-php.log"));
Expand All @@ -58,6 +62,7 @@ protected function init($platformType)
->environment(Environment::sandbox())
->publicKey(getenv("CHECKOUT_PREVIOUS_PUBLIC_KEY"))
->secretKey(getenv("CHECKOUT_PREVIOUS_SECRET_KEY"))
->httpClientBuilder(new DefaultHttpClientBuilder($configClient))
->logger($this->logger)
->build();
return;
Expand All @@ -66,18 +71,23 @@ protected function init($platformType)
->publicKey(getenv("CHECKOUT_DEFAULT_PUBLIC_KEY"))
->secretKey(getenv("CHECKOUT_DEFAULT_SECRET_KEY"))
->environment(Environment::sandbox())
->httpClientBuilder(new DefaultHttpClientBuilder($configClient))
->logger($this->logger)
->build();
return;
case PlatformType::$default_oauth:
$this->checkoutApi = CheckoutSdk::builder()->oAuth()
->clientCredentials(getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"), getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
->clientCredentials(
getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
getenv("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET")
)
->scopes([OAuthScope::$Files, OAuthScope::$Flow, OAuthScope::$Fx, OAuthScope::$Gateway,
OAuthScope::$Accounts, OAuthScope::$SessionsApp, OAuthScope::$SessionsBrowser,
OAuthScope::$Vault, OAuthScope::$PayoutsBankDetails, OAuthScope::$TransfersCreate,
OAuthScope::$TransfersView, OAuthScope::$BalancesView, OAuthScope::$VaultCardMetadata,
OAuthScope::$FinancialActions])
->environment(Environment::sandbox())
->httpClientBuilder(new DefaultHttpClientBuilder($configClient))
->logger($this->logger)
->build();
return;
Expand All @@ -101,7 +111,6 @@ protected function assertResponse($obj, ...$properties)
$joined = implode(".", array_slice($props, 1));
$this->assertResponse($testingObj, $joined);
} else {
//echo "\e[0;30;45massertResponse[property] testing=" . json_encode($property) . " found=" . json_encode($obj[$property]) . "\n";
$this->assertNotNull($obj[$property]);
$this->assertNotEmpty($obj[$property]);
}
Expand Down Expand Up @@ -191,7 +200,9 @@ protected function retriable(callable $func, callable $predicate = null, $timeou
return $response;
}
} catch (Exception $ex) {
$this->logger->warning("Request/Predicate failed with error '${ex}' - retry ${currentAttempt}/${maxAttempts}");
$this->logger->warning(
"Request/Predicate failed with error '$ex' - retry $currentAttempt/$maxAttempts"
);
}
$currentAttempt++;
sleep($timeout);
Expand Down

0 comments on commit 064c383

Please sign in to comment.