Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guzzle client configuration support #231

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading