shikhar/laravel-payments
最新稳定版本:v1.1.0
Composer 安装命令:
composer require shikhar/laravel-payments
包简介
A Laravel payment gateway package supporting Khalti & eSewa
README 文档
README
Easily integrate eSewa & Khalti payments in your Laravel app – Made in Nepal by Shikhar
🚀 Installation
composer require shikhar/laravel-payments
📁 Publish Config File
php artisan vendor:publish --tag=payments-config
This will create:
config/payments.php
⚙️ Example config/payments.php
return [ 'default' => env('PAYMENT_DEFAULT', 'khalti'), 'gateways' => [ 'khalti' => [ 'public_key' => env('KHALTI_PUBLIC_KEY', ''), 'secret_key' => env('KHALTI_SECRET_KEY', ''), ], 'esewa' => [ 'form_url' => 'https://rc-epay.esewa.com.np/api/epay/main/v2/form', 'merchant_id' => env('ESEWA_MERCHANT_ID', 'EPAYTEST'), 'secret_key' => env('ESEWA_SECRET_KEY', '8gBm/:&EnhH.1/q'), ], ], ];
🔐 Add Credentials to .env
PAYMENT_DEFAULT=esewa KHALTI_PUBLIC_KEY=your_public_key KHALTI_SECRET_KEY=your_secret_key ESEWA_MERCHANT_ID=EPAYTEST ESEWA_SECRET_KEY=your_secret_key
🧩 Controller Example
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Shikhar\Payments\PaymentManager; class PaymentController extends Controller { public $payment; public function __construct(PaymentManager $payment) { $this->payment = $payment; } public function pay(Request $request) { $payload = [ 'tax_amount' => $request->input('tax_amount'), 'transaction_uuid' => $request->input('transaction_uuid'), 'product_code' => $request->input('product_code'), 'customer_name' => $request->input('customer_name'), 'customer_email' => $request->input('customer_email'), 'customer_phone' => $request->input('customer_phone'), 'success_url' => $request->input('success_url'), 'failure_url' => $request->input('failure_url'), ]; $response = $this->payment ->via($request->payment_gateway) ->charge($request->amount, $payload); return view('pay')->with(compact('response')); } }
💳 Example Payment Form (User Chooses Gateway)
<form id="paymentForm" method="POST" action="{{ url('/pay') }}"> @csrf <select name="payment_gateway" required> <option value="esewa">Esewa</option> <option value="khalti">Khalti</option> </select> <input type="number" name="amount" value="100" required> <input type="number" name="tax_amount" value="10"> <input type="text" name="transaction_uuid" value="{{ uniqid() }}"> <input type="text" name="product_code" value="EPAYTEST"> <input type="text" name="success_url" value="https://yourapp.com/success"> <input type="text" name="failure_url" value="https://yourapp.com/failure"> <input type="text" name="customer_name" value="John Doe"> <input type="email" name="customer_email" value="john@example.com"> <input type="text" name="customer_phone" value="9800000000"> <button type="submit">Pay Now</button> </form>
🧾 Esewa Redirect Page Example
<form id="esewaForm" method="POST" action="{{ $response['action_url'] }}" style="display:none;"> @foreach ($response['fields'] as $key => $value) <input type="hidden" name="{{ $key }}" value="{{ $value }}"> @endforeach </form> <button onclick="document.getElementById('esewaForm').submit();"> Pay with Esewa </button>
🏗 Folder Structure
src/
PaymentManager.php
Providers/
PaymentServiceProvider.php
config/
payments.php
📌 Usage Summary
- Install package
- Publish
payments.php - Configure
.env - Inject
PaymentManager
$this->payment->via('esewa')->charge(100, $payload);
OR:
$this->payment->via('khalti')->charge(100, $payload);
🧪 Sandbox Support
- Esewa: default sandbox form URL included
- Khalti: works automatically with test keys
📜 License
MIT © Shikhar Bahik Magar
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-22