paykit-php / paykit
Unified API for multiple payment gateways in PHP.
dev-main
2026-04-23 11:04 UTC
Requires
- php: ^8.3
- php-collective/dto: ^0.1.17
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- symfony/var-dumper: ^8.0
This package is auto-updated.
Last update: 2026-04-23 11:15:52 UTC
README
Paykit is a modular payment gateway abstraction library for PHP. It provides a consistent interface to interact with multiple payment providers while keeping vendor-specific behavior isolated in dedicated drivers.
Installation
composer require paykit-php/paykit composer require paykit-php/duitku
Basic Usage
use Paykit\Paykit; use Paykit\Duitku\DuitkuGateway; $paykit = new Paykit(); $paykit->register('duitku', function () { return new DuitkuGateway([ 'merchant_code' => 'your_merchant_code', 'api_key' => 'your_api_key', 'environment' => 'sandbox', ]); }); $gateway = $paykit->driver('duitku');
Get Payment Methods
$methods = $gateway->getMethods(10000); foreach ($methods->getItems() as $method) { echo $method->getCode(); echo $method->getName(); }
Create Payment
use Paykit\DTO\CreatePaymentDto; use Paykit\DTO\CustomerDto; use Paykit\DTO\UrlDto; $payment = $gateway->createPayment( new CreatePaymentDto( method: 'VC', amount: 10000, orderId: 'INV-001', customer: new CustomerDto( email: 'john@example.com', firstName: 'John' ), url: new UrlDto( callbackUrl: 'https://your-app.test/callback', successUrl: 'https://your-app.test/success', failedUrl: 'https://your-app.test/failed' ) ) );
Inquiry Payment
$payment = $gateway->inquiry('INV-001'); echo $payment->getStatus()->value;
Redirect Handling
Some providers return users via redirect (success or failed URL).
use Paykit\Contracts\Capabilities\SupportsRedirect; if ($gateway instanceof SupportsRedirect) { $payment = $gateway->handleRedirect($_GET); }
Callback Handling (Webhook)
use Paykit\Contracts\Capabilities\SupportsWebhook; $payload = json_decode(file_get_contents('php://input'), true); if ($gateway instanceof SupportsWebhook) { $payment = $gateway->handleCallback($payload); }
Payment Data
$payment->getOrderId(); $payment->getReferenceId(); $payment->getPaymentUrl(); $payment->getAmount(); $payment->getFee(); $payment->getStatus(); $details = $payment->getPayment(); $details?->getQris()?->getUrl(); $details?->getVirtualAccount()?->getNumber();
Notes
- Payment method codes must be used exactly as provided by each vendor.
- No normalization is applied to method codes.
- Only payment flow and status are standardized.
- Raw vendor response is always available via
$payment->getRaw().
License
MIT