checkout/checkout-sdk-php-beta

This package is abandoned and no longer maintained. No replacement package was suggested.

Checkout.com SDK for PHP

2.0.0-beta2 2022-02-09 16:41 UTC

README

This is a temporary development Checkout PHP SDK project that was archived and transferred to the official repository.

build-main GitHub license GitHub release Quality Gate Status

Getting started

Packages and sources are available from Packagist.

Composer

"require": {
    "php": ">=7.4",
    "checkout/checkout-sdk-php-beta": "version"
}

Please check in GitHub releases for all the versions available.

How to use the SDK

This SDK can be used with two different pair of API keys provided by Checkout. However, using different API keys imply using specific API features. Please find in the table below the types of keys that can be used within this SDK.

Account System Public Key (example) Secret Key (example)
default pk_g650ff27-7c42-4ce1-ae90-5691a188ee7b sk_gk3517a8-3z01-45fq-b4bd-4282384b0a64
Four pk_pkhpdtvabcf7hdgpwnbhw7r2uic sk_m73dzypy7cf3gf5d2xr4k7sxo4e

Note: sandbox keys have a test_ or sbox_ identifier, for Default and Four accounts respectively.

PLEASE NEVER SHARE OR PUBLISH YOUR CHECKOUT CREDENTIALS.

If you don't have your own API keys, you can sign up for a test account here.

Default

Default keys client instantiation can be done as follows:

$builder = CheckoutDefaultSdk::staticKeys();
$builder->setPublicKey("public_key");
$builder->setSecretKey("secret_key");
$builder->setEnvironment(Environment::sandbox()); // or production()
$builder->setHttpClientBuilder(); // optional, for a custom HTTP client
$defaultApi = $builder->build();

$paymentsClient = $defaultApi->getPaymentsClient();
$paymentsClient->refundPayment("payment_id");

Four

If your pair of keys matches the Four type, this is how the SDK should be used:

$builder = CheckoutFourSdk::staticKeys();
$builder->setPublicKey("public_key");
$builder->setSecretKey("secret_key");
$builder->setEnvironment(Environment::sandbox()); // or production()
$builder->setHttpClientBuilder(); // optional, for a custom HTTP client
$fourApi = $builder->build();

$paymentsClient = $fourApi->getPaymentsClient();
$paymentsClient->refundPayment("payment_id");

The SDK supports client credentials OAuth, when initialized as follows:

$builder = CheckoutFourSdk::oAuth();
$builder->clientCredentials("client_id", "client_secret");
$builder->scopes([FourOAuthScope::$Files, FourOAuthScope::$Flow]); // array of scopes
$builder->setEnvironment(Environment::sandbox()); // or production()
$builder->setHttpClientBuilder(); // optional, for a custom HTTP client
$fourApi = $builder->build();

$paymentsClient = $fourApi->getPaymentsClient();
$paymentsClient->refundPayment("payment_id");

PHP Settings

For operations that require file upload (Disputes or Marketplace) the configuration extension=fileinfo must be enabled in the php.ini.

Exception handling

All the API responses that do not fall in the 2** status codes will cause a CheckoutApiException. The exception encapsulates the requestId, httpStatusCode and a map of errorDetails, if available.

More documentation related to Checkout API and the SDK is available at:

Building from source

Once you checkout the code from GitHub, the project can be built using composer:

composer update

The execution of integration tests require the following environment variables set in your system:

  • For Default account systems: CHECKOUT_PUBLIC_KEY & CHECKOUT_SECRET_KEY
  • For Four account systems: CHECKOUT_FOUR_PUBLIC_KEY & CHECKOUT_FOUR_SECRET_KEY
  • For Four account systems (OAuth): CHECKOUT_FOUR_OAUTH_CLIENT_ID & CHECKOUT_FOUR_OAUTH_CLIENT_SECRET

Code of Conduct

Please refer to Code of Conduct

Licensing

MIT