PHP code example of codearachnid / check-commerce-php-sdk
1. Go to this page and download the library: Download codearachnid/check-commerce-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codearachnid / check-commerce-php-sdk example snippets
use CheckCommerce\CheckCommerceClient;
$client = new CheckCommerceClient([
'api_key' => getenv('CHECK_COMMERCE_API_KEY'),
'merchant_number' => getenv('CHECK_COMMERCE_MERCHANT_NUMBER'),
'environment' => 'sandbox',
]);
// The API ame' => 'Jane Doe',
'bankAccountNumber' => '1234567890',
'bankRoutingNumber' => 121000248,
],
]);
echo $result->transactionId; // 123456789
echo $result->status->value; // "Processed"
// Reads CHECK_COMMERCE_API_KEY, CHECK_COMMERCE_MERCHANT_NUMBER, and
// CHECK_COMMERCE_ENVIRONMENT ("production" or "sandbox", default production).
$client = CheckCommerceClient::fromEnv();
// Anything not in the environment can be passed as an override:
$client = CheckCommerceClient::fromEnv(['timeout' => 60, 'max_retries' => 3]);
use CheckCommerce\CheckCommerceClient;
use CheckCommerce\Environment;
use CheckCommerce\Scope;
$client = new CheckCommerceClient([
'api_key' => getenv('CHECK_COMMERCE_API_KEY'),
'merchant_number' => getenv('CHECK_COMMERCE_MERCHANT_NUMBER'),
'environment' => Environment::Sandbox,
'scopes' => [Scope::Transactions, Scope::HostedPages],
'timeout' => 30,
'max_retries' => 2,
]);
use CheckCommerce\Auth\AccessToken;
use CheckCommerce\Auth\TokenStoreInterface;
final class CacheTokenStore implements TokenStoreInterface
{
public function __construct(private \Psr\SimpleCache\CacheInterface $cache) {}
public function get(string $key): ?AccessToken
{
$data = $this->cache->get($key);
return is_array($data) ? AccessToken::fromArray($data) : null;
}
public function put(string $key, AccessToken $token): void
{
$this->cache->set($key, $token->toArray());
}
public function forget(string $key): void
{
$this->cache->delete($key);
}
}
$client = new CheckCommerceClient($config, tokenStore: new CacheTokenStore($cache));
use CheckCommerce\Enums\PaymentType;
use CheckCommerce\Enums\TransactionType;
$mid = $client->config->merchantNumber; // as configured (e.g. from CHECK_COMMERCE_MERCHANT_NUMBER)
// Sugar for the common operations — sets transactionType for you:
$client->transactions->debit([...]);
$client->transactions->credit([...]);
$client->transactions->void(['merchantNumber' => $mid, 'originalTransaction' => ['transactionId' => 123456789]]);
$client->transactions->refund(['merchantNumber' => $mid, 'originalTransaction' => ['referenceNumber' => 'INV-1001']]);
// Full control — any transaction type, any payment rail:
$client->transactions->create(
['merchantNumber' => $mid, 'transactionType' => TransactionType::Prenote, /* ... */],
PaymentType::Rtp,
);
// Status lookups:
$status = $client->transactions->status(transactionId: 123456789);
$status = $client->transactions->status(referenceNumber: 'INV-1001', requestType: PaymentType::Ach);
$auth = $client->transactions->authStatus(transactionId: 123456789);
if ($status->isDeclined()) {
echo $status->processingFailure?->detail; // "Threshold Exceeded"
}