aliziodev / payid-midtrans
Midtrans driver for PayID — Laravel Payment Orchestrator
v0.1.0
2026-04-13 02:56 UTC
Requires
- php: ^8.2
- aliziodev/midtrans-php: ^1.0
- aliziodev/payid: ^0.1
- illuminate/contracts: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpstan/phpstan: ^2.0
README
Driver Midtrans untuk aliziodev/payid.
Package ini menyediakan integrasi Midtrans dengan API PayID yang konsisten untuk flow:
- Snap charge
- Core API direct charge
- status / cancel / expire / refund / approve / deny
- subscription lifecycle
- webhook verification + parsing
- GoPay account linking
Requirements
- PHP 8.2+
- Laravel 11 / 12 / 13
aliziodev/payid^0.1
Instalasi
composer require aliziodev/payid composer require aliziodev/payid-midtrans
Konfigurasi
Tambahkan kredensial Midtrans pada konfigurasi driver payid.
Contoh di config/payid.php:
'drivers' => [ 'midtrans' => [ 'driver' => 'midtrans', 'environment' => env('MIDTRANS_ENV', 'sandbox'), 'server_key' => env('MIDTRANS_SERVER_KEY'), 'client_key' => env('MIDTRANS_CLIENT_KEY'), 'merchant_id' => env('MIDTRANS_MERCHANT_ID'), 'timeout' => 30, 'retry_times' => 1, 'endpoints' => [ // Optional override 'snap_base_url' => env('MIDTRANS_SNAP_BASE_URL'), 'core_base_url' => env('MIDTRANS_CORE_BASE_URL'), 'subscription_base_url' => env('MIDTRANS_SUBSCRIPTION_BASE_URL'), ], 'webhook' => [ 'replay_protection' => true, 'replay_ttl_seconds' => 3600, 'cache_store' => null, ], ], ],
Contoh .env:
PAYID_DEFAULT_DRIVER=midtrans MIDTRANS_ENV=sandbox MIDTRANS_SERVER_KEY=SB-Mid-server-xxxx MIDTRANS_CLIENT_KEY=SB-Mid-client-xxxx MIDTRANS_MERCHANT_ID=Gxxxxxxxx
Endpoint Mapping
- Snap API
POST /snap/v1/transactions
- Core API v2
POST /v2/chargeGET /v2/{id}/statusPOST /v2/{id}/cancelPOST /v2/{id}/expirePOST /v2/{id}/refundPOST /v2/{id}/approvePOST /v2/{id}/denyPOST /v2/pay/accountGET /v2/pay/account/{account_id}POST /v2/pay/account/{account_id}/unbind
- Subscription API v1
POST /v1/subscriptionsGET /v1/subscriptions/{subscription_id}PATCH /v1/subscriptions/{subscription_id}POST /v1/subscriptions/{subscription_id}/disablePOST /v1/subscriptions/{subscription_id}/enablePOST /v1/subscriptions/{subscription_id}/cancel
Penggunaan
Charge (Snap)
use Aliziodev\PayId\DTO\ChargeRequest; use Aliziodev\PayId\Enums\PaymentChannel; use Illuminate\Support\Facades\PayId; $response = PayId::charge(ChargeRequest::make([ 'merchant_order_id' => 'ORDER-1001', 'amount' => 150000, 'currency' => 'IDR', 'channel' => PaymentChannel::Qris, ]));
Direct Charge (Core API)
$response = PayId::directCharge(ChargeRequest::make([ 'merchant_order_id' => 'ORDER-1002', 'amount' => 200000, 'currency' => 'IDR', 'channel' => PaymentChannel::VaBca, ]));
Status / Refund
$status = PayId::status('ORDER-1001'); $refund = PayId::refund(\Aliziodev\PayId\DTO\RefundRequest::make([ 'merchant_order_id' => 'ORDER-1001', 'amount' => 50000, 'reason' => 'Customer request', ]));
Subscription
$created = PayId::createSubscription(\Aliziodev\PayId\DTO\SubscriptionRequest::make([ 'subscription_id' => 'SUB-1001', 'name' => 'MONTHLY_PLAN', 'amount' => 99000, 'token' => 'saved_token_id_or_gopay_token', 'interval' => 'month', 'interval_count' => 1, ])); $paused = PayId::pauseSubscription($created->providerSubscriptionId); $resumed = PayId::resumeSubscription($created->providerSubscriptionId); $canceled = PayId::cancelSubscription($created->providerSubscriptionId);
Webhook
- Signature diverifikasi dengan formula resmi Midtrans:
SHA512(order_id + status_code + gross_amount + server_key)
- Replay protection tersedia via cache fingerprint.
Dokumen operasional:
docs/webhook-replay-protection.mddocs/webhook-incident-runbook.md
Kesiapan Saat Ini
Audit sinkronisasi API Midtrans terbaru sudah dilakukan per 2026-04-13.
Lihat detail:
docs/api-compatibility-audit-2026-04-13.mddocs/release-readiness-checklist.md
Quality Gates
composer test
composer analyse
composer lint-check
Lisensi
MIT