Skip to content

PurrProof/zen-payment-sdk

Repository files navigation

Zen Payment API skeleton

Overview

How to run tests

composer install
composer phpunit

Example

<?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";
}

README

What is implemented

  • Purchase:
    • CreateTransaction
    • GetTransactionByMerchantId
  • Refund:
    • CreateTransaction
  • Payout:
    • CreateTransaction

These endpoints are based on documentation examples. The API has not been tested in a real environment.

Code structure

  • 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.

Extending the SDK

To add a new endpoint:

  1. Create a new directory under src/Endpoints for the module.
  2. Add a class for the endpoint, implementing EndpointInterface.
  3. Update the client usage, e.g., $client->NewModule->NewAction([...]).

Next steps

  1. Real API Testing: Perform integration tests with a live or sandbox API environment.
  2. Stronger Validation: Implement typed objects for request and response data.
  3. Logging: Add robust error handling and logging mechanisms.
  4. More Endpoints: Expand the SDK to cover all supported API endpoints.

Features

Requirements

  • PHP 8.1+

Disclaimer

Use at your own risk!

Credits

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

About

No description, website, or topics provided.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.TEMPLATE

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages