PHPackages                             anggit/indonesia-payments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. anggit/indonesia-payments

ActiveLibrary[Payment Processing](/categories/payments)

anggit/indonesia-payments
=========================

Unified PHP SDK for Indonesian payment gateways (Midtrans, Xendit, etc.) with Laravel 13 integration.

v0.2.1-beta(2mo ago)12↓100%MITPHPPHP ^8.1

Since Apr 9Pushed 2mo agoCompare

[ Source](https://github.com/putralangkat97/indonesia-payments)[ Packagist](https://packagist.org/packages/anggit/indonesia-payments)[ RSS](/packages/anggit-indonesia-payments/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (4)Used By (0)

Indonesia Payments
==================

[](#indonesia-payments)

Unified PHP SDK for **Indonesian payment gateways**, with initial focus on **Xendit** and **Midtrans**, and seamless **Laravel** integration.

This library provides a consistent abstraction for:

- Creating payment charges/invoices.
- Checking payment status.
- Processing refunds.
- Handling webhook callbacks.
- (Future) Adding other drivers like DOKU, Duitku, etc.

The current implementations are **Xendit** and **Midtrans** via direct HTTP clients to their REST APIs (without depending on official SDKs). This keeps the package more stable and easier to follow PHP and framework updates.

---

Features
--------

[](#features)

- Core **framework-agnostic** (pure PHP, PSR-4).
- Consistent `GatewayInterface` abstraction for all providers.
- `XenditGateway` implementation:
    - Create invoice (Payment Link API).
    - Get invoice status.
    - Create refunds.
    - Webhook handler + callback token verification (`x-callback-token`).
- `MidtransGateway` implementation:
    - Create Snap transaction.
    - Get transaction status.
    - Create refunds.
    - Webhook handler + SHA-512 signature verification.
- Clean DTOs &amp; Enums:
    - `ChargeRequest`, `ChargeResponse`, `PaymentDetails`, `RefundRequest`, `RefundResponse`, `WebhookPayload`, `WebhookResult`.
    - `PaymentMethod` (`VIRTUAL_ACCOUNT`, `EWALLET`, `CARD`, `QRIS`).
    - `PaymentStatus` (`PENDING`, `PAID`, `FAILED`, `EXPIRED`, `REFUNDED`).
- `PaymentManager` + `GatewayFactory` for gateway selection.
- Laravel integration (ServiceProvider + `Payment` Facade).
- **Mago** linter/formatter configured out of the box.

---

Installation
------------

[](#installation)

```
composer require anggit/indonesia-payments
```

Requirements:

- PHP `^8.1` (8.1, 8.2, 8.3, 8.4, 8.5).
- Composer v2.

This package uses `guzzlehttp/guzzle` for HTTP communication with the payment gateway APIs.

---

Architecture
------------

[](#architecture)

Overview of the core components:

- `GatewayInterface` -- contract for all payment gateways:
    - `charge()`, `getPayment()`, `refund()`, `handleWebhook()`.
- `XenditGateway` -- Xendit implementation.
- `MidtransGateway` -- Midtrans Snap implementation.
- `PaymentManager` -- select gateway (`default()` / `via('xendit')`).
- `GatewayFactory` -- build gateway instances from configuration.
- `WebhookPayload` &amp; `WebhookResult` -- normalized webhook data.

Main namespace structure:

- `Anggit\IndonesiaPayments\Contracts`
- `Anggit\IndonesiaPayments\DTO`
- `Anggit\IndonesiaPayments\Enums`
- `Anggit\IndonesiaPayments\Gateways`
- `Anggit\IndonesiaPayments\Support`
- `Anggit\IndonesiaPayments\Laravel\...`

---

Configuration
-------------

[](#configuration)

### Xendit

[](#xendit)

You need a **Secret Key** and a **Webhook Verification Token** from the Xendit dashboard (Development or Production). The webhook token is found under Settings &gt; Webhooks in the Xendit Dashboard.

### Midtrans

[](#midtrans)

You need a **Server Key** from the Midtrans dashboard (Sandbox or Production).

### Pure PHP Configuration

[](#pure-php-configuration)

```
$config = [
    'default' => 'xendit',
    'gateways' => [
        'xendit' => [
            'secret_key'    => 'xnd_development_XXXXXXXXXXX',
            'webhook_token' => 'your-xendit-webhook-verification-token',
            'base_url'      => null, // null = https://api.xendit.co
        ],
        'midtrans' => [
            'server_key'    => 'SB-Mid-server-XXXXXXXXXXX',
            'is_production' => false,
        ],
    ],
];
```

### Laravel Configuration (`config/indopay.php`)

[](#laravel-configuration-configindopayphp)

```
return [
    'default' => env('INDOPAY_DEFAULT', 'xendit'),

    'gateways' => [
        'xendit' => [
            'secret_key'    => env('XENDIT_SECRET_KEY'),
            'webhook_token' => env('XENDIT_WEBHOOK_TOKEN'),
            'base_url'      => env('XENDIT_BASE_URL'),
        ],

        'midtrans' => [
            'server_key'    => env('MIDTRANS_SERVER_KEY'),
            'is_production' => env('MIDTRANS_IS_PRODUCTION', false),
        ],
    ],
];
```

In your `.env`:

```
XENDIT_SECRET_KEY=xnd_development_XXXXXXXXXXX
XENDIT_WEBHOOK_TOKEN=your-xendit-webhook-verification-token
MIDTRANS_SERVER_KEY=SB-Mid-server-XXXXXXXXXXX
INDOPAY_DEFAULT=xendit
```

---

Usage -- Pure PHP
-----------------

[](#usage----pure-php)

Minimal example using `PaymentManager` and `GatewayFactory` directly.

```
