-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathManualMultiPay.php
More file actions
182 lines (172 loc) · 7.04 KB
/
Copy pathManualMultiPay.php
File metadata and controls
182 lines (172 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
namespace Paymenter\Extensions\Gateways\ManualMultiPay;
use App\Classes\Extension\Gateway;
use Illuminate\Support\Facades\Log;
use App\Models\Invoice;
use Illuminate\Support\Facades\View;
class ManualMultiPay extends Gateway
{
public function boot()
{
require __DIR__ . '/routes.php';
View::addNamespace('gateways.mmp', __DIR__ . '/resources/views');
}
/**
* Get all the configuration for the extension
*
* @param array $values
* @return array
*/
public function getConfig($values = [])
{
return [
[
'name' => 'merchant_name',
'label' => 'Merchant Name',
'type' => 'text',
'description' => 'Merchant Name',
'required' => true,
],
[
'name' => 'payment_address_type',
'label' => 'Payment Address Type',
'type' => 'select',
'default' => 'upi',
'required' => true,
'options' => [
'upi' => 'UPI Address',
'bank' => 'Bank Account Number',
'aadhaar' => 'Aadhaar Number',
'mobile' => 'Mobile Number',
],
],
[
'name' => 'upi_address',
'label' => 'UPI Address',
'type' => 'text',
'required' => true,
'description' => 'Set to 0 if not applicable',
],
[
'name' => 'bank_account_number',
'label' => 'Bank Account Number',
'type' => 'text',
'required' => true,
'description' => 'Set to 0 if not applicable',
],
[
'name' => 'bank_ifsc_code',
'label' => 'Bank IFSC Code',
'type' => 'text',
'required' => true,
'description' => 'Set to 0 if not applicable',
],
[
'name' => 'aadhaar_number',
'label' => 'Aadhaar Number',
'type' => 'number',
'required' => true,
'description' => 'Set to 0 if not applicable',
],
[
'name' => 'mobile_number',
'label' => 'Mobile Number',
'type' => 'number',
'required' => true,
'description' => 'Set to 0 if not applicable',
],
[
'name' => 'order_prefix',
'label' => 'Order Prefix',
'type' => 'text',
'description' => 'Order Prefix',
'required' => false,
],
[
'name' => 'payment_confirmation_eta',
'label' => 'Payment Confirmation ETA',
'type' => 'text',
'required' => false,
],
[
'name' => 'allow_foreign_currency',
'label' => 'Allow Foreign Currency',
'type' => 'checkbox',
]
];
}
/**
* Return a view or a url to redirect to
*
* @param Invoice $invoice
* @param float $total
* @return string
*/
public function pay($invoice, $total)
{
return route('extensions.gateways.mmp.pay', ['invoiceId' => $invoice->id]);
}
public function payment($invoiceId) {
$invoice = Invoice::find($invoiceId);
if (!$invoice) {
return redirect()->route('invoices')->with('error', 'Invoice not found');
}
if ($invoice->status != 'pending') {
return redirect()->route('invoices.show', ['invoice' => $invoice->id])->with('error', 'Invoice must be pending');
}
$allowForeignCurrency = $this->config('allow_foreign_currency');
if (!$allowForeignCurrency && $invoice->currency_code != 'INR') {
return redirect()->route('invoices.show', ['invoice' => $invoice->id])->with('error', 'Foreign currency not allowed (Extension Setting)');
}
$total = $invoice->remaining;
$orderId = $this->config('order_prefix') . $invoiceId;
$paymentLink = '';
$paymentAddressDisplay = '';
$merchantName = $this->config('merchant_name');
$paymentAddressType = $this->config('payment_address_type');
$upiAddress = $this->config('upi_address');
$bankAccountNumber = $this->config('bank_account_number');
$bankIfscCode = $this->config('bank_ifsc_code');
$aadhaarNumber = $this->config('aadhaar_number');
$mobileNumber = $this->config('mobile_number');
$paymentConfirmationEta = $this->config('payment_confirmation_eta');
switch($paymentAddressType) {
case "upi":
$paymentLink = "upi://pay?pa={$upiAddress}&pn={$merchantName}&am={$total}&tn={$orderId}&cu=INR";
$paymentAddressDisplay = $upiAddress;
break;
case "bank":
$paymentLink = "upi://pay?pa={$bankAccountNumber}@{$bankIfscCode}.ifsc.npci&pn={$merchantName}&am={$total}&tn={$orderId}&cu=INR";
$paymentAddressDisplay = "{$bankAccountNumber}@{$bankIfscCode}.ifsc.npci";
break;
case "aadhaar":
$paymentLink = "upi://pay?pa={$aadhaarNumber}@aadhaar.npci&pn={$merchantName}&am={$total}&tn={$orderId}&cu=INR";
$paymentAddressDisplay = "{$aadhaarNumber}@aadhaar.npci";
break;
case "mobile":
$paymentLink = "upi://pay?pa={$mobileNumber}@mobile.npci&pn={$merchantName}&am={$total}&tn={$orderId}&cu=INR";
$paymentAddressDisplay = "{$mobileNumber}@mobile.npci";
break;
default:
return redirect()->route('invoices.show', ['invoice' => $invoice->id])->with('error', 'Invalid Payment Address Type (Extension Setting)');
}
Log::info('MMP Order ID: ' . $orderId . 'Debug: ' . $paymentLink . ' ' . $paymentAddressDisplay . ' ' . $total . ' ' . $merchantName . ' ' . $paymentAddressType . ' ' . $paymentConfirmationEta . ' ' . $upiAddress . ' ' . $bankAccountNumber . ' ' . $bankIfscCode . ' ' . $aadhaarNumber . ' ' . $mobileNumber);
return view('gateways.mmp::pay', [
'invoice' => $invoice,
'merchantName' => $merchantName,
'paymentAddressType' => $paymentAddressType,
'paymentLink' => $paymentLink,
'paymentAddressDisplay' => $paymentAddressDisplay,
'total' => $total,
'orderId' => $orderId,
'returnUrl' => route('invoices.show', ['invoice' => $invoice->id]),
'paymentConfirmationEta' => $paymentConfirmationEta,
'upiAddress' => $upiAddress,
'bankAccountNumber' => $bankAccountNumber,
'bankIfscCode' => $bankIfscCode,
'aadhaarNumber' => $aadhaarNumber,
'mobileNumber' => $mobileNumber,
'allowForeignCurrency' => $allowForeignCurrency,
]);
}
}