|
1 | 1 | # Laravel Online Payment :: LaraPay component |
2 | 2 |
|
3 | | -Online Payment Module handler for Laravel 5+ known as LaraPay component. |
| 3 | +Online Payment Module handler for Laravel 5+ known as LaraPay component completely compatible with [banktest.ir](banktest.ir) simulator |
| 4 | + |
| 5 | +## What is Banktest? |
| 6 | +[BankTest](banktest.ir) is a sandbox service for all Iranian online payment gateways |
| 7 | +بانک تست : شبیه ساز درگاه های پرداخت آنلاین / تست درگاه پرداخت آنلاین |
| 8 | + |
4 | 9 |
|
5 | 10 | ## Currenctly support: |
6 | 11 |
|
@@ -45,37 +50,250 @@ use Tartan\Larapay\Transaction; |
45 | 50 |
|
46 | 51 | class Transaction extends Model implements TransactionInterface |
47 | 52 | { |
| 53 | + // set order reference Id |
48 | 54 | public function setReferenceId($referenceId, $save = true){} |
49 | 55 |
|
| 56 | + // check if you transaction is ready for requesting payment token |
50 | 57 | public function checkForRequestToken(){} |
51 | 58 |
|
| 59 | + // check if transaction is ready for requesting verify transaction |
52 | 60 | public function checkForVerify(){} |
53 | 61 |
|
| 62 | + // check if transaction is ready for requesting inqury transaction (if supported by gateway) |
54 | 63 | public function checkForInquiry(){} |
55 | 64 |
|
| 65 | + // check if transaction is ready for requesting reverse transaction (if supported by gateway) |
56 | 66 | public function checkForReverse(){} |
57 | 67 |
|
| 68 | + // check if transaction is ready for requesting settle/... transaction (if needed by gateway) |
58 | 69 | public function checkForAfterVerify(){} |
59 | 70 |
|
| 71 | + // update transaction by paid card number (if provided by gateway) |
60 | 72 | public function setCardNumber($cardNumber){} |
61 | | - |
| 73 | + |
| 74 | + // mark transaction as verified |
62 | 75 | public function setVerified(){} |
63 | | - |
| 76 | + |
| 77 | + // mark transaction as settled/... |
64 | 78 | public function setAfterVerified(){} |
65 | 79 |
|
| 80 | + // mark transaction as completed |
66 | 81 | public function setSuccessful($flag){} |
67 | 82 |
|
| 83 | + // mark transaction as reversed |
68 | 84 | public function setReversed(){} |
69 | 85 |
|
| 86 | + // get transaction amount |
70 | 87 | public function getAmount(){} |
71 | 88 |
|
| 89 | + // set transactions's paid tme |
72 | 90 | public function setPaidAt($time = 'now'){} |
73 | 91 |
|
| 92 | + // set transaction's extra details |
74 | 93 | public function setExtra($key, $value, $save = false){} |
75 | 94 | } |
76 | 95 | ``` |
77 | 96 |
|
| 97 | +6. Prepare for online payment |
| 98 | + |
| 99 | +```php |
| 100 | + public function payOnline (Request $request, Transaction $transaction) |
| 101 | + { |
| 102 | + // check if the selected payment is active or not from your gateways table |
| 103 | + $paymentGateway = Gateway::activeGate() |
| 104 | + ->where('slug', $request->input('by_online_gateway')) |
| 105 | + ->first(); |
| 106 | + |
| 107 | + if (empty($paymentGateway)) { |
| 108 | + return view('gateway.notfound'); |
| 109 | + } |
| 110 | + |
| 111 | + // get some additional parameters for updating transaction |
| 112 | + $parameters = [ |
| 113 | + 'description' => $request->input('by_online_description', ''), |
| 114 | + 'bank' => $request->input('by_online_gateway'), |
| 115 | + ]; |
| 116 | + |
| 117 | + // update transaction payment method |
| 118 | + $transaction = $this->transactionsRepository->setTransactionPaid( |
| 119 | + $transaction, TransactionPayment::ONLINE, $parameters |
| 120 | + ); |
| 121 | + |
| 122 | + // make larapay payment gateway instance |
| 123 | + $paymentGatewayHandler = Larapay::make($paymentGateway->slug, $transaction); |
| 124 | + |
| 125 | + |
| 126 | + // set payment params |
| 127 | + $paymentParams = [ |
| 128 | + 'order_id' => $transaction->getBankOrderId(), |
| 129 | + 'redirect_url' => route('payment.callback', [ |
| 130 | + 'bank' => $paymentGateway->slug, |
| 131 | + 'transactionId' => $transaction->guid |
| 132 | + ]), |
| 133 | + 'amount' => $transaction->amount, |
| 134 | + 'submit_label' => trans('larapay::larapay.goto_gate') |
| 135 | + ]; |
| 136 | + |
| 137 | + try { |
| 138 | + // get goto gate form |
| 139 | + $form = $paymentGatewayHandler->form($paymentParams); |
| 140 | + } catch (\Exception $e) { |
| 141 | + // could not generate goto gate form |
| 142 | + Log::emergency($paymentGateway->slug . ' #' . $e->getCode() . '-' . $e->getMessage()); |
| 143 | + Session::flash('alert-danger', trans('t.could_not_create_goto_bank_form', ['gateway' => $paymentGateway->name])); |
| 144 | + |
| 145 | + return redirect()->back()->withInput(); |
| 146 | + } |
| 147 | + if (is_null($form)) { |
| 148 | + return redirect()->back()->withInput(); |
| 149 | + } |
| 150 | + |
| 151 | + // view goto gate view |
| 152 | + return view('gateway.gotogate', [ |
| 153 | + 'gateway' => $paymentGateway, |
| 154 | + 'form' => $form, |
| 155 | + ]); |
| 156 | + } |
| 157 | +``` |
| 158 | + |
| 159 | +## Component Configuration |
78 | 160 |
|
| 161 | +```php |
| 162 | +return [ |
| 163 | + |
| 164 | + /* |
| 165 | + |-------------------------------------------------------------------------- |
| 166 | + | Tartan e-payment component`s operation mode |
| 167 | + |-------------------------------------------------------------------------- |
| 168 | + | |
| 169 | + | *** very important config *** |
| 170 | + | please do not change it if you don't know what BankTest is |
| 171 | + | |
| 172 | + | > production: component operates with real payments gateways |
| 173 | + | > development: component operates with simulated "BankTest" (banktest.ir) gateways |
| 174 | + | |
| 175 | + */ |
| 176 | + 'mode' => env('LARAPAY_MODE', 'production'), |
| 177 | + |
| 178 | + /* |
| 179 | + |-------------------------------------------------------------------------- |
| 180 | + | ready to serve gateways |
| 181 | + |-------------------------------------------------------------------------- |
| 182 | + | |
| 183 | + | specifies ready to serve gateways. |
| 184 | + | gateway characters are case sensitive and should be exactly same as their folder name. |
| 185 | + | eg, "Jahanpay" is correct not "JahanPay" or "jahanpay" |
| 186 | + | the gateways list is comma separated |
| 187 | + | |
| 188 | + */ |
| 189 | + 'gateways' => env('LARAPAY_GATES', 'Mellat,Saman,Pasargad'), |
| 190 | + |
| 191 | + /* |
| 192 | + |-------------------------------------------------------------------------- |
| 193 | + | Mellat gateway configuration |
| 194 | + |-------------------------------------------------------------------------- |
| 195 | + */ |
| 196 | + 'mellat' => [ |
| 197 | + 'username' => env('MELLAT_USERNAME', ''), |
| 198 | + 'password' => env('MELLAT_PASSWORD',''), |
| 199 | + 'terminal_id' => env('MELLAT_TERMINAL_ID', ''), |
| 200 | + 'callback_url' => env('MELLAT_CALLBACK_URL', '') |
| 201 | + ], |
| 202 | + |
| 203 | + /* |
| 204 | + |-------------------------------------------------------------------------- |
| 205 | + | Parsian gateway configuration |
| 206 | + |-------------------------------------------------------------------------- |
| 207 | + */ |
| 208 | + 'parsian' => [ |
| 209 | + 'pin' => env('PARSIAN_PIN', ''), |
| 210 | + ], |
| 211 | + /* |
| 212 | + |-------------------------------------------------------------------------- |
| 213 | + | Pasargad gateway configuration |
| 214 | + |-------------------------------------------------------------------------- |
| 215 | + */ |
| 216 | + 'pasargad' => [ |
| 217 | + 'terminalId' => env('PASARGAD_TERMINAL_ID', ''), |
| 218 | + 'merchantId' => env('PASARGAD_MERCHANT_ID', ''), |
| 219 | + 'certificate_path' => storage_path(env('PASARGAD_CERT_PATH', 'payment/pasargad/certificate.xml')), |
| 220 | + 'callback_url' => env('PASARGAD_CALLBACK_URL', '') |
| 221 | + ], |
| 222 | + |
| 223 | + /* |
| 224 | + |-------------------------------------------------------------------------- |
| 225 | + | Sadad gateway configuration |
| 226 | + |-------------------------------------------------------------------------- |
| 227 | + */ |
| 228 | + 'sadad' => [ |
| 229 | + 'merchant' => env('SADAD_MERCHANT', ''), |
| 230 | + 'transaction_key' => env('SADAD_TRANS_KEY', ''), |
| 231 | + 'terminal_id' => env('SADAD_TERMINAL_ID', ''), |
| 232 | + 'callback_url' => env('SADAD_CALLBACK_URL', ''), |
| 233 | + ], |
| 234 | + |
| 235 | + 'saderat' => [ |
| 236 | + 'MID' => env('SADERAT_MID', ''), |
| 237 | + 'TID' => env('SADERAT_TID', ''), |
| 238 | + 'public_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/public.key')), |
| 239 | + 'private_key_path' => storage_path(env('SADERAT_CERT_PATH', 'payment/saderat/private.key')), |
| 240 | + ], |
| 241 | + |
| 242 | + /* |
| 243 | + |-------------------------------------------------------------------------- |
| 244 | + | Saman gateway configuration |
| 245 | + |-------------------------------------------------------------------------- |
| 246 | + */ |
| 247 | + 'saman' => [ |
| 248 | + 'merchant_id' => env('SAMAN_MERCHANT_ID', ''), |
| 249 | + 'merchant_pass' => env('SAMAN_MERCHANT_PASS', ''), |
| 250 | + ], |
| 251 | + |
| 252 | + /* |
| 253 | + |-------------------------------------------------------------------------- |
| 254 | + | Zarinpal gateway configuration |
| 255 | + |-------------------------------------------------------------------------- |
| 256 | + | |
| 257 | + | types: acceptable values --- zarin-gate or normal |
| 258 | + | server: acceptable values --- germany or iran or test |
| 259 | + | |
| 260 | + */ |
| 261 | + 'zarinpal' => [ |
| 262 | + 'merchant_id' => env('ZARINPAL_MERCHANT_ID', ''), |
| 263 | + 'type' => env('ZARINPAL_TYPE', 'zarin-gate'), |
| 264 | + 'callback_url' => env('ZARINPAL_CALLBACK_URL', ''), |
| 265 | + 'server' => env('ZARINPAL_SERVER', 'germany'), |
| 266 | + 'email' => env('ZARINPAL_EMAIL', ''), |
| 267 | + 'mobile' => env('ZARINPAL_MOBILE', '09xxxxxxxxx'), |
| 268 | + 'description' => env('ZARINPAL_MOBILE', 'powered-by-TartanPayment'), |
| 269 | + ], |
| 270 | + |
| 271 | + /* |
| 272 | + |-------------------------------------------------------------------------- |
| 273 | + | SoapClient Options |
| 274 | + |-------------------------------------------------------------------------- |
| 275 | + | |
| 276 | + | useOptions: true/false |
| 277 | + | options: soapClient Options |
| 278 | + | |
| 279 | + */ |
| 280 | + 'soap' => [ |
| 281 | + 'useOptions' => env('SOAP_HAS_OPTIONS', false), |
| 282 | + 'options' => [ |
| 283 | + 'proxy_host' => env('SOAP_PROXY_HOST', ''), |
| 284 | + 'proxy_port' => env('SOAP_PROXY_PORT', ''), |
| 285 | + 'stream_context' => stream_context_create( |
| 286 | + [ |
| 287 | + 'ssl' => [ |
| 288 | + 'verify_peer' => false, |
| 289 | + 'verify_peer_name' => false, |
| 290 | + ], |
| 291 | + ] |
| 292 | + ), |
| 293 | + ] |
| 294 | + ] |
| 295 | +]; |
| 296 | +``` |
79 | 297 |
|
80 | 298 | ## Team |
81 | 299 |
|
|
0 commit comments