dizatech /
transaction
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dizatech\Transaction\Drivers; |
||
| 4 | |||
| 5 | use Dizatech\SamanIpg\SamanIpg; |
||
| 6 | use Dizatech\Transaction\Abstracts\Driver; |
||
| 7 | use Dizatech\Transaction\Models\Transaction; |
||
| 8 | |||
| 9 | class Saman extends Driver |
||
| 10 | { |
||
| 11 | public function init($amount, $orderId, $callbackUrl, $detail = []) |
||
| 12 | { |
||
| 13 | // Create new transaction |
||
| 14 | $transaction = $this->createNewTransaction($orderId, $amount); |
||
| 15 | |||
| 16 | // Create object from Sadad Driver |
||
| 17 | $class = new SamanIpg($this->getInformation()); |
||
| 18 | |||
| 19 | $result = $class->requestPayment( |
||
| 20 | amount: $amount, |
||
| 21 | order_id: $transaction->id, |
||
| 22 | redirect_url: $callbackUrl |
||
| 23 | ); |
||
| 24 | |||
| 25 | if (!isset($detail['auto_redirect']) || $detail['auto_redirect'] == true) { |
||
| 26 | echo "<form method='post' action='https://sep.shaparak.ir/OnlinePG/OnlinePG' id='saman_redirect_form' style='display: none;'> |
||
| 27 | <input type='text' name='token' value='{$result->token}'> |
||
| 28 | <button type='submit'>Send</button> |
||
| 29 | </form> |
||
| 30 | <script>window.addEventListener('load', function () {document.getElementById('saman_redirect_form').submit()})</script>"; |
||
| 31 | exit; |
||
|
0 ignored issues
–
show
|
|||
| 32 | } |
||
| 33 | |||
| 34 | return $result; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function verify($request) |
||
| 38 | { |
||
| 39 | $class = new SamanIpg($this->getInformation()); |
||
| 40 | if (isset($request['State']) && $request['State'] == 'OK') { |
||
| 41 | $transaction = Transaction::whereId($request['ResNum'])->first(); |
||
| 42 | $result = $class->verify(amount: intval($transaction->amount), ref_number: $request['RefNum']); |
||
|
0 ignored issues
–
show
|
|||
| 43 | |||
| 44 | if ($result->status == 'success') { |
||
| 45 | $this->updateTransactionData($transaction->id, ['status' => 'successful', 'ref_no' => $result->ref_no, 'token' => $result->token]); |
||
|
0 ignored issues
–
show
|
|||
| 46 | } else { |
||
| 47 | $this->updateTransactionData($transaction->id, ['status' => 'failed']); |
||
| 48 | } |
||
| 49 | |||
| 50 | return $result; |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->updateTransactionData($request['ResNum'], ['status' => 'failed']); |
||
| 54 | return (object)[ |
||
| 55 | 'status' => 'error', |
||
| 56 | 'message' => 'پرداخت با خطا مواجه شد.', |
||
| 57 | ]; |
||
| 58 | } |
||
| 59 | } |
||
| 60 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.