EasyPaisa is Pakistan's leading digital payment platform, operated by Telenor Microfinance Bank. It provides comprehensive payment solutions including mobile wallet payments, over-the-counter (OTC) payments, and bank transfers, serving millions of users across Pakistan.
| Method | Type | Description |
|---|---|---|
| Mobile Account | Wallet | Direct payment from EasyPaisa mobile account balance |
| OTC | Cash | Generate payment voucher and pay cash at any EasyPaisa shop |
| Bank Account | Bank Transfer | Payment through linked bank accounts |
composer require zfhassaan/easypaisa
Add the following to your .env file:
# EasyPaisa Configuration
EASYPAISA_MERCHANT_ID=your_merchant_id
EASYPAISA_MERCHANT_PASSWORD=your_merchant_password
EASYPAISA_STORE_ID=your_store_id
EASYPAISA_ACCOUNT_NUMBER=your_account_number
EASYPAISA_TEST_MODE=true
For production:
EASYPAISA_MERCHANT_ID=your_production_merchant_id
EASYPAISA_MERCHANT_PASSWORD=your_production_password
EASYPAISA_TEST_MODE=false
use Mdiqbal\LaravelPayments\Facades\Payment;
$paymentData = [
'amount' => 1000.00,
'currency' => 'PKR',
'user_email' => 'customer@example.com',
'user_name' => 'Ahmed Khan',
'description' => 'Payment for Order #123',
'metadata' => [
'payment_type' => 'mobile_account',
'mobile_account' => '03xxxxxxxxx', // EasyPaisa mobile number
],
];
$response = Payment::via('easypaisa')->pay($paymentData);
if ($response->success) {
// Redirect to payment URL or show payment details
if ($response->redirect_url) {
return redirect($response->redirect_url);
}
// Or show payment instructions
return view('payment.instructions', [
'transaction_id' => $response->transaction_id,
'message' => $response->message,
]);
}
// Handle error
return back()->with('error', $response->message);
$paymentData = [
'amount' => 2500.00,
'currency' => 'PKR',
'user_email' => 'customer@example.com',
'user_name' => 'Muhammad Ali',
'description' => 'Product purchase',
'metadata' => [
'payment_type' => 'otc',
'expiry_date' => date('Ymd', strtotime('+3 days')),
],
];
$response = Payment::gateway('easypaisa')
->config('test_mode', false) // Force production
->pay($paymentData);
if ($response->success) {
$paymentCode = $response->data['payment_code'] ?? null;
$expiryDate = $response->data['expiry_date'] ?? null;
return view('payment.otc', [
'payment_code' => $paymentCode,
'amount' => 2500.00,
'expiry_date' => $expiryDate,
'instructions' => 'Visit any EasyPaisa shop and provide this payment code',
]);
}
$paymentData = [
'amount' => 5000.00,
'currency' => 'PKR',
'user_email' => 'customer@example.com',
'user_name' => 'Fatima Ahmed',
'description' => 'Service payment',
'metadata' => [
'payment_type' => 'bank_account',
'bank_account' => '1234567890123', // Bank account number
],
];
$response = Payment::via('easypaisa')->pay($paymentData);
if ($response->success) {
return redirect($response->redirect_url);
}
use Illuminate\Http\Request;
public function verifyPayment(Request $request)
{
$transactionId = $request->input('transaction_id');
$response = Payment::via('easypaisa')->verify([
'transaction_id' => $transactionId
]);
if ($response->success) {
// Payment successful
$status = $response->status;
$amount = $response->amount;
$currency = $response->currency;
return response()->json([
'status' => 'success',
'payment_status' => $status,
'amount' => $amount,
'currency' => $currency,
]);
}
return response()->json([
'status' => 'error',
'message' => $response->message,
]);
}
$methods = Payment::via('easypaisa')->methods();
foreach ($methods as $method) {
echo $method['name'] . ': ' . $method['description'] . "\n";
}
Create a webhook endpoint to receive payment notifications:
// routes/web.php
Route::post('/webhooks/easypaisa', 'PaymentController@handleEasyPaisaWebhook');
// PaymentController.php
use Illuminate\Http\Request;
public function handleEasyPaisaWebhook(Request $request)
{
$response = Payment::via('easypaisa')->webhook($request);
if ($response->success) {
$transactionId = $response->transaction_id;
$status = $response->status;
$amount = $response->amount;
$paymentMethod = $response->data['payment_method'] ?? null;
// Handle based on payment status
switch ($status) {
case 'completed':
// Update order as paid
$this->updateOrderAsPaid($transactionId, $amount);
break;
case 'failed':
// Handle failed payment
$this->handleFailedPayment($transactionId);
break;
case 'cancelled':
// Handle cancelled payment
$this->handleCancelledPayment($transactionId);
break;
case 'pending':
// Payment is pending confirmation
$this->markOrderAsPending($transactionId);
break;
}
return response()->json(['status' => 'received']);
}
return response()->json(['error' => 'Invalid webhook'], 400);
}
Process refunds through the EasyPaisa gateway:
$refundData = [
'transaction_id' => 'original_transaction_id',
'amount' => 500.00, // Optional - defaults to full refund
'reason' => 'Customer requested refund',
];
$response = Payment::via('easypaisa')->refund($refundData);
if ($response->success) {
$refundId = $response->transaction_id;
// Update your records
}
EasyPaisa exclusively supports Pakistani Rupee (PKR):
// Check currency support
$supportsPKR = Payment::via('easypaisa')->supportsCurrency('PKR'); // true
$supportsUSD = Payment::via('easypaisa')->supportsCurrency('USD'); // false
EasyPaisa gateway provides comprehensive error handling:
try {
$response = Payment::via('easypaisa')->pay($paymentData);
if (!$response->success) {
// Handle specific EasyPaisa errors
switch ($response->code) {
case '002':
return back()->with('error', 'Payment failed - insufficient funds');
case '097':
return back()->with('error', 'Transaction rejected by bank');
case '098':
return back()->with('error', 'Payment cancelled by user');
default:
return back()->with('error', $response->message);
}
}
return redirect($response->redirect_url);
} catch (\Exception $e) {
Log::error('EasyPaisa payment error: ' . $e->getMessage());
return back()->with('error', 'Payment processing error');
}
| Code | Description | Action |
|---|---|---|
| 000 | Success | Payment completed |
| 001 | Pending | Payment is processing |
| 002 | Failed | Payment failed - retry |
| 003 | Cancelled | Payment cancelled by user |
| 096 | Pending | Awaiting confirmation |
| 097 | Failed | Bank rejected transaction |
| 098 | Cancelled | User cancelled |
| 099 | Failed | General failure |
EasyPaisa provides a sandbox environment:
// Enable test mode
Payment::via('easypaisa')->config('test_mode', true);
// Or use test credentials directly
Payment::gateway('easypaisa')
->withConfig('test_mode', true)
->pay($paymentData);
Use these test credentials for development:
'test_mode' => true,
'merchant_id' => 'TEST_MERCHANT_ID',
'merchant_password' => 'TEST_PASSWORD',
'store_id' => 'TEST_STORE',
API Security
Webhook Security
Data Protection
Payment Flow
User Experience
Monitoring
"Invalid Merchant Credentials"
"Payment Failed"
"Webhook Not Received"
"Token Generation Failed"
Enable debug logging:
// Enable debug logging
Payment::gateway('easypaisa')
->withConfig('debug', true)
->pay($paymentData);
EasyPaisa operates under State Bank of Pakistan (SBP) regulations:
How can I help you explore Laravel packages today?