Skip to content

Commit a348f2a

Browse files
committed
release: alpha
0 parents  commit a348f2a

File tree

73 files changed

+12497
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+12497
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.env
2+
.idea
3+
vendor

README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Laravel Midtrans
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/bensondevs/laravel-midtrans.svg?style=flat-square)](https://packagist.org/packages/bensondevs/laravel-midtrans)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/bensondevs/laravel-midtrans.svg?style=flat-square)](https://packagist.org/packages/bensondevs/laravel-midtrans)
5+
6+
A modern, testable, and fluent Laravel wrapper for the [Midtrans](https://midtrans.com) API.
7+
8+
Supports:
9+
- Snap payments
10+
- Subscription billing
11+
- Card registration
12+
- GoPay partner account creation
13+
- Laravel auto-discovery and configuration publishing
14+
15+
---
16+
17+
## 🚧 Project Status
18+
This package is currently in alpha testing phase.
19+
20+
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.
21+
22+
Your feedback and contributions are highly appreciated as the package stabilizes.
23+
24+
---
25+
26+
## 🔧 Installation
27+
28+
You can install the package via Composer:
29+
30+
```bash
31+
composer require bensondevs/laravel-midtrans
32+
```
33+
34+
If you want to publish the config file:
35+
36+
```bash
37+
php artisan vendor:publish --tag=midtrans-config
38+
```
39+
40+
---
41+
42+
## ⚙️ Configuration
43+
44+
After publishing, configure your `.env`:
45+
46+
```dotenv
47+
MIDTRANS_SANDBOX=true
48+
MIDTRANS_SANDBOX_CLIENT_KEY=your_sandbox_client_key
49+
MIDTRANS_SANDBOX_SERVER_KEY=your_sandbox_server_key
50+
51+
MIDTRANS_PRODUCTION_CLIENT_KEY=your_production_client_key
52+
MIDTRANS_PRODUCTION_SERVER_KEY=your_production_server_key
53+
```
54+
55+
---
56+
57+
## 💳 Billable Trait
58+
59+
To make a model (like `User`) billable, use the `Billable` trait:
60+
61+
```php
62+
use Bensondevs\Midtrans\Models\Concerns\Billable;
63+
64+
class User extends Authenticatable
65+
{
66+
use Billable;
67+
}
68+
```
69+
70+
This trait provides:
71+
72+
- `snapCharge(array $order)`
73+
- `refund(TransactionDetails $order, ?int $amount = null, ?string $reason = '')`
74+
- `subscribe(Subscribable $subscribable, PaymentType|string $paymentType, string $token)`
75+
- `gopaySubscribe(Subscribable $subscribable, GopayPaymentOption|string|null $paymentOption)`
76+
- `registerCard(...)` via `HasRegisteredCards`
77+
- `createGopayAccount()` and `getGopayToken(...)` via `HasGopayAccounts`
78+
79+
Ensure your model implements `Customer`, and optionally `Subscribable` or `TransactionDetails`.
80+
81+
---
82+
83+
## 🚀 Usage Examples
84+
85+
### Snap Payment
86+
87+
```php
88+
$response = $user->snapCharge([
89+
'order_id' => now()->timestamp,
90+
'gross_amount' => 100000,
91+
]);
92+
93+
$redirectUrl = $response->getRedirectUrl();
94+
```
95+
96+
### Refund
97+
98+
```php
99+
$user->refund($order, 50000, 'Customer requested refund');
100+
```
101+
102+
### Create Subscription (Credit Card)
103+
104+
```php
105+
$user->subscribe($plan, PaymentType::CreditCard, $cardToken);
106+
```
107+
108+
### Create Subscription (GoPay)
109+
110+
```php
111+
$user->gopaySubscribe($plan);
112+
```
113+
114+
### Register Credit Card
115+
116+
```php
117+
$user->registerCard('4811111111111114', '12', '2025');
118+
```
119+
120+
### Create GoPay Partner Account
121+
122+
```php
123+
$activationUrl = $user->getGopayActivationUrl('https://yourapp.com/redirect');
124+
```
125+
126+
---
127+
128+
## ✅ Testing
129+
130+
```bash
131+
composer test
132+
```
133+
134+
Make sure to set valid sandbox credentials in your `.env`.
135+
136+
---
137+
138+
## 📦 Roadmap
139+
140+
- [x] Snap charge
141+
- [x] Subscription API
142+
- [x] Card registration
143+
- [x] GoPay partner creation
144+
- [ ] Refunds & Transaction status
145+
- [ ] Event handling (webhooks)
146+
147+
---
148+
149+
## 🤝 Contributing
150+
151+
Contributions, issues, and feature requests are welcome!
152+
Feel free to open an issue or submit a pull request.
153+
154+
---
155+
156+
## 📄 License
157+
158+
MIT © [Simeon Benson](https://github.com/bensondevs)

composer.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "bensondevs/laravel-midtrans",
3+
"description": "Laravel wrapper for Midtrans Payments — simple, clean integration for Snap, Core API, and subscription billing.",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Simeon Bensona",
8+
"email": "[email protected]",
9+
"role": "Developer"
10+
}
11+
],
12+
"homepage": "https://github.com/bensondevs/laravel-midtrans",
13+
"keywords": [
14+
"Bensondevs",
15+
"Laravel",
16+
"Payment",
17+
"Midtrans"
18+
],
19+
"require": {
20+
"php": ">=8.2",
21+
"illuminate/broadcasting": "^10.0|^11.0|^12.0",
22+
"illuminate/events": "^10.0|^11.0|^12.0",
23+
"illuminate/http": "^10.0|^11.0|^12.0",
24+
"illuminate/queue": "^10.0|^11.0|^12.0",
25+
"illuminate/support": "^10.0|^11.0|^12.0",
26+
"symfony/http-foundation": "^6|^7"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Bensondevs\\Midtrans\\": "src"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Bensondevs\\Midtrans\\Tests\\": "tests",
36+
"Workbench\\App\\": "workbench/app/",
37+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
38+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
39+
}
40+
},
41+
"scripts": {
42+
"test": "vendor/bin/phpunit",
43+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
44+
"post-autoload-dump": [
45+
"@clear",
46+
"@prepare"
47+
],
48+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
49+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
50+
"build": "@php vendor/bin/testbench workbench:build --ansi",
51+
"serve": [
52+
"Composer\\Config::disableProcessTimeout",
53+
"@build",
54+
"@php vendor/bin/testbench serve --ansi"
55+
]
56+
},
57+
"config": {
58+
"sort-packages": true,
59+
"allow-plugins": {
60+
"pestphp/pest-plugin": true
61+
}
62+
},
63+
"extra": {
64+
"laravel": {
65+
"providers": [
66+
"Bensondevs\\Midtrans\\MidtransServiceProvider"
67+
],
68+
"aliases": {
69+
"Midtrans": "Bensondevs\\Midtrans\\Facades\\Midtrans"
70+
}
71+
}
72+
},
73+
"require-dev": {
74+
"laravel/pint": "^1.22",
75+
"orchestra/testbench": "^10.3",
76+
"pestphp/pest": "^3.8"
77+
}
78+
}

0 commit comments

Comments
 (0)