A modern, testable, and fluent Laravel wrapper for the Midtrans API.
Supports:
- Snap payments
- Subscription billing
- Card registration
- GoPay partner account creation
- Laravel auto-discovery and configuration publishing
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.
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
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
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(...)
viaHasRegisteredCards
createGopayAccount()
andgetGopayToken(...)
viaHasGopayAccounts
Ensure your model implements Customer
, and optionally Subscribable
or TransactionDetails
.
$response = $user->snapCharge([
'order_id' => now()->timestamp,
'gross_amount' => 100000,
]);
$redirectUrl = $response->getRedirectUrl();
$user->refund($order, 50000, 'Customer requested refund');
$user->subscribe($plan, PaymentType::CreditCard, $cardToken);
$user->gopaySubscribe($plan);
$user->registerCard('4811111111111114', '12', '2025');
$activationUrl = $user->getGopayActivationUrl('https://yourapp.com/redirect');
composer test
Make sure to set valid sandbox credentials in your .env
.
- Snap charge
- Subscription API
- Card registration
- GoPay partner creation
- Refunds & Transaction status
- Event handling (webhooks)
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request.
MIT © Simeon Benson