Skip to content
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
25 changes: 21 additions & 4 deletions .github/scripts/phpunit-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,30 @@
$REMOVE_PHPSTAN
composer update --no-interaction --no-progress --no-scripts --no-plugins"

# Only the variable names are listed here; docker reads the values from this environment.
# Only the variables the workflows set are passed, and only when set; docker reads the values
# from this environment. Any other CHECKOUT_* variable of the calling shell stays out.
ENV_ARGS=()
for name in $(compgen -e | grep '^CHECKOUT_' || true); do
ENV_ARGS+=(-e "$name")
for name in \
CHECKOUT_PROCESSING_CHANNEL_ID \
CHECKOUT_PREVIOUS_SECRET_KEY \
CHECKOUT_PREVIOUS_PUBLIC_KEY \
CHECKOUT_DEFAULT_SECRET_KEY \
CHECKOUT_DEFAULT_PUBLIC_KEY \
CHECKOUT_DEFAULT_OAUTH_CLIENT_ID \
CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET \
CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID \
CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET \
CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID \
CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET \
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID \
CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET \
CHECKOUT_MERCHANT_SUBDOMAIN; do
if [ -n "${!name+set}" ]; then

Check failure on line 54 in .github/scripts/phpunit-in-docker.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=checkout_checkout-sdk-php&issues=AaI7akYXxXlkvLEBUa9a&open=AaI7akYXxXlkvLEBUa9a&pullRequest=431
ENV_ARGS+=(-e "$name")
fi
done

docker run --rm -u "$(id -u):$(id -g)" "${ENV_ARGS[@]}" -v "$PWD":/app -w /app "$PHP_IMAGE" sh -c "
docker run --rm -u "$(id -u):$(id -g)" ${ENV_ARGS[@]+"${ENV_ARGS[@]}"} -v "$PWD":/app -w /app "$PHP_IMAGE" sh -c "
php -v &&
if [ -x vendor/bin/phpstan ]; then vendor/bin/phpstan analyse --no-progress --memory-limit=1G; fi &&
vendor/bin/phpunit --verbose"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ A `cURL error 60` means PHP cannot find a CA bundle that trusts the API certific

All the API responses that do not fall in the 2** status codes, the SDK will throw a `CheckoutApiException`.

The exception encapsulates `http_metadata` and `$error_details`, if available.
The exception encapsulates `http_metadata` (status, reason phrase and response headers, cookies excluded) and `$error_details`, if available.

A request argument that cannot be sent as given (for example an empty id, or a query filter value that is not a string, number, boolean or `DateTime`) throws a `CheckoutArgumentException` before any request is sent. Both exceptions extend `CheckoutException`: catch `CheckoutException` to handle the two.

Expand Down
35 changes: 27 additions & 8 deletions lib/Checkout/AbstractStaticKeysCheckoutSdkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ abstract class AbstractStaticKeysCheckoutSdkBuilder extends AbstractCheckoutSdkB
protected $secretKey = null;

/**
* @param string $key
* @param string|object $key the secret key, a string or an object with __toString
* @param string $secretKeyPattern
* @throws CheckoutArgumentException
* @throws CheckoutArgumentException when the key is not text or does not match the pattern
*/
protected function validateSecretKey($key, $secretKeyPattern)
{
if ($this->validKey($secretKeyPattern, $key)) {
protected function validateSecretKey(
#[\SensitiveParameter]
$key,
$secretKeyPattern
) {
$isText = is_string($key) || (is_object($key) && method_exists($key, "__toString"));
if ($isText && $this->validKey($secretKeyPattern, (string)$key)) {
return;
}
throw new CheckoutArgumentException("invalid secret key");
Expand All @@ -37,12 +41,27 @@ protected function validatePublicKey($key, $publicKeyPattern)
throw new CheckoutArgumentException("invalid public key");
}

private function validKey($pattern, $key)
{
/**
* @param string $pattern
* @param string $key
* @return int|false 1 when the key matches the pattern
*/
private function validKey(
$pattern,
#[\SensitiveParameter]
$key
) {
return preg_match($pattern, $key);
}

abstract protected function publicKey($publicKey);

abstract protected function secretKey($secretKey);
/**
* @param string|object $secretKey the secret key, a string or an object with __toString
* @return $this
*/
abstract protected function secretKey(
#[\SensitiveParameter]
$secretKey
);
}
7 changes: 5 additions & 2 deletions lib/Checkout/AbstractStaticKeysSdkCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ abstract class AbstractStaticKeysSdkCredentials implements SdkCredentialsInterfa
* @param string|null $secretKey
* @param string|null $publicKey
*/
public function __construct($secretKey, $publicKey)
{
public function __construct(
#[\SensitiveParameter]
$secretKey,
$publicKey
) {
$this->publicKey = $publicKey;
$this->secretKey = $secretKey;
}
Expand Down
Loading
Loading