PHPackages                             bensondevs/laravel-midtrans - 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. bensondevs/laravel-midtrans

ActiveLibrary[Payment Processing](/categories/payments)

bensondevs/laravel-midtrans
===========================

Laravel wrapper for Midtrans Payments — simple, clean integration for Snap, Core API, and subscription billing.

0.1.0-alpha(1y ago)11MITPHPPHP &gt;=8.2

Since Jun 15Pushed 1y agoCompare

[ Source](https://github.com/bensondevs/laravel-midtrans)[ Packagist](https://packagist.org/packages/bensondevs/laravel-midtrans)[ Docs](https://github.com/bensondevs/laravel-midtrans)[ RSS](/packages/bensondevs-laravel-midtrans/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (9)Versions (3)Used By (0)

Laravel Midtrans
================

[](#laravel-midtrans)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3d303a4e929dd3b01b0d28b027260aaf4c5f433e4c1949e5d42cb716ef731880/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e736f6e646576732f6c61726176656c2d6d69647472616e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bensondevs/laravel-midtrans)[![Total Downloads](https://camo.githubusercontent.com/52f83b6b460058b0fd6dc42f1f80295ca75e0ed3dc729118d1a07edd7e2e90da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62656e736f6e646576732f6c61726176656c2d6d69647472616e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bensondevs/laravel-midtrans)

A modern, testable, and fluent Laravel wrapper for the [Midtrans](https://midtrans.com) API.

Supports:

- Snap payments
- Subscription billing
- Card registration
- GoPay partner account creation
- Laravel auto-discovery and configuration publishing

---

🚧 Project Status
----------------

[](#-project-status)

This package is currently in alpha testing phase.

The development process has encountered several challenges, particularly with GoPay-related integration, due to inconsistencies and gaps in the official Midtrans documentation. Please expect some rough edges, especially around GoPay functionality.

Your feedback and contributions are highly appreciated as the package stabilizes.

---

🔧 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require bensondevs/laravel-midtrans:^0.1@alpha
```

If you want to publish the config file:

```
php artisan vendor:publish --tag=midtrans-config
```

---

⚙️ Configuration
----------------

[](#️-configuration)

After publishing, configure your `.env`:

```
MIDTRANS_SANDBOX=true
MIDTRANS_SANDBOX_CLIENT_KEY=your_sandbox_client_key
MIDTRANS_SANDBOX_SERVER_KEY=your_sandbox_server_key

MIDTRANS_PRODUCTION_CLIENT_KEY=your_production_client_key
MIDTRANS_PRODUCTION_SERVER_KEY=your_production_server_key
```

---

💳 Billable Trait
----------------

[](#-billable-trait)

To make a model (like `User`) billable, use the `Billable` trait:

```
use Bensondevs\Midtrans\Models\Concerns\Billable;

class User extends Authenticatable
{
    use Billable;
}
```

This trait provides:

- `snapCharge(array $order)`
- `refund(TransactionDetails $order, ?int $amount = null, ?string $reason = '')`
- `subscribe(Subscribable $subscribable, PaymentType|string $paymentType, string $token)`
- `gopaySubscribe(Subscribable $subscribable, GopayPaymentOption|string|null $paymentOption)`
- `registerCard(...)` via `HasRegisteredCards`
- `createGopayAccount()` and `getGopayToken(...)` via `HasGopayAccounts`

Ensure your model implements `Customer`, and optionally `Subscribable` or `TransactionDetails`.

---

🚀 Usage Examples
----------------

[](#-usage-examples)

### Snap Payment

[](#snap-payment)

```
$response = $user->snapCharge([
    'order_id' => now()->timestamp,
    'gross_amount' => 100000,
]);

$redirectUrl = $response->getRedirectUrl();
```

### Refund

[](#refund)

```
$user->refund($order, 50000, 'Customer requested refund');
```

### Create Subscription (Credit Card)

[](#create-subscription-credit-card)

```
$user->subscribe($plan, PaymentType::CreditCard, $cardToken);
```

### Create Subscription (GoPay)

[](#create-subscription-gopay)

```
$user->gopaySubscribe($plan);
```

### Register Credit Card

[](#register-credit-card)

```
$user->registerCard('4811111111111114', '12', '2025');
```

### Create GoPay Partner Account

[](#create-gopay-partner-account)

```
$activationUrl = $user->getGopayActivationUrl('https://yourapp.com/redirect');
```

---

✅ Testing
---------

[](#-testing)

```
composer test
```

Make sure to set valid sandbox credentials in your `.env`.

---

📦 Roadmap
---------

[](#-roadmap)

- Snap charge
- Subscription API
- Card registration
- GoPay partner creation
- Refunds &amp; Transaction status
- Event handling (webhooks)

---

🤝 Contributing
--------------

[](#-contributing)

Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.

---

📄 License
---------

[](#-license)

MIT © [Simeon Benson](https://github.com/bensondevs)

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance48

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

384d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6953e310af7dc10b68168564e03f24bfcc36b8dd0830dea1d1696f50cda16fff?d=identicon)[bensondevs](/maintainers/bensondevs)

---

Top Contributors

[![bensondevs](https://avatars.githubusercontent.com/u/76855099?v=4)](https://github.com/bensondevs "bensondevs (3 commits)")

---

Tags

billablelaravelmidtranspaymentpayment-gatewaysnap-paymentlaravelpaymentmidtransBensondevs

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/bensondevs-laravel-midtrans/health.svg)

```
[![Health](https://phpackages.com/badges/bensondevs-laravel-midtrans/health.svg)](https://phpackages.com/packages/bensondevs-laravel-midtrans)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[illuminate/auth

The Illuminate Auth package.

10528.2M1.2k](/packages/illuminate-auth)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
