composer install
composer phpunit<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
use ZenPayments\Config\ZenConfig;
use ZenPayments\ZenClient;
use ZenPayments\Exceptions\ApiException;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
$dotenv->required(['ZEN_API_BASE_URL', 'ZEN_API_KEY'])->notEmpty();
$config = new ZenConfig();
$client = new ZenClient($config);
try {
// create purschase tx
$purchaseResp = $client->Purchase->CreateTransaction([
'merchantTransactionId' => 'merchant-abc',
'amount' => '100.00',
'currency' => 'PLN'
]);
$data = $purchaseResp->getData();
echo "Created purchase ID: {$data['id']}, status: {$data['status']}\n";
// get purchase tx status
$statusResp = $client->Purchase->GetTransactionByMerchantId([
'merchantTransactionId' => 'merchant-abc'
]);
$statusData = $statusResp->getData();
echo "Purchase status: {$statusData['status']}\n";
// create refund tx
$refundResp = $client->Refund->CreateTransaction([
'transactionId' => 'orig-xyz',
'amount' => '50.00',
'currency' => 'PLN',
'merchantTransactionId' => 'refund-111'
]);
$refundData = $refundResp->getData();
echo "Refund ID: {$refundData['id']}, status: {$refundData['status']}\n";
// create payout tx
$payoutResp = $client->Payout->CreateTransaction([
'merchantTransactionId' => 'payout-xyz',
'paymentChannel' => 'PCL_CARD',
'amount' => '50.00',
'currency' => 'PLN'
]);
$payoutData = $payoutResp->getData();
echo "Payout ID: {$payoutData['id']}, status: {$payoutData['status']}\n";
} catch (ApiException $e) {
echo "API Error: " . $e->getMessage() . "\n";
}- Purchase:
CreateTransactionGetTransactionByMerchantId
- Refund:
CreateTransaction
- Payout:
CreateTransaction
These endpoints are based on documentation examples. The API has not been tested in a real environment.
src/ZenClient.php: Entry point for the SDK. Allows chaining like$client->Purchase->CreateTransaction([...]).src/Endpoints/*: Contains endpoint classes for specific API sections (e.g.,Purchase,Refund,Payout).src/Base: Includes shared base classes for requests (BaseRequest) and responses (BaseResponse).src/Factories: Handles dynamic creation of endpoint and request instances.tests/: Includes basic unit tests with mock responses.
To add a new endpoint:
- Create a new directory under
src/Endpointsfor the module. - Add a class for the endpoint, implementing
EndpointInterface. - Update the client usage, e.g.,
$client->NewModule->NewAction([...]).
- Real API Testing: Perform integration tests with a live or sandbox API environment.
- Stronger Validation: Implement typed objects for request and response data.
- Logging: Add robust error handling and logging mechanisms.
- More Endpoints: Expand the SDK to cover all supported API endpoints.
- Composer dependency management
- PHPUnit unit tests
- PHPStan static analysis
- PHPCS coding standard analyzer
- PHPMD mess detector
- Codecov code coverage analysis
- phpDocumentor auto generated API docs
- PHP 8.1+
Use at your own risk!
Based on the template/boilerplate for PHP libraries (similar to chillerlan/php-library-template but without phpdocs and readthedocs deployment). Template's license is MIT (C) chillerlan, see LICENSE.INITIAL