diff --git a/Enum.php b/Enum.php deleted file mode 100644 index ef00acdf..00000000 --- a/Enum.php +++ /dev/null @@ -1,33 +0,0 @@ -config = app('config'); - $this->request = app('request'); - - if ($this->config->has('gateway.timezone')) - date_default_timezone_set($this->config->get('gateway.timezone')); - - if (!is_null($port)) $this->make($port); - } - - /** - * Get supported ports - * - * @return array - */ - public function getSupportedPorts() - { - return [Enum::MELLAT, Enum::SADAD, Enum::ZARINPAL, Enum::PAYLINE, Enum::JAHANPAY, Enum::PARSIAN, Enum::PASARGAD]; - } - - /** - * Call methods of current driver - * - * @return mixed - */ - public function __call($name, $arguments) - { - - // calling by this way ( Gateway::mellat()->.. , Gateway::parsian()->.. ) - if(in_array(strtoupper($name),$this->getSupportedPorts())){ - return $this->make($name); - } - - return call_user_func_array([$this->port, $name], $arguments); - } - - /** - * Gets query builder from you transactions table - * @return mixed - */ - function getTable() - { - return DB::table($this->config->get('gateway.table')); - } - - /** - * Callback - * - * @return $this->port - * - * @throws InvalidRequestException - * @throws NotFoundTransactionException - * @throws PortNotFoundException - * @throws RetryException - */ - public function verify() - { - if (!$this->request->has('transaction_id')) - throw new InvalidRequestException; - - $id = intval($this->request->get('transaction_id')); - - $transaction = $this->getTable()->whereId($id)->first(); - - if (!$transaction) - throw new NotFoundTransactionException; - - if (in_array($transaction->status, [Enum::TRANSACTION_SUCCEED, Enum::TRANSACTION_FAILED])) - throw new RetryException; - - $this->make($transaction->port); - - return $this->port->verify($transaction); - } - - - /** - * Create new object from port class - * - * @param int $port - * @throws PortNotFoundException - */ - function make($port) - { - if ($port InstanceOf Mellat) { - $name = Enum::MELLAT; - } elseif ($port InstanceOf Parsian) { - $name = Enum::PARSIAN; - } elseif ($port InstanceOf Payline) { - $name = Enum::PAYLINE; - } elseif ($port InstanceOf Zarinpal) { - $name = Enum::ZARINPAL; - } elseif ($port InstanceOf JahanPay) { - $name = Enum::JAHANPAY; - } elseif ($port InstanceOf SADAD) { - $name = Enum::SADAD; - } elseif(in_array(strtoupper($port),$this->getSupportedPorts())){ - $port=ucfirst(strtolower($port)); - $name=strtoupper($port); - $class=__NAMESPACE__.'\\'.$port.'\\'.$port; - $port=new $class; - } else - throw new PortNotFoundException; - - $this->port = $port; - $this->port->setConfig($this->config); // injects config - $this->port->setPortName($name); // injects config - $this->port->boot(); - - return $this; - } -} diff --git a/GatewayServiceProvider.php b/GatewayServiceProvider.php deleted file mode 100644 index d387dee9..00000000 --- a/GatewayServiceProvider.php +++ /dev/null @@ -1,60 +0,0 @@ -publishes([ - $config => config_path('gateway.php'), - ], 'config'); - - // php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider --tag=migrations - $this->publishes([ - $migrations => base_path('database/migrations') - ], 'migrations'); - - - $this->loadViewsFrom($views, 'gateway'); - - // php artisan vendor:publish --provider=Larabookir\Gateway\GatewayServiceProvider --tag=views - $this->publishes([ - $views => base_path('resources/views/vendor/gateway'), - ], 'views'); - - //$this->mergeConfigFrom( $config,'gateway') - } - - /** - * Register the application services. - * - * @return void - */ - public function register() - { - $this->app->singleton('gateway', function () { - return new GatewayResolver(); - }); - - } -} diff --git a/JahanPay/JahanPay.php b/JahanPay/JahanPay.php deleted file mode 100644 index b6995735..00000000 --- a/JahanPay/JahanPay.php +++ /dev/null @@ -1,181 +0,0 @@ -amount = ($amount / 10); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - return redirect()->to($this->gateUrl.$this->refId()); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.jahanpay.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws JahanPayException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->requestpayment( - $this->config->get('gateway.jahanpay.api'), - $this->amount, - $this->getCallback(), - $this->transactionId(), - '' - ); - - } catch(\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (intval($response) >= 0) { - $this->refId = $response; - $this->transactionSetRefId(); - return true; - } - - $this->transactionFailed(); - $this->newLog($response, JahanPayException::$errors[$response]); - throw new JahanPayException($response); - } - - /** - * Check user payment - * - * @return bool - * - * @throws JahanPayException - */ - protected function userPayment() - { - $refId = Input::get('au'); - - if ($this->refId() != $refId) { - $this->transactionFailed(); - $this->newLog(-30, JahanPayException::$errors[-30]); - throw new JahanPayException(-30); - } - - return true; - } - - /** - * Verify user payment from bank server - * - * @return bool - * - * @throws JahanPayException - */ - protected function verifyPayment() - { - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->verification( - $this->config->get('gateway.jahanpay.api'), - $this->amount, - $this->refId - ); - - } catch(\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (intval($response) == 1) { - $this->transactionSucceed(); - $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - $this->transactionFailed(); - $this->newLog($response, JahanPayException::$errors[$response]); - throw new JahanPayException($response); - } -} diff --git a/JahanPay/JahanPayException.php b/JahanPay/JahanPayException.php deleted file mode 100644 index f6167535..00000000 --- a/JahanPay/JahanPayException.php +++ /dev/null @@ -1,31 +0,0 @@ - 'تراکنش انجام شده اما مبلغ مطابقت ندارد', - -31 => 'تراکنش انجام نشده است', - -30 => 'چنین تراکنشی موجود نیست', - -29 => 'آدرس کال بک خالی است', - -27 => 'آي پی شما مسدود است', - -26 => 'درگاه غیر فعال شده است', - -24 => 'مبلغ نادرست است', - -23 => 'مبلغ زیاد است', - -22 => 'مبلغ خیلی کم است -حداقل مبلغ ارسالی به درگاه 100 ت می باشد', - -21 => 'آي پی براي این درگاه نامعتبر است', - -20 => 'api نادرست است', - -6 => 'خطاي اتصال به بانک', - -9 => 'خطاي سیستمی', - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -} diff --git a/Mellat/Mellat.php b/Mellat/Mellat.php deleted file mode 100644 index 79d7a6af..00000000 --- a/Mellat/Mellat.php +++ /dev/null @@ -1,234 +0,0 @@ -amount = $amount; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $refId = $this->refId; - - return view('gateway::mellat-redirector')->with(compact('refId')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - $this->settleRequest(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.mellat.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws MellatException - */ - protected function sendPayRequest() - { - $dateTime = new DateTime(); - - $this->newTransaction(); - - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'amount' => $this->amount, - 'localDate' => $dateTime->format('Ymd'), - 'localTime' => $dateTime->format('His'), - 'additionalData' => '', - 'callBackUrl' => $this->getCallback(), - 'payerId' => 0, - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpPayRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - $response = explode(',', $response->return); - - if ($response[0] != '0') { - $this->transactionFailed(); - $this->newLog($response[0], MellatException::$errors[$response[0]]); - throw new MellatException($response[0]); - } - $this->refId = $response[1]; - $this->transactionSetRefId(); - } - - /** - * Check user payment - * - * @return bool - * - * @throws MellatException - */ - protected function userPayment() - { - $this->refId = Input::get('RefId'); - $this->trackingCode = Input::get('SaleReferenceId'); - $this->cardNumber = Input::get('CardHolderPan'); - $payRequestResCode = Input::get('ResCode'); - - if ($payRequestResCode == '0') { - return true; - } - - $this->transactionFailed(); - $this->newLog($payRequestResCode, @MellatException::$errors[$payRequestResCode]); - throw new MellatException($payRequestResCode); - } - - /** - * Verify user payment from bank server - * - * @return bool - * - * @throws MellatException - * @throws SoapFault - */ - protected function verifyPayment() - { - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'saleOrderId' => $this->transactionId(), - 'saleReferenceId' => $this->trackingCode() - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpVerifyRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->return != '0') { - $this->transactionFailed(); - $this->newLog($response->return, MellatException::$errors[$response->return]); - throw new MellatException($response->return); - } - - return true; - } - - /** - * Send settle request - * - * @return bool - * - * @throws MellatException - * @throws SoapFault - */ - protected function settleRequest() - { - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'saleOrderId' => $this->transactionId(), - 'saleReferenceId' => $this->trackingCode - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpSettleRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->return == '0' || $response->return == '45') { - $this->transactionSucceed(); - $this->newLog($response->return, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - $this->transactionFailed(); - $this->newLog($response->return, MellatException::$errors[$response->return]); - throw new MellatException($response->return); - } -} diff --git a/Mellat/MellatException.php b/Mellat/MellatException.php deleted file mode 100644 index 55f5ef3c..00000000 --- a/Mellat/MellatException.php +++ /dev/null @@ -1,62 +0,0 @@ - 'شماره کارت نامعتبر است', - 12 => 'موجودی کافی نیست', - 13 => 'رمز نادرست است', - 14 => 'تعداد دفعات وارد کردن رمز بیش از حد مجاز است', - 15 => 'کارت نامعتبر است', - 16 => 'دفعات برداشت وجه بیش از حد مجاز است', - 17 => 'کاربر از انجام تراکنش منصرف شده است', - 18 => 'تاریخ انقضای کارت گذشته است', - 19 => 'مبلغ برداشت وجه بیش از حد مجاز است', - 111 => 'صادر کننده کارت نامعتبر است', - 112 => 'خطای سوییچ صادر کننده کارت', - 113 => 'پاسخی از صادر کننده کارت دریافت نشد', - 114 => 'دارنده این کارت مجاز به انجام این تراکنش نیست', - 21 => 'پذیرنده نامعتبر است', - 23 => 'خطای امنیتی رخ داده است', - 24 => 'اطلاعات کاربری پذیرنده نامعتبر است', - 25 => 'مبلغ نامعتبر است', - 31 => 'پاسخ نامعتبر است', - 32 => 'فرمت اطلاعات وارد شده صحیح نمی‌باشد', - 33 => 'حساب نامعتبر است', - 34 => 'خطای سیستمی', - 35 => 'تاریخ نامعتبر است', - 41 => 'شماره درخواست تکراری است', - 42 => 'تراکنش Sale یافت نشد', - 43 => 'قبلا درخواست Verfiy داده شده است', - 44 => 'درخواست Verfiy یافت نشد', - 45 => 'تراکنش Settle شده است', - 46 => 'تراکنش Settle نشده است', - 47 => 'تراکنش Settle یافت نشد', - 48 => 'تراکنش Reverse شده است', - 49 => 'تراکنش Refund یافت نشد.', - 412 => 'شناسه قبض نادرست است', - 413 => 'شناسه پرداخت نادرست است', - 414=> 'سازمان صادر کننده قبض نامعتبر است', - 415 => 'زمان جلسه کاری به پایان رسیده است', - 416 => 'خطا در ثبت اطلاعات', - 417 => 'شناسه پرداخت کننده نامعتبر است', - 418 => 'اشکال در تعریف اطلاعات مشتری', - 419 => 'تعداد دفعات ورود اطلاعات از حد مجاز گذشته است', - 421 => 'IP نامعتبر است', - 51 => 'تراکنش تکراری است', - 54 => 'تراکنش مرجع موجود نیست', - 55 => 'تراکنش نامعتبر است', - 61 => 'خطا در واریز' - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -} diff --git a/Parsian/Parsian.php b/Parsian/Parsian.php deleted file mode 100644 index 2be94093..00000000 --- a/Parsian/Parsian.php +++ /dev/null @@ -1,191 +0,0 @@ -amount = intval($amount); - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $url = $this->gateUrl . $this->refId(); - - return view('gateway::parsian-redirector')->with(compact('url')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.parsian.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to parsian gateway - * - * @return bool - * - * @throws ParsianErrorException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $params = array( - 'pin' => $this->config->get('gateway.parsian.pin'), - 'amount' => $this->amount, - 'orderId' => $this->transactionId(), - 'callbackUrl' => $this->getCallback(), - 'authority' => 0, - 'status' => 1 - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PinPaymentRequest($params); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response !== false) { - $authority = $response->authority; - $status = $response->status; - - if ($authority && $status == 0) { - $this->refId = $authority; - $this->transactionSetRefId(); - return true; - } - - $errorMessage = ParsianResult::errorMessage($status); - $this->transactionFailed(); - $this->newLog($status, $errorMessage); - throw new ParsianErrorException($errorMessage, $status); - - } else { - $this->transactionFailed(); - $this->newLog(-1, 'خطا در اتصال به درگاه پارسیان'); - throw new ParsianErrorException('خطا در اتصال به درگاه پارسیان', -1); - } - } - - /** - * Verify payment - * - * @throws ParsianErrorException - */ - protected function verifyPayment() - { - if (!Input::has('au') && !Input::has('rs')) - throw new ParsianErrorException('درخواست غیر معتبر', -1); - - $authority = Input::get('au'); - $status = Input::get('rs'); - - if ($status != 0) { - $errorMessage = ParsianResult::errorMessage($status); - $this->newLog($status, $errorMessage); - throw new ParsianErrorException($errorMessage, $status); - } - - if ($this->refId != $authority) - throw new ParsianErrorException('تراکنشی یافت نشد', -1); - - $params = array( - 'pin' => $this->config->get('gateway.parsian.pin'), - 'authority' => $authority, - 'status' => 1 - ); - - try { - $soap = new SoapClient($this->serverUrl); - $result = $soap->PinPaymentEnquiry($params); - - } catch (\SoapFault $e) { - throw new ParsianErrorException($e->getMessage(), -1); - } - - if ($result === false || !isset($result->status)) - throw new ParsianErrorException('پاسخ دریافتی از بانک نامعتبر است.', -1); - - if ($result->status != 0) { - $errorMessage = ParsianResult::errorMessage($result->status); - $this->transactionFailed(); - $this->newLog($result->status, $errorMessage); - throw new ParsianErrorException($errorMessage, $result->status); - } - - $this->trackingCode = $authority; - $this->transactionSucceed(); - $this->newLog($result->status, ParsianResult::errorMessage($result->status)); - } -} diff --git a/Parsian/ParsianErrorException.php b/Parsian/ParsianErrorException.php deleted file mode 100644 index 3d6fbcc6..00000000 --- a/Parsian/ParsianErrorException.php +++ /dev/null @@ -1,7 +0,0 @@ - 'تراکنش با موفقیت انجام شد.', - 1 => 'خطا در انجام تراکنش', - 2 => 'بین عملیات وقفه افتاده است.', - 10 => 'شماره کارت نامعتبر است.', - 11 => 'کارت شما منقضی شده است', - 12 => 'رمز کارت وارد شده اشتباه است', - 13 => 'موجودی کارت شما کافی نیست', - 14 => 'مبلغ تراکنش بیش از سقف مجاز پذیرنده است.', - 15 => 'سقف مجاز روزانه شما کامل شده است.', - 18 => 'این تراکنش قبلا تایید شده است', - 20 => 'اطلاعات پذیرنده صحیح نیست.', - 21 => 'invalid authority', - 22 => 'اطلاعات پذیرنده صحیح نیست.', - 30 => 'عملیات قبلا با موفقیت انجام شده است.', - 34 => 'شماره تراکنش فروشنده درست نمی باشد.' - ); - - public static function errorMessage($errorId) - { - return isset(self::$errors[$errorId])?self::$errors[$errorId] : $errorId; - } -} diff --git a/Pasargad/Parser.php b/Pasargad/Parser.php deleted file mode 100644 index a6c73b1f..00000000 --- a/Pasargad/Parser.php +++ /dev/null @@ -1,86 +0,0 @@ - Input::get('iN'), - "invoiceDate" => Input::get('iD') - ]; - - foreach ($values as $key => $val) { - switch ($val['type']) { - case 'open': - array_push($hash_stack, $val['tag']); - break; - case 'close': - array_pop($hash_stack); - break; - case 'complete': - array_push($hash_stack, $val['tag']); - if(!isset($val['value'])){ - $val['value'] = $temp[$val['tag']]; - } - - eval("\$ret['" . implode($hash_stack, "']['") . "'] = '{$val['value']}';"); - array_pop($hash_stack); - break; - } - } - - return $ret['resultObj']; - } - - - /** - * CURL POST TO HTTPS - * - * @param $fields_arr - * @param $url - * @return mixed - */ - public static function post2https($fields_arr, $url) - { - $fields_string = ''; - //url-ify the data for the POST - foreach ($fields_arr as $key => $value) { - $fields_string .= $key . '=' . $value . '&'; - } - $fields_string = substr($fields_string, 0, -1); - - //open connection - $ch = curl_init(); - - //set the url, number of POST vars, POST data - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, count($fields_arr)); - curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - - //execute post - $res = curl_exec($ch); - - //close connection - curl_close($ch); - return $res; - } -} diff --git a/Pasargad/Pasargad.php b/Pasargad/Pasargad.php deleted file mode 100644 index 53e25305..00000000 --- a/Pasargad/Pasargad.php +++ /dev/null @@ -1,149 +0,0 @@ -amount = intval($amount); - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - - $processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile); - - $url = $this->gateUrl; - $redirectUrl = $this->getCallback(); - $invoiceNumber = $this->transactionId(); - $amount = $this->amount; - $terminalCode = $this->config->get('gateway.pasargad.terminalId'); - $merchantCode = $this->config->get('gateway.pasargad.merchantId'); - $timeStamp = date("Y/m/d H:i:s"); - $invoiceDate = date("Y/m/d H:i:s"); - $action = 1003; - $data = "#". $merchantCode ."#". $terminalCode ."#". $invoiceNumber ."#". $invoiceDate ."#". $amount ."#". $redirectUrl ."#". $action ."#". $timeStamp ."#"; - $data = sha1($data,true); - $data = $processor->sign($data); // امضاي ديجيتال - $sign = base64_encode($data); // base64_encode - - return view('gateway::pasargad-redirector')->with(compact('url','redirectUrl','invoiceNumber','invoiceDate','amount','terminalCode','merchantCode','timeStamp','action','sign')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.pasargad.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to parsian gateway - * - * @return bool - * - * @throws ParsianErrorException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - } - - /** - * Verify payment - * - * @throws ParsianErrorException - */ - protected function verifyPayment() - { - $fields = array( - 'invoiceUID' => $_GET['tref'] - ); - - $result = Parser::post2https($fields, $this->checkTransactionUrl); - $array = Parser::makeXMLTree($result); - - - if ($array['result'] != "True") { - $this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT); - $this->transactionFailed(); - throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1); - } - - $this->refId = $array['transactionReferenceID']; - $this->transactionSetRefId(); - - $this->trackingCode = $array['traceNumber']; - $this->transactionSucceed(); - $this->newLog($array['result'], Enum::TRANSACTION_SUCCEED_TEXT); - } -} diff --git a/Pasargad/PasargadErrorException.php b/Pasargad/PasargadErrorException.php deleted file mode 100644 index 205e56bd..00000000 --- a/Pasargad/PasargadErrorException.php +++ /dev/null @@ -1,7 +0,0 @@ -= 0; $i--) { - $digit = ord($data{$i}); - $part_res = bcmul($digit, $radix); - $result = bcadd($result, $part_res); - $radix = bcmul($radix, $base); - } - return $result; - } - - public static function number_to_binary($number, $blocksize) - { - $base = "256"; - $result = ""; - $div = $number; - while ($div > 0) { - $mod = bcmod($div, $base); - $div = bcdiv($div, $base); - $result = chr($mod) . $result; - } - return str_pad($result, $blocksize, "\x00", STR_PAD_LEFT); - } -} \ No newline at end of file diff --git a/Pasargad/RSAProcessor.php b/Pasargad/RSAProcessor.php deleted file mode 100644 index 05cee320..00000000 --- a/Pasargad/RSAProcessor.php +++ /dev/null @@ -1,72 +0,0 @@ -modulus = RSA::binary_to_number(base64_decode($xmlObj->Modulus)); - $this->public_key = RSA::binary_to_number(base64_decode($xmlObj->Exponent)); - $this->private_key = RSA::binary_to_number(base64_decode($xmlObj->D)); - $this->key_length = strlen(base64_decode($xmlObj->Modulus)) * 8; - } - - public function getPublicKey() - { - return $this->public_key; - } - - public function getPrivateKey() - { - return $this->private_key; - } - - public function getKeyLength() - { - return $this->key_length; - } - - public function getModulus() - { - return $this->modulus; - } - - public function encrypt($data) - { - return base64_encode(RSA::rsa_encrypt($data, $this->public_key, $this->modulus, $this->key_length)); - } - - public function dencrypt($data) - { - return RSA::rsa_decrypt($data, $this->private_key, $this->modulus, $this->key_length); - } - - public function sign($data) - { - return RSA::rsa_sign($data, $this->private_key, $this->modulus, $this->key_length); - } - - public function verify($data) - { - return RSA::rsa_verify($data, $this->public_key, $this->modulus, $this->key_length); - } -} - -class RSAKeyType -{ - const XMLFile = 0; - const XMLString = 1; -} \ No newline at end of file diff --git a/Pasargad/certificate.xml b/Pasargad/certificate.xml deleted file mode 100644 index 2cf89da5..00000000 --- a/Pasargad/certificate.xml +++ /dev/null @@ -1 +0,0 @@ -tCZiqDS5BVQQZDBUYbyeoP4rENN4mX5FZJjjMNfGbyzfzH45RY2/YsMaY0yI1jMCOpukvkUyl153tcn0LXhMCDdsEhhZPoKbPUGMniKtFGjs18rv/b5FFUUW1utgwoL8+WJqjOqhQGgvbja63X9+WMFP0nM3d8yudn9C/X55KyM=AQAB

5HXvmU4IfqUG2jFLSqi/BMEQ3x1NsUDvx3zN5O1p9yLLspJ4sqAt4RUkxzcGodYgBSdXsR9IGcPwjQfbx3a7nQ==

yd2hDCF/5Zqtz9DXjY1NRYGvBjTS4AQn83ERR46Y5eBSnLjpVjv6gPfARuhsUP44nikrQPvwPnjxQcOhJaOlvw==ztuqUplBP8qU5cN0dOlN7DQT3rFdw30Unv/2Pa5qIAc1gT72YmZ+pCrM3kSIkMicvY3d7NZyJkIv8MKI0ZZEUQ==QFLJ5YarLWubZPQEK4vSCornTY/5ff51CIKH4ghTOjS/vkbBu4PDL+NCNpYLJcfMHMG7kap2BEIfhjgjGk5KGw==WE6TqpcexQJwt9Mnp1FbeLtarBcFkXVdBauouFKHcbHCfQjA3IjUrGTxgSO74O/4QSKqaF2gnlL6GI7gKuGbzQ==czYtWDfHsFGv3fNOs+cGaB3E+xDTiw7HYGuquJz2qjk/s69x/zqFEKuIH8Ndq+eZYFQUCx+EGGxxENDkmYPa0z8wbfFI6JEHpxaLmQfpkkbSL1BJIp9Z5BNM2gy6jJqgbWwQPcN/4jpiMefHZWAqhMKqenUu1KIq1ZX6Bz5xKYk=
\ No newline at end of file diff --git a/Payline/Payline.php b/Payline/Payline.php deleted file mode 100644 index bcfdf798..00000000 --- a/Payline/Payline.php +++ /dev/null @@ -1,193 +0,0 @@ -amount = $amount; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - return redirect()->to($this->gateUrl . $this->refId); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.payline.callback-url'); - - return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()])); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws PaylineSendException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $fields = array( - 'api' => $this->config->get('gateway.payline.api'), - 'amount' => $this->amount, - 'redirect' => $this->getCallback(), - ); - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $this->serverUrl); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $response = curl_exec($ch); - curl_close($ch); - - if (is_numeric($response) && $response > 0) { - $this->refId = $response; - $this->transactionSetRefId(); - - return true; - } - - $this->transactionFailed(); - $this->newLog($response, PaylineSendException::$errors[$response]); - throw new PaylineSendException($response); - } - - /** - * Check user payment with GET data - * - * @return bool - * - * @throws PaylineReceiveException - */ - protected function userPayment() - { - $this->refIf = Input::get('id_get'); - $trackingCode = Input::get('trans_id'); - - if (is_numeric($trackingCode) && $trackingCode > 0) { - $this->trackingCode = $trackingCode; - return true; - } - - $this->transactionFailed(); - $this->newLog(-4, PaylineReceiveException::$errors[-4]); - throw new PaylineReceiveException(-4); - } - - /** - * Verify user payment from zarinpal server - * - * @return bool - * - * @throws PaylineReceiveException - */ - protected function verifyPayment() - { - $fields = array( - 'api' => $this->config->get('gateway.payline.api'), - 'id_get' => $this->refId(), - 'trans_id' => $this->trackingCode() - ); - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $this->serverVerifyUrl); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $response = curl_exec($ch); - curl_close($ch); - - if ($response == 1) { - $this->transactionSucceed(); - $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT); - - return true; - } - - $this->transactionFailed(); - $this->newLog($response, PaylineReceiveException::$errors[$response]); - throw new PaylineReceiveException($response); - } -} diff --git a/Payline/PaylineReceiveException.php b/Payline/PaylineReceiveException.php deleted file mode 100644 index c281c35a..00000000 --- a/Payline/PaylineReceiveException.php +++ /dev/null @@ -1,22 +0,0 @@ - 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', - -2 => 'trans_id ارسال شده معتبر نمی‌باشد.', - -3 => 'id_get ارسالی معتبر نمی باشد.', - -4 => 'چنین تراکنشی در سیستم وجود ندارد و یا موفقیت آمیز نبوده است.' - ); - - public function __construct($errorId) - { - $this->errorId = $errorId; - - parent::__construct(@self::$errors[$errorId].' #'.$errorId, $errorId); - } -} diff --git a/Payline/PaylineSendException.php b/Payline/PaylineSendException.php deleted file mode 100644 index f5a8a7c5..00000000 --- a/Payline/PaylineSendException.php +++ /dev/null @@ -1,22 +0,0 @@ - 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', - -2 => 'مقدار amount داده عددی نمی باشد و یا کمتر از 1000 ریال است.', - -3 => 'مقدار redirect رشته null است.', - -4 => 'درگاهی با اطلاعات ارسالی شما یافت نشد و یا در حالت انتظار می باشد.' - ); - - public function __construct($errorId) - { - $this->errorId = $errorId; - - parent::__construct(@self::$errors[$errorId].' #'.$errorId, $errorId); - } -} diff --git a/PortAbstract.php b/PortAbstract.php deleted file mode 100644 index 90241be4..00000000 --- a/PortAbstract.php +++ /dev/null @@ -1,317 +0,0 @@ -db = app('db'); - } - - /** bootstraper */ - function boot(){ - - } - - function setConfig($config) - { - $this->config = $config; - } - - /** - * @return mixed - */ - function getTable() - { - return $this->db->table($this->config->get('gateway.table')); - } - - /** - * @return mixed - */ - function getLogTable() - { - return $this->db->table($this->config->get('gateway.table') . '_logs'); - } - - /** - * Get port id, $this->port - * - * @return int - */ - function getPortName() - { - return $this->portName; - } - - /** - * Get port id, $this->port - * - * @return int - */ - function setPortName($name) - { - $this->portName = $name; - } - - /** - * Return card number - * - * @return string - */ - function cardNumber() - { - return $this->cardNumber; - } - - /** - * Return tracking code - */ - function trackingCode() - { - return $this->trackingCode; - } - - /** - * Get transaction id - * - * @return int|null - */ - function transactionId() - { - return $this->transactionId; - } - - /** - * Return reference id - */ - function refId() - { - return $this->refId; - } - - /** - * Sets price - * @param $price - * @return mixed - */ - function price($price) - { - return $this->set($price); - } - - /** - * Return result of payment - * If result is done, return true, otherwise throws an related exception - * - * This method must be implements in child class - * - * @param object $transaction row of transaction in database - * - * @return $this - */ - function verify($transaction) - { - $this->transaction = $transaction; - $this->transactionId = intval($transaction->id); - $this->amount = intval($transaction->price); - $this->refId = $transaction->ref_id; - } - - function getTimeId() - { - $uid = time(); - while ($this->getTable()->whereId($uid)->first()) - $uid = time(); - return $uid; - } - - /** - * Insert new transaction to poolport_transactions table - * - * @return int last inserted id - */ - protected function newTransaction() - { - $uid = $this->getTimeId(); - $this->transactionId = $this->getTable()->insert([ - 'id' => $uid, - 'port' => $this->getPortName(), - 'price' => $this->amount, - 'status' => Enum::TRANSACTION_INIT, - 'ip' => Request::getClientIp(), - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now(), - ]) ? $uid : null; - - return $this->transactionId; - } - - /** - * Commit transaction - * Set status field to success status - * - * @return bool - */ - protected function transactionSucceed() - { - return $this->getTable()->whereId($this->transactionId)->update([ - 'status' => Enum::TRANSACTION_SUCCEED, - 'tracking_code' => $this->trackingCode, - 'card_number' => $this->cardNumber, - 'payment_date' => Carbon::now(), - 'updated_at' => Carbon::now(), - ]); - } - - /** - * Failed transaction - * Set status field to error status - * - * @return bool - */ - protected function transactionFailed() - { - return $this->getTable()->whereId($this->transactionId)->update([ - 'status' => Enum::TRANSACTION_FAILED, - 'updated_at' => Carbon::now(), - ]); - } - - /** - * Update transaction refId - * - * @return void - */ - protected function transactionSetRefId() - { - return $this->getTable()->whereId($this->transactionId)->update([ - 'ref_id' => $this->refId, - 'updated_at' => Carbon::now(), - ]); - - } - - /** - * New log - * - * @param string|int $statusCode - * @param string $statusMessage - */ - protected function newLog($statusCode, $statusMessage) - { - return $this->getLogTable()->insert([ - 'transaction_id' => $this->transactionId, - 'result_code' => $statusCode, - 'result_message' => $statusMessage, - 'log_date' => Carbon::now(), - ]); - } - - /** - * Add query string to a url - * - * @param string $url - * @param array $query - * @return string - */ - protected function makeCallback($url, array $query) - { - return $this->url_modify(array_merge($query, ['_token' => csrf_token()]), url($url)); - } - - /** - * manipulate the Current/Given URL with the given parameters - * @param $changes - * @param $url - * @return string - */ - protected function url_modify($changes, $url) - { - // Parse the url into pieces - $url_array = parse_url($url); - - // The original URL had a query string, modify it. - if (!empty($url_array['query'])) { - parse_str($url_array['query'], $query_array); - $query_array = array_merge($query_array, $changes); - } // The original URL didn't have a query string, add it. - else { - $query_array = $changes; - } - - return (!empty($url_array['scheme']) ? $url_array['scheme'] . '://' : null) . - (!empty($url_array['host']) ? $url_array['host'] : null) . - $url_array['path'] . '?' . http_build_query($query_array); - } -} diff --git a/PortInterface.php b/PortInterface.php deleted file mode 100644 index 70dbfd77..00000000 --- a/PortInterface.php +++ /dev/null @@ -1,89 +0,0 @@ -portId - * - * @return int - */ - public function getPortName(); - - /** - * Get transaction id - * - * @return int|null - */ - public function transactionId(); - - /** - * Return card number - * - * @return string - */ - public function cardNumber(); - - /** - * Sets callback url - * - * @return string - */ - public function setCallback($url); - - /** - * Gets callback url - * - * @return string - */ - public function getCallback(); - - /** - * This method use for redirect to port - * - * @return mixed - */ - public function redirect(); - - /** - * Return result of payment - * If result is done, return true, otherwise throws an related exception - * - * @param object $transaction row of transaction in database - * - * @return $this - */ - public function verify($transaction); -} diff --git a/Sadad/Sadad.php b/Sadad/Sadad.php deleted file mode 100644 index 55fd0322..00000000 --- a/Sadad/Sadad.php +++ /dev/null @@ -1,203 +0,0 @@ -amount = intval($amount); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $form = $this->form; - - return view('gateway::sadad-redirector')->with(compact('form')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.sadad.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws SadadException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $this->form = ''; - - try { - $soap = new SoapClient($this->serverUrl); - - $response = $soap->PaymentUtility( - $this->config->get('gateway.sadad.merchant'), - $this->amount, - $this->transactionId(), - $this->config->get('gateway.sadad.transactionKey'), - $this->config->get('gateway.sadad.terminalId'), - $this->getCallback() - ); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (!isset($response['RequestKey']) || !isset($response['PaymentUtilityResult'])) { - $this->newLog(SadadResult::INVALID_RESPONSE_CODE, SadadResult::INVALID_RESPONSE_MESSAGE); - throw new SadadException(SadadResult::INVALID_RESPONSE_MESSAGE, SadadResult::INVALID_RESPONSE_CODE); - } - - $this->form = $response['PaymentUtilityResult']; - - $this->refId = $response['RequestKey']; - - $this->transactionSetRefId(); - } - - /** - * Verify user payment from bank server - * - * @throws SadadException - */ - protected function verifyPayment() - { - try { - $soap = new SoapClient($this->serverUrl); - - $result = $soap->CheckRequestStatusResult( - $this->transactionId(), - $this->config->get('gateway.sadad.merchant'), - $this->config->get('gateway.sadad.terminalId'), - $this->config->get('gateway.sadad.transactionKey'), - $this->refId(), - $this->amount - ); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (empty($result) || !isset($result->AppStatusCode)) - throw new SadadException('در دریافت اطلاعات از بانک خطایی رخ داده است.'); - - $statusResult = strval($result->AppStatusCode); - $appStatus = strtolower($result->AppStatusDescription); - - $message = $this->getMessage($statusResult, $appStatus); - - $this->newLog($statusResult, $message['fa']); - - if ($statusResult == 0 && $appStatus === 'commit') { - $this->trackingCode = $result->TraceNo; - $this->cardNumber = $result->CustomerCardNumber; - $this->transactionSucceed(); - } else { - $this->transactionFailed(); - throw new SadadException($message['fa'], $statusResult); - } - } - - /** - * Register error to error list - * - * @param int $code - * @param string $message - * - * @return array|null - * - * @throws SadadException - */ - private function getMessage($code, $message) - { - $result = SadadResult::codeResponse($code, $message); - if (!$result) { - $result = array( - 'code' => SadadResult::UNKNOWN_CODE, - 'message' => SadadResult::UNKNOWN_MESSAGE, - 'fa' => 'خطای ناشناخته', - 'en' => 'Unknown Error', - 'retry' => false - ); - } - - return $result; - } -} diff --git a/Sadad/SadadException.php b/Sadad/SadadException.php deleted file mode 100644 index 25f7e734..00000000 --- a/Sadad/SadadException.php +++ /dev/null @@ -1,8 +0,0 @@ - SadadResult::ERROR_CONNECT, - 'message'=>SadadResult::ERROR_CONNECT_MESSAGE, - 'fa' => 'خطا در اتصال به درگاه سداد', - 'en' => 'Error in connect to sadad', - 'retry' => false - ), - array( - 'code' => SadadResult::INVALID_RESPONSE_CODE, - 'message'=>SadadResult::INVALID_RESPONSE_MESSAGE, - 'fa' => 'جواب نامعتبر', - 'en' => 'Invalid Response', - 'retry' => false - ), - array( - 'code' => -1, - 'message'=>'not_set', - 'fa' => 'نتیجه استعلام نامعلوم و یا کاربر از انجام تراکنش منصرف شده است.', - 'en' => 'Result of the Inquiry Unknown or Customer Cancellation', - 'retry' => true, - ), - array( - 'code' => -1, - 'message'=>'not_exist', - 'fa' => 'پارامترهای ارسالی صحیح نیست و یا تراکنش در سیستم وجود ندارد.', - 'en' => 'Parameters passed is incorrect or there is no transaction in the system.', - 'retry' => false, - ), - array( - 'code' => 9000, - 'message'=>'incomplet_info', - 'fa' => 'درخواست تراکنش در سیستم ثبت شده ولی تراکنش هنوز شروع نشده است.', - 'en' => 'Transaction request registered in the system, but the transaction has not started yet.', - 'retry' => true, - ), - array( - 'code' => 9001, - 'message'=>'wait_for_send_and_get_response', - 'fa' => 'تراکنش در سیستم ثبت شده و پیام مالی به سیستم بانک ارسال شده است اما هنوز پاسخی دریافت نشده است.', - 'en' => 'Financial transaction log and the message has been sent to the banking system but not yet received.', - 'retry' => true, - ), - array( - 'code' => 9004, - 'message'=>'wait_for_reversal', - 'fa' => 'سیستم در حال تلاش جهت برگشت تراکنش خرید است.', - 'en' => 'The system is trying to buy back transaction.', - 'retry' => true, - ), - array( - 'code' => 9005, - 'message'=>'wait_for_reversal_advise', - 'fa' => 'سیستم در حال تلاش جهت برگشت تراکنش خرید است.', - 'en' => 'The system is trying to buy back transaction.', - 'retry' => true, - ), - array( - 'code' => 9006, - 'message'=>'reversaled', - 'fa' => 'تراکنش ناموفق بوده و مبلغ با موفقیت به حساب مشتری برگشت خورده است', - 'en' => 'Purchase operation was unsuccessful and The amount is returned successfully to the client`s account', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'failed', - 'fa' => 'عملیات خرید نا موفق بوده است', - 'en' => 'Purchase operation was unsuccessful', - 'retry' => false, - ), - array( - 'code' => 56, - 'message'=>'failed', - 'fa' => 'کارت نامعتبر است.', - 'en' => 'Card Not Effective', - 'retry' => false, - ), - array( - 'code' => 51, - 'message'=>'failed', - 'fa' => 'مبلغ درخواستی از موجودی حساب شما, بیشتر است.حداقل مانده حساب شما پس از عملیات پرداخت باید 100,000 ریال باشد.', - 'en' => 'Inventory shortage', - 'retry' => false, - ), - array( - 'code' => 55, - 'message'=>'failed', - 'fa' => 'رمز کارت صحیح نمی باشد لطفا مجددا, سعی کنید.', - 'en' => 'Incorrect Pin', - 'retry' => false, - ), - array( - 'code' => 9008, - 'message'=>'check_status', - 'fa' => 'در هنگام انجام عملیات CheckStatus مشکلی رخ داده است.', - 'en' => 'CheckStatus operations when a problem has occurred.', - 'retry' => true, - ), - array( - 'code' => 9009, - 'message'=>'async_get_response', - 'fa' => 'سیستم در حال تلاش برای دریافت جواب عملیات بانکی است.', - 'en' => 'The system is trying to Get answers to banking operations.', - 'retry' => true, - ), - array( - 'code' => 9010, - 'message'=>'wait_for_reversal_auto', - 'fa' => 'تراکنش به لیست تراکنش های برگشت خودکار اضافه شده است و در انتظار برگشت می باشد.', - 'en' => 'The transaction is automatically added to the list of back transactions and is expected to return.', - 'retry' => true, - ), - array( - 'code' => 9011, - 'message'=>'pendingcurrenttransaction', - 'fa' => 'تراکنش برگشت خرید ارسال شده است اما پاسخ دریافت شده قطعی نیست و تراکنش در لیست تراکنش های معوق می باشد و نتیجه عملیات بانکی ظرف 24 ساعت آینده مشخص خواهد شد.', - 'en' => 'Back purchase transaction has been sent but not conclusive answer has been received and the transaction is on the list of pending transactions and banking operations will be determined within the next 24 hours.', - 'retry' => false, - ), - array( - 'code' => 9012, - 'message'=>'pendingtransactionreversed', - 'fa' => 'تراکنش ناموفق - نتیجه تراکنش معوق بعد از 24 ساعت مشخص می شود', - 'en' => 'Failed Transaction - result of outstanding transactions will be determined after 24 hours', - 'retry' => false, - ), - array( - 'code' => 2, - 'message'=>'request_done', - 'fa' => 'تراکنش موفق', - 'en' => 'Successful Transaction', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'pendingtransactioncommited', - 'fa' => 'تایید پرداخت - نتیجه تراکنش معوق بعد از 24 ساعت مشخص می شود', - 'en' => 'Verify Payment - result of outstanding transactions will be determined after 24 hours', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'commit', - 'fa' => 'تایید پرداخت', - 'en' => 'Verify Payment', - 'retry' => false, - ), - ); - - /** - * return response - * - * @param int $code - * @param string $message - * @return null - */ - public static function codeResponse($code,$message) - { - $code = intval($code); - - foreach(self::$results as $v) { - if ($v['message'] == $message && $v['code'] == $code) - return $v; - } - - return null; - } -} diff --git a/Zarinpal/Zarinpal.php b/Zarinpal/Zarinpal.php deleted file mode 100644 index b1111b93..00000000 --- a/Zarinpal/Zarinpal.php +++ /dev/null @@ -1,318 +0,0 @@ -setServer(); - } - - /** - * {@inheritdoc} - */ - public function set($amount) - { - $this->amount = ($amount / 10); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - switch ($this->config->get('gateway.zarinpal.type')) { - case 'zarin-gate': - return redirect()->to(str_replace('$Authority', $this->refId, $this->zarinGateUrl)); - break; - - case 'normal': - default: - return redirect()->to($this->gateUrl . $this->refId); - break; - } - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.zarinpal.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws ZarinpalException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $fields = array( - 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'), - 'Amount' => $this->amount, - 'CallbackURL' => $this->getCallback(), - 'Description' => $this->description ? $this->description : $this->config->get('gateway.zarinpal.description', ''), - 'Email' => $this->email ? $this->email :$this->config->get('gateway.zarinpal.email', ''), - 'Mobile' => $this->mobileNumber ? $this->mobileNumber : $this->config->get('gateway.zarinpal.mobile', ''), - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PaymentRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->Status != 100) { - $this->transactionFailed(); - $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]); - throw new ZarinpalException($response->Status); - } - - $this->refId = $response->Authority; - $this->transactionSetRefId(); - } - - /** - * Check user payment with GET data - * - * @return bool - * - * @throws ZarinpalException - */ - protected function userPayment() - { - $this->authority = Input::get('Authority'); - $status = Input::get('Status'); - - if ($status == 'OK') { - return true; - } - - $this->transactionFailed(); - $this->newLog(-22, ZarinpalException::$errors[-22]); - throw new ZarinpalException(-22); - } - - /** - * Verify user payment from zarinpal server - * - * @return bool - * - * @throws ZarinpalException - */ - protected function verifyPayment() - { - - $fields = array( - 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'), - 'Authority' => $this->refId, - 'Amount' => $this->amount, - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PaymentVerification($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->Status != 100 && $response->Status != 101) { - $this->transactionFailed(); - $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]); - throw new ZarinpalException($response->Status); - } - - $this->trackingCode = $response->RefID; - $this->transactionSucceed(); - $this->newLog($response->Status, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - /** - * Set server for soap transfers data - * - * @return void - */ - protected function setServer() - { - $server = $this->config->get('gateway.zarinpal.server', 'germany'); - switch ($server) { - case 'iran': - $this->serverUrl = $this->iranServer; - break; - - case 'test': - $this->serverUrl = $this->sandboxServer; - $this->gateUrl = $this->sandboxGateUrl; - break; - - case 'germany': - default: - $this->serverUrl = $this->germanyServer; - break; - } - } - - - /** - * Set Description - * - * @param $description - * @return void - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * Set Payer Email Address - * - * @param $email - * @return void - */ - public function setEmail($email) - { - $this->email = $email; - } - - /** - * Set Payer Mobile Number - * - * @param $number - * @return void - */ - public function setMobileNumber($number) - { - $this->mobileNumber = $number; - } -} diff --git a/Zarinpal/ZarinpalException.php b/Zarinpal/ZarinpalException.php deleted file mode 100644 index 2951e3d9..00000000 --- a/Zarinpal/ZarinpalException.php +++ /dev/null @@ -1,29 +0,0 @@ - 'اطلاعات ارسال شده ناقص است.', - -2 => 'IP و یا مرچنت کد پذیرنده صحیح نیست', - -3 => 'رقم باید بالای 100 تومان باشد', - -4 => 'سطح پذیرنده پایین تر از سطح نقره ای است', - -11 => 'درخواست مورد نظر یافت نشد', - -21 => 'هیچ نوع عملیات مالی برای این تراکنش یافت نشد', - -22 => 'تراکنش ناموفق میباشد', - -33 => 'رقم تراکنش با رقم پرداخت شده مطابقت ندارد', - -54 => 'درخواست مورد نظر آرشیو شده', - 100 => 'عملیات با موفقیت انجام شد', - 101 => 'عملیات پرداخت با موفقیت انجام شده ولی قبلا عملیات PaymentVertification بر روی این تراکنش انجام شده است', - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -} diff --git a/src/Exceptions/ConfigFileNotFoundException.php b/src/Exceptions/ConfigFileNotFoundException.php index dc812f05..cf5d05fc 100644 --- a/src/Exceptions/ConfigFileNotFoundException.php +++ b/src/Exceptions/ConfigFileNotFoundException.php @@ -2,7 +2,7 @@ namespace Larabookir\Gateway\Exceptions; -class ConfigFileNotFoundException extends \Exception { - +class ConfigFileNotFoundException extends GatewayException { + protected $code=-105; protected $message='فایل تنظیمات یافت نشد.'; } diff --git a/src/Exceptions/InvalidRequestException.php b/src/Exceptions/InvalidRequestException.php index 8f047c7a..8b05fab7 100644 --- a/src/Exceptions/InvalidRequestException.php +++ b/src/Exceptions/InvalidRequestException.php @@ -2,7 +2,8 @@ namespace Larabookir\Gateway\Exceptions; -class InvalidRequestException extends \Exception { +class InvalidRequestException extends GatewayException { + protected $code=-104; protected $message='اطلاعات بازگشتی از بانک صحیح نمی باشد. '; } diff --git a/src/Exceptions/NotFoundTransactionException.php b/src/Exceptions/NotFoundTransactionException.php index 8f52e1ff..293d028f 100644 --- a/src/Exceptions/NotFoundTransactionException.php +++ b/src/Exceptions/NotFoundTransactionException.php @@ -2,7 +2,8 @@ namespace Larabookir\Gateway\Exceptions; -class NotFoundTransactionException extends \Exception +class NotFoundTransactionException extends GatewayException { + protected $code=-103; protected $message = 'چنین رکورد پرداختی موجود نمی باشد.'; } diff --git a/src/Exceptions/PortNotFoundException.php b/src/Exceptions/PortNotFoundException.php index e903151a..9719d89d 100644 --- a/src/Exceptions/PortNotFoundException.php +++ b/src/Exceptions/PortNotFoundException.php @@ -2,6 +2,8 @@ namespace Larabookir\Gateway\Exceptions; -class PortNotFoundException extends \Exception { +class PortNotFoundException extends GatewayException { + + protected $code=-102; protected $message='درگاهی برای تراکنش مورد نظر در سایت یافت نشد.'; } diff --git a/src/Exceptions/RetryException.php b/src/Exceptions/RetryException.php index 35776868..143cc0ca 100644 --- a/src/Exceptions/RetryException.php +++ b/src/Exceptions/RetryException.php @@ -4,7 +4,8 @@ /** * This exception when throws, user try to submit a payment request who submitted before */ -class RetryException extends \Exception +class RetryException extends GatewayException { + protected $code=-101; protected $message = 'نتیجه تراکنش قبلا از طرف بانک اعلام گردیده.'; } diff --git a/src/JahanPay/JahanPayException.php b/src/JahanPay/JahanPayException.php index f9491d4e..f6167535 100644 --- a/src/JahanPay/JahanPayException.php +++ b/src/JahanPay/JahanPayException.php @@ -2,7 +2,9 @@ namespace Larabookir\Gateway\JahanPay; -class JahanPayException extends \Exception +use Larabookir\Gateway\Exceptions\BankException; + +class JahanPayException extends BankException { public static $errors = array( -32 => 'تراکنش انجام شده اما مبلغ مطابقت ندارد', diff --git a/src/LICENSE b/src/LICENSE index 24947d2f..d48c581e 100644 --- a/src/LICENSE +++ b/src/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 PoolPort +Copyright (c) 2016 Larabook Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/Mellat/MellatException.php b/src/Mellat/MellatException.php index aaeebf86..55f5ef3c 100644 --- a/src/Mellat/MellatException.php +++ b/src/Mellat/MellatException.php @@ -2,7 +2,9 @@ namespace Larabookir\Gateway\Mellat; -class MellatException extends \Exception +use Larabookir\Gateway\Exceptions\BankException; + +class MellatException extends BankException { public static $errors = array( 11 => 'شماره کارت نامعتبر است', diff --git a/src/Parsian/ParsianErrorException.php b/src/Parsian/ParsianErrorException.php index 538f14f1..3d6fbcc6 100644 --- a/src/Parsian/ParsianErrorException.php +++ b/src/Parsian/ParsianErrorException.php @@ -2,4 +2,6 @@ namespace Larabookir\Gateway\Parsian; -class ParsianErrorException extends \Exception {} +use Larabookir\Gateway\Exceptions\BankException; + +class ParsianErrorException extends BankException {} diff --git a/src/Pasargad/PasargadErrorException.php b/src/Pasargad/PasargadErrorException.php index a3957fe9..205e56bd 100644 --- a/src/Pasargad/PasargadErrorException.php +++ b/src/Pasargad/PasargadErrorException.php @@ -2,4 +2,6 @@ namespace Larabookir\Gateway\Pasargad; -class PasargadErrorException extends \Exception {} +use Larabookir\Gateway\Exceptions\BankException; + +class PasargadErrorException extends BankException {} diff --git a/src/Payline/PaylineReceiveException.php b/src/Payline/PaylineReceiveException.php index 201b8c90..c281c35a 100644 --- a/src/Payline/PaylineReceiveException.php +++ b/src/Payline/PaylineReceiveException.php @@ -2,7 +2,9 @@ namespace Larabookir\Gateway\Payline; -class PaylineReceiveException extends \Exception +use Larabookir\Gateway\Exceptions\BankException; + +class PaylineReceiveException extends BankException { public static $errors = array( -1 => 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', diff --git a/src/Payline/PaylineSendException.php b/src/Payline/PaylineSendException.php index 0416b50a..f5a8a7c5 100644 --- a/src/Payline/PaylineSendException.php +++ b/src/Payline/PaylineSendException.php @@ -2,7 +2,9 @@ namespace Larabookir\Gateway\Payline; -class PaylineSendException extends \Exception +use Larabookir\Gateway\Exceptions\BankException; + +class PaylineSendException extends BankException { public static $errors = array( -1 => 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', diff --git a/src/Sadad/Sadad.php b/src/Sadad/Sadad.php index 2bf1a052..55fd0322 100644 --- a/src/Sadad/Sadad.php +++ b/src/Sadad/Sadad.php @@ -109,7 +109,7 @@ protected function sendPayRequest() $this->transactionId(), $this->config->get('gateway.sadad.transactionKey'), $this->config->get('gateway.sadad.terminalId'), - $this->getCallback(), + $this->getCallback() ); } catch (\SoapFault $e) { diff --git a/src/Sadad/SadadException.php b/src/Sadad/SadadException.php index 02701819..25f7e734 100644 --- a/src/Sadad/SadadException.php +++ b/src/Sadad/SadadException.php @@ -3,4 +3,6 @@ namespace Larabookir\Gateway\Sadad; -class SadadException extends \Exception {} +use Larabookir\Gateway\Exceptions\BankException; + +class SadadException extends BankException {} diff --git a/src/Zarinpal/ZarinpalException.php b/src/Zarinpal/ZarinpalException.php index 76dd5fb0..2951e3d9 100644 --- a/src/Zarinpal/ZarinpalException.php +++ b/src/Zarinpal/ZarinpalException.php @@ -2,7 +2,9 @@ namespace Larabookir\Gateway\Zarinpal; -class ZarinpalException extends \Exception +use Larabookir\Gateway\Exceptions\BankException; + +class ZarinpalException extends BankException { public static $errors = array( -1 => 'اطلاعات ارسال شده ناقص است.', diff --git a/src/src/Exceptions/BankException.php b/src/src/Exceptions/BankException.php deleted file mode 100644 index 9bb645be..00000000 --- a/src/src/Exceptions/BankException.php +++ /dev/null @@ -1,11 +0,0 @@ -amount = ($amount / 10); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - return redirect()->to($this->gateUrl.$this->refId()); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.jahanpay.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws JahanPayException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->requestpayment( - $this->config->get('gateway.jahanpay.api'), - $this->amount, - $this->getCallback(), - $this->transactionId(), - '' - ); - - } catch(\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (intval($response) >= 0) { - $this->refId = $response; - $this->transactionSetRefId(); - return true; - } - - $this->transactionFailed(); - $this->newLog($response, JahanPayException::$errors[$response]); - throw new JahanPayException($response); - } - - /** - * Check user payment - * - * @return bool - * - * @throws JahanPayException - */ - protected function userPayment() - { - $refId = Input::get('au'); - - if ($this->refId() != $refId) { - $this->transactionFailed(); - $this->newLog(-30, JahanPayException::$errors[-30]); - throw new JahanPayException(-30); - } - - return true; - } - - /** - * Verify user payment from bank server - * - * @return bool - * - * @throws JahanPayException - */ - protected function verifyPayment() - { - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->verification( - $this->config->get('gateway.jahanpay.api'), - $this->amount, - $this->refId - ); - - } catch(\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (intval($response) == 1) { - $this->transactionSucceed(); - $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - $this->transactionFailed(); - $this->newLog($response, JahanPayException::$errors[$response]); - throw new JahanPayException($response); - } -} diff --git a/src/src/JahanPay/JahanPayException.php b/src/src/JahanPay/JahanPayException.php deleted file mode 100644 index f6167535..00000000 --- a/src/src/JahanPay/JahanPayException.php +++ /dev/null @@ -1,31 +0,0 @@ - 'تراکنش انجام شده اما مبلغ مطابقت ندارد', - -31 => 'تراکنش انجام نشده است', - -30 => 'چنین تراکنشی موجود نیست', - -29 => 'آدرس کال بک خالی است', - -27 => 'آي پی شما مسدود است', - -26 => 'درگاه غیر فعال شده است', - -24 => 'مبلغ نادرست است', - -23 => 'مبلغ زیاد است', - -22 => 'مبلغ خیلی کم است -حداقل مبلغ ارسالی به درگاه 100 ت می باشد', - -21 => 'آي پی براي این درگاه نامعتبر است', - -20 => 'api نادرست است', - -6 => 'خطاي اتصال به بانک', - -9 => 'خطاي سیستمی', - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -} diff --git a/src/src/Mellat/Mellat.php b/src/src/Mellat/Mellat.php deleted file mode 100644 index 79d7a6af..00000000 --- a/src/src/Mellat/Mellat.php +++ /dev/null @@ -1,234 +0,0 @@ -amount = $amount; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $refId = $this->refId; - - return view('gateway::mellat-redirector')->with(compact('refId')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - $this->settleRequest(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.mellat.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws MellatException - */ - protected function sendPayRequest() - { - $dateTime = new DateTime(); - - $this->newTransaction(); - - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'amount' => $this->amount, - 'localDate' => $dateTime->format('Ymd'), - 'localTime' => $dateTime->format('His'), - 'additionalData' => '', - 'callBackUrl' => $this->getCallback(), - 'payerId' => 0, - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpPayRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - $response = explode(',', $response->return); - - if ($response[0] != '0') { - $this->transactionFailed(); - $this->newLog($response[0], MellatException::$errors[$response[0]]); - throw new MellatException($response[0]); - } - $this->refId = $response[1]; - $this->transactionSetRefId(); - } - - /** - * Check user payment - * - * @return bool - * - * @throws MellatException - */ - protected function userPayment() - { - $this->refId = Input::get('RefId'); - $this->trackingCode = Input::get('SaleReferenceId'); - $this->cardNumber = Input::get('CardHolderPan'); - $payRequestResCode = Input::get('ResCode'); - - if ($payRequestResCode == '0') { - return true; - } - - $this->transactionFailed(); - $this->newLog($payRequestResCode, @MellatException::$errors[$payRequestResCode]); - throw new MellatException($payRequestResCode); - } - - /** - * Verify user payment from bank server - * - * @return bool - * - * @throws MellatException - * @throws SoapFault - */ - protected function verifyPayment() - { - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'saleOrderId' => $this->transactionId(), - 'saleReferenceId' => $this->trackingCode() - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpVerifyRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->return != '0') { - $this->transactionFailed(); - $this->newLog($response->return, MellatException::$errors[$response->return]); - throw new MellatException($response->return); - } - - return true; - } - - /** - * Send settle request - * - * @return bool - * - * @throws MellatException - * @throws SoapFault - */ - protected function settleRequest() - { - $fields = array( - 'terminalId' => $this->config->get('gateway.mellat.terminalId'), - 'userName' => $this->config->get('gateway.mellat.username'), - 'userPassword' => $this->config->get('gateway.mellat.password'), - 'orderId' => $this->transactionId(), - 'saleOrderId' => $this->transactionId(), - 'saleReferenceId' => $this->trackingCode - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->bpSettleRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->return == '0' || $response->return == '45') { - $this->transactionSucceed(); - $this->newLog($response->return, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - $this->transactionFailed(); - $this->newLog($response->return, MellatException::$errors[$response->return]); - throw new MellatException($response->return); - } -} diff --git a/src/src/Mellat/MellatException.php b/src/src/Mellat/MellatException.php deleted file mode 100644 index 55f5ef3c..00000000 --- a/src/src/Mellat/MellatException.php +++ /dev/null @@ -1,62 +0,0 @@ - 'شماره کارت نامعتبر است', - 12 => 'موجودی کافی نیست', - 13 => 'رمز نادرست است', - 14 => 'تعداد دفعات وارد کردن رمز بیش از حد مجاز است', - 15 => 'کارت نامعتبر است', - 16 => 'دفعات برداشت وجه بیش از حد مجاز است', - 17 => 'کاربر از انجام تراکنش منصرف شده است', - 18 => 'تاریخ انقضای کارت گذشته است', - 19 => 'مبلغ برداشت وجه بیش از حد مجاز است', - 111 => 'صادر کننده کارت نامعتبر است', - 112 => 'خطای سوییچ صادر کننده کارت', - 113 => 'پاسخی از صادر کننده کارت دریافت نشد', - 114 => 'دارنده این کارت مجاز به انجام این تراکنش نیست', - 21 => 'پذیرنده نامعتبر است', - 23 => 'خطای امنیتی رخ داده است', - 24 => 'اطلاعات کاربری پذیرنده نامعتبر است', - 25 => 'مبلغ نامعتبر است', - 31 => 'پاسخ نامعتبر است', - 32 => 'فرمت اطلاعات وارد شده صحیح نمی‌باشد', - 33 => 'حساب نامعتبر است', - 34 => 'خطای سیستمی', - 35 => 'تاریخ نامعتبر است', - 41 => 'شماره درخواست تکراری است', - 42 => 'تراکنش Sale یافت نشد', - 43 => 'قبلا درخواست Verfiy داده شده است', - 44 => 'درخواست Verfiy یافت نشد', - 45 => 'تراکنش Settle شده است', - 46 => 'تراکنش Settle نشده است', - 47 => 'تراکنش Settle یافت نشد', - 48 => 'تراکنش Reverse شده است', - 49 => 'تراکنش Refund یافت نشد.', - 412 => 'شناسه قبض نادرست است', - 413 => 'شناسه پرداخت نادرست است', - 414=> 'سازمان صادر کننده قبض نامعتبر است', - 415 => 'زمان جلسه کاری به پایان رسیده است', - 416 => 'خطا در ثبت اطلاعات', - 417 => 'شناسه پرداخت کننده نامعتبر است', - 418 => 'اشکال در تعریف اطلاعات مشتری', - 419 => 'تعداد دفعات ورود اطلاعات از حد مجاز گذشته است', - 421 => 'IP نامعتبر است', - 51 => 'تراکنش تکراری است', - 54 => 'تراکنش مرجع موجود نیست', - 55 => 'تراکنش نامعتبر است', - 61 => 'خطا در واریز' - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -} diff --git a/src/src/Parsian/Parsian.php b/src/src/Parsian/Parsian.php deleted file mode 100644 index 2be94093..00000000 --- a/src/src/Parsian/Parsian.php +++ /dev/null @@ -1,191 +0,0 @@ -amount = intval($amount); - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $url = $this->gateUrl . $this->refId(); - - return view('gateway::parsian-redirector')->with(compact('url')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.parsian.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to parsian gateway - * - * @return bool - * - * @throws ParsianErrorException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $params = array( - 'pin' => $this->config->get('gateway.parsian.pin'), - 'amount' => $this->amount, - 'orderId' => $this->transactionId(), - 'callbackUrl' => $this->getCallback(), - 'authority' => 0, - 'status' => 1 - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PinPaymentRequest($params); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response !== false) { - $authority = $response->authority; - $status = $response->status; - - if ($authority && $status == 0) { - $this->refId = $authority; - $this->transactionSetRefId(); - return true; - } - - $errorMessage = ParsianResult::errorMessage($status); - $this->transactionFailed(); - $this->newLog($status, $errorMessage); - throw new ParsianErrorException($errorMessage, $status); - - } else { - $this->transactionFailed(); - $this->newLog(-1, 'خطا در اتصال به درگاه پارسیان'); - throw new ParsianErrorException('خطا در اتصال به درگاه پارسیان', -1); - } - } - - /** - * Verify payment - * - * @throws ParsianErrorException - */ - protected function verifyPayment() - { - if (!Input::has('au') && !Input::has('rs')) - throw new ParsianErrorException('درخواست غیر معتبر', -1); - - $authority = Input::get('au'); - $status = Input::get('rs'); - - if ($status != 0) { - $errorMessage = ParsianResult::errorMessage($status); - $this->newLog($status, $errorMessage); - throw new ParsianErrorException($errorMessage, $status); - } - - if ($this->refId != $authority) - throw new ParsianErrorException('تراکنشی یافت نشد', -1); - - $params = array( - 'pin' => $this->config->get('gateway.parsian.pin'), - 'authority' => $authority, - 'status' => 1 - ); - - try { - $soap = new SoapClient($this->serverUrl); - $result = $soap->PinPaymentEnquiry($params); - - } catch (\SoapFault $e) { - throw new ParsianErrorException($e->getMessage(), -1); - } - - if ($result === false || !isset($result->status)) - throw new ParsianErrorException('پاسخ دریافتی از بانک نامعتبر است.', -1); - - if ($result->status != 0) { - $errorMessage = ParsianResult::errorMessage($result->status); - $this->transactionFailed(); - $this->newLog($result->status, $errorMessage); - throw new ParsianErrorException($errorMessage, $result->status); - } - - $this->trackingCode = $authority; - $this->transactionSucceed(); - $this->newLog($result->status, ParsianResult::errorMessage($result->status)); - } -} diff --git a/src/src/Parsian/ParsianErrorException.php b/src/src/Parsian/ParsianErrorException.php deleted file mode 100644 index 3d6fbcc6..00000000 --- a/src/src/Parsian/ParsianErrorException.php +++ /dev/null @@ -1,7 +0,0 @@ - 'تراکنش با موفقیت انجام شد.', - 1 => 'خطا در انجام تراکنش', - 2 => 'بین عملیات وقفه افتاده است.', - 10 => 'شماره کارت نامعتبر است.', - 11 => 'کارت شما منقضی شده است', - 12 => 'رمز کارت وارد شده اشتباه است', - 13 => 'موجودی کارت شما کافی نیست', - 14 => 'مبلغ تراکنش بیش از سقف مجاز پذیرنده است.', - 15 => 'سقف مجاز روزانه شما کامل شده است.', - 18 => 'این تراکنش قبلا تایید شده است', - 20 => 'اطلاعات پذیرنده صحیح نیست.', - 21 => 'invalid authority', - 22 => 'اطلاعات پذیرنده صحیح نیست.', - 30 => 'عملیات قبلا با موفقیت انجام شده است.', - 34 => 'شماره تراکنش فروشنده درست نمی باشد.' - ); - - public static function errorMessage($errorId) - { - return isset(self::$errors[$errorId])?self::$errors[$errorId] : $errorId; - } -} diff --git a/src/src/Payline/Payline.php b/src/src/Payline/Payline.php deleted file mode 100644 index bcfdf798..00000000 --- a/src/src/Payline/Payline.php +++ /dev/null @@ -1,193 +0,0 @@ -amount = $amount; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - return redirect()->to($this->gateUrl . $this->refId); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.payline.callback-url'); - - return urlencode($this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()])); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws PaylineSendException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $fields = array( - 'api' => $this->config->get('gateway.payline.api'), - 'amount' => $this->amount, - 'redirect' => $this->getCallback(), - ); - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $this->serverUrl); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $response = curl_exec($ch); - curl_close($ch); - - if (is_numeric($response) && $response > 0) { - $this->refId = $response; - $this->transactionSetRefId(); - - return true; - } - - $this->transactionFailed(); - $this->newLog($response, PaylineSendException::$errors[$response]); - throw new PaylineSendException($response); - } - - /** - * Check user payment with GET data - * - * @return bool - * - * @throws PaylineReceiveException - */ - protected function userPayment() - { - $this->refIf = Input::get('id_get'); - $trackingCode = Input::get('trans_id'); - - if (is_numeric($trackingCode) && $trackingCode > 0) { - $this->trackingCode = $trackingCode; - return true; - } - - $this->transactionFailed(); - $this->newLog(-4, PaylineReceiveException::$errors[-4]); - throw new PaylineReceiveException(-4); - } - - /** - * Verify user payment from zarinpal server - * - * @return bool - * - * @throws PaylineReceiveException - */ - protected function verifyPayment() - { - $fields = array( - 'api' => $this->config->get('gateway.payline.api'), - 'id_get' => $this->refId(), - 'trans_id' => $this->trackingCode() - ); - - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $this->serverVerifyUrl); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $response = curl_exec($ch); - curl_close($ch); - - if ($response == 1) { - $this->transactionSucceed(); - $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT); - - return true; - } - - $this->transactionFailed(); - $this->newLog($response, PaylineReceiveException::$errors[$response]); - throw new PaylineReceiveException($response); - } -} diff --git a/src/src/Payline/PaylineReceiveException.php b/src/src/Payline/PaylineReceiveException.php deleted file mode 100644 index c281c35a..00000000 --- a/src/src/Payline/PaylineReceiveException.php +++ /dev/null @@ -1,22 +0,0 @@ - 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', - -2 => 'trans_id ارسال شده معتبر نمی‌باشد.', - -3 => 'id_get ارسالی معتبر نمی باشد.', - -4 => 'چنین تراکنشی در سیستم وجود ندارد و یا موفقیت آمیز نبوده است.' - ); - - public function __construct($errorId) - { - $this->errorId = $errorId; - - parent::__construct(@self::$errors[$errorId].' #'.$errorId, $errorId); - } -} diff --git a/src/src/Payline/PaylineSendException.php b/src/src/Payline/PaylineSendException.php deleted file mode 100644 index f5a8a7c5..00000000 --- a/src/src/Payline/PaylineSendException.php +++ /dev/null @@ -1,22 +0,0 @@ - 'api ارسالی با نوع api تعریف شده در payline سازگار نیست.', - -2 => 'مقدار amount داده عددی نمی باشد و یا کمتر از 1000 ریال است.', - -3 => 'مقدار redirect رشته null است.', - -4 => 'درگاهی با اطلاعات ارسالی شما یافت نشد و یا در حالت انتظار می باشد.' - ); - - public function __construct($errorId) - { - $this->errorId = $errorId; - - parent::__construct(@self::$errors[$errorId].' #'.$errorId, $errorId); - } -} diff --git a/src/src/Sadad/Sadad.php b/src/src/Sadad/Sadad.php deleted file mode 100644 index 55fd0322..00000000 --- a/src/src/Sadad/Sadad.php +++ /dev/null @@ -1,203 +0,0 @@ -amount = intval($amount); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - $form = $this->form; - - return view('gateway::sadad-redirector')->with(compact('form')); - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.sadad.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws SadadException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $this->form = ''; - - try { - $soap = new SoapClient($this->serverUrl); - - $response = $soap->PaymentUtility( - $this->config->get('gateway.sadad.merchant'), - $this->amount, - $this->transactionId(), - $this->config->get('gateway.sadad.transactionKey'), - $this->config->get('gateway.sadad.terminalId'), - $this->getCallback() - ); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (!isset($response['RequestKey']) || !isset($response['PaymentUtilityResult'])) { - $this->newLog(SadadResult::INVALID_RESPONSE_CODE, SadadResult::INVALID_RESPONSE_MESSAGE); - throw new SadadException(SadadResult::INVALID_RESPONSE_MESSAGE, SadadResult::INVALID_RESPONSE_CODE); - } - - $this->form = $response['PaymentUtilityResult']; - - $this->refId = $response['RequestKey']; - - $this->transactionSetRefId(); - } - - /** - * Verify user payment from bank server - * - * @throws SadadException - */ - protected function verifyPayment() - { - try { - $soap = new SoapClient($this->serverUrl); - - $result = $soap->CheckRequestStatusResult( - $this->transactionId(), - $this->config->get('gateway.sadad.merchant'), - $this->config->get('gateway.sadad.terminalId'), - $this->config->get('gateway.sadad.transactionKey'), - $this->refId(), - $this->amount - ); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if (empty($result) || !isset($result->AppStatusCode)) - throw new SadadException('در دریافت اطلاعات از بانک خطایی رخ داده است.'); - - $statusResult = strval($result->AppStatusCode); - $appStatus = strtolower($result->AppStatusDescription); - - $message = $this->getMessage($statusResult, $appStatus); - - $this->newLog($statusResult, $message['fa']); - - if ($statusResult == 0 && $appStatus === 'commit') { - $this->trackingCode = $result->TraceNo; - $this->cardNumber = $result->CustomerCardNumber; - $this->transactionSucceed(); - } else { - $this->transactionFailed(); - throw new SadadException($message['fa'], $statusResult); - } - } - - /** - * Register error to error list - * - * @param int $code - * @param string $message - * - * @return array|null - * - * @throws SadadException - */ - private function getMessage($code, $message) - { - $result = SadadResult::codeResponse($code, $message); - if (!$result) { - $result = array( - 'code' => SadadResult::UNKNOWN_CODE, - 'message' => SadadResult::UNKNOWN_MESSAGE, - 'fa' => 'خطای ناشناخته', - 'en' => 'Unknown Error', - 'retry' => false - ); - } - - return $result; - } -} diff --git a/src/src/Sadad/SadadException.php b/src/src/Sadad/SadadException.php deleted file mode 100644 index 25f7e734..00000000 --- a/src/src/Sadad/SadadException.php +++ /dev/null @@ -1,8 +0,0 @@ - SadadResult::ERROR_CONNECT, - 'message'=>SadadResult::ERROR_CONNECT_MESSAGE, - 'fa' => 'خطا در اتصال به درگاه سداد', - 'en' => 'Error in connect to sadad', - 'retry' => false - ), - array( - 'code' => SadadResult::INVALID_RESPONSE_CODE, - 'message'=>SadadResult::INVALID_RESPONSE_MESSAGE, - 'fa' => 'جواب نامعتبر', - 'en' => 'Invalid Response', - 'retry' => false - ), - array( - 'code' => -1, - 'message'=>'not_set', - 'fa' => 'نتیجه استعلام نامعلوم و یا کاربر از انجام تراکنش منصرف شده است.', - 'en' => 'Result of the Inquiry Unknown or Customer Cancellation', - 'retry' => true, - ), - array( - 'code' => -1, - 'message'=>'not_exist', - 'fa' => 'پارامترهای ارسالی صحیح نیست و یا تراکنش در سیستم وجود ندارد.', - 'en' => 'Parameters passed is incorrect or there is no transaction in the system.', - 'retry' => false, - ), - array( - 'code' => 9000, - 'message'=>'incomplet_info', - 'fa' => 'درخواست تراکنش در سیستم ثبت شده ولی تراکنش هنوز شروع نشده است.', - 'en' => 'Transaction request registered in the system, but the transaction has not started yet.', - 'retry' => true, - ), - array( - 'code' => 9001, - 'message'=>'wait_for_send_and_get_response', - 'fa' => 'تراکنش در سیستم ثبت شده و پیام مالی به سیستم بانک ارسال شده است اما هنوز پاسخی دریافت نشده است.', - 'en' => 'Financial transaction log and the message has been sent to the banking system but not yet received.', - 'retry' => true, - ), - array( - 'code' => 9004, - 'message'=>'wait_for_reversal', - 'fa' => 'سیستم در حال تلاش جهت برگشت تراکنش خرید است.', - 'en' => 'The system is trying to buy back transaction.', - 'retry' => true, - ), - array( - 'code' => 9005, - 'message'=>'wait_for_reversal_advise', - 'fa' => 'سیستم در حال تلاش جهت برگشت تراکنش خرید است.', - 'en' => 'The system is trying to buy back transaction.', - 'retry' => true, - ), - array( - 'code' => 9006, - 'message'=>'reversaled', - 'fa' => 'تراکنش ناموفق بوده و مبلغ با موفقیت به حساب مشتری برگشت خورده است', - 'en' => 'Purchase operation was unsuccessful and The amount is returned successfully to the client`s account', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'failed', - 'fa' => 'عملیات خرید نا موفق بوده است', - 'en' => 'Purchase operation was unsuccessful', - 'retry' => false, - ), - array( - 'code' => 56, - 'message'=>'failed', - 'fa' => 'کارت نامعتبر است.', - 'en' => 'Card Not Effective', - 'retry' => false, - ), - array( - 'code' => 51, - 'message'=>'failed', - 'fa' => 'مبلغ درخواستی از موجودی حساب شما, بیشتر است.حداقل مانده حساب شما پس از عملیات پرداخت باید 100,000 ریال باشد.', - 'en' => 'Inventory shortage', - 'retry' => false, - ), - array( - 'code' => 55, - 'message'=>'failed', - 'fa' => 'رمز کارت صحیح نمی باشد لطفا مجددا, سعی کنید.', - 'en' => 'Incorrect Pin', - 'retry' => false, - ), - array( - 'code' => 9008, - 'message'=>'check_status', - 'fa' => 'در هنگام انجام عملیات CheckStatus مشکلی رخ داده است.', - 'en' => 'CheckStatus operations when a problem has occurred.', - 'retry' => true, - ), - array( - 'code' => 9009, - 'message'=>'async_get_response', - 'fa' => 'سیستم در حال تلاش برای دریافت جواب عملیات بانکی است.', - 'en' => 'The system is trying to Get answers to banking operations.', - 'retry' => true, - ), - array( - 'code' => 9010, - 'message'=>'wait_for_reversal_auto', - 'fa' => 'تراکنش به لیست تراکنش های برگشت خودکار اضافه شده است و در انتظار برگشت می باشد.', - 'en' => 'The transaction is automatically added to the list of back transactions and is expected to return.', - 'retry' => true, - ), - array( - 'code' => 9011, - 'message'=>'pendingcurrenttransaction', - 'fa' => 'تراکنش برگشت خرید ارسال شده است اما پاسخ دریافت شده قطعی نیست و تراکنش در لیست تراکنش های معوق می باشد و نتیجه عملیات بانکی ظرف 24 ساعت آینده مشخص خواهد شد.', - 'en' => 'Back purchase transaction has been sent but not conclusive answer has been received and the transaction is on the list of pending transactions and banking operations will be determined within the next 24 hours.', - 'retry' => false, - ), - array( - 'code' => 9012, - 'message'=>'pendingtransactionreversed', - 'fa' => 'تراکنش ناموفق - نتیجه تراکنش معوق بعد از 24 ساعت مشخص می شود', - 'en' => 'Failed Transaction - result of outstanding transactions will be determined after 24 hours', - 'retry' => false, - ), - array( - 'code' => 2, - 'message'=>'request_done', - 'fa' => 'تراکنش موفق', - 'en' => 'Successful Transaction', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'pendingtransactioncommited', - 'fa' => 'تایید پرداخت - نتیجه تراکنش معوق بعد از 24 ساعت مشخص می شود', - 'en' => 'Verify Payment - result of outstanding transactions will be determined after 24 hours', - 'retry' => false, - ), - array( - 'code' => 0, - 'message'=>'commit', - 'fa' => 'تایید پرداخت', - 'en' => 'Verify Payment', - 'retry' => false, - ), - ); - - /** - * return response - * - * @param int $code - * @param string $message - * @return null - */ - public static function codeResponse($code,$message) - { - $code = intval($code); - - foreach(self::$results as $v) { - if ($v['message'] == $message && $v['code'] == $code) - return $v; - } - - return null; - } -} diff --git a/src/src/Zarinpal/Zarinpal.php b/src/src/Zarinpal/Zarinpal.php deleted file mode 100644 index 507f2ae7..00000000 --- a/src/src/Zarinpal/Zarinpal.php +++ /dev/null @@ -1,263 +0,0 @@ -setServer(); - } - - /** - * {@inheritdoc} - */ - public function set($amount) - { - $this->amount = ($amount / 10); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function ready() - { - $this->sendPayRequest(); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function redirect() - { - switch ($this->config->get('gateway.zarinpal.type')) { - case 'zarin-gate': - return redirect()->to(str_replace('$Authority', $this->refId, $this->zarinGateUrl)); - break; - - case 'normal': - default: - return redirect()->to($this->gateUrl . $this->refId); - break; - } - } - - /** - * {@inheritdoc} - */ - public function verify($transaction) - { - parent::verify($transaction); - - $this->userPayment(); - $this->verifyPayment(); - - return $this; - } - - /** - * Sets callback url - * @param $url - */ - function setCallback($url) - { - $this->callbackUrl = $url; - return $this; - } - - /** - * Gets callback url - * @return string - */ - function getCallback() - { - if (!$this->callbackUrl) - $this->callbackUrl = $this->config->get('gateway.zarinpal.callback-url'); - - return $this->makeCallback($this->callbackUrl, ['transaction_id' => $this->transactionId()]); - } - - /** - * Send pay request to server - * - * @return void - * - * @throws ZarinpalException - */ - protected function sendPayRequest() - { - $this->newTransaction(); - - $fields = array( - 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'), - 'Amount' => $this->amount, - 'CallbackURL' => $this->getCallback(), - 'Description' => $this->config->get('gateway.zarinpal.description', ''), - 'Email' => $this->config->get('gateway.zarinpal.email', ''), - 'Mobile' => $this->config->get('gateway.zarinpal.mobile', ''), - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PaymentRequest($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->Status != 100) { - $this->transactionFailed(); - $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]); - throw new ZarinpalException($response->Status); - } - - $this->refId = $response->Authority; - $this->transactionSetRefId(); - } - - /** - * Check user payment with GET data - * - * @return bool - * - * @throws ZarinpalException - */ - protected function userPayment() - { - $this->authority = Input::get('Authority'); - $status = Input::get('Status'); - - if ($status == 'OK') { - return true; - } - - $this->transactionFailed(); - $this->newLog(-22, ZarinpalException::$errors[-22]); - throw new ZarinpalException(-22); - } - - /** - * Verify user payment from zarinpal server - * - * @return bool - * - * @throws ZarinpalException - */ - protected function verifyPayment() - { - - $fields = array( - 'MerchantID' => $this->config->get('gateway.zarinpal.merchant-id'), - 'Authority' => $this->refId, - 'Amount' => $this->amount, - ); - - try { - $soap = new SoapClient($this->serverUrl); - $response = $soap->PaymentVerification($fields); - - } catch (\SoapFault $e) { - $this->transactionFailed(); - $this->newLog('SoapFault', $e->getMessage()); - throw $e; - } - - if ($response->Status != 100 && $response->Status != 100) { - $this->transactionFailed(); - $this->newLog($response->Status, ZarinpalException::$errors[$response->Status]); - throw new ZarinpalException($response->Status); - } - - $this->trackingCode = $response->RefID; - $this->transactionSucceed(); - $this->newLog($response->Status, Enum::TRANSACTION_SUCCEED_TEXT); - return true; - } - - /** - * Set server for soap transfers data - * - * @return void - */ - protected function setServer() - { - $server = $this->config->get('gateway.zarinpal.server', 'germany'); - switch ($server) { - case 'iran': - $this->serverUrl = $this->iranServer; - break; - - case 'test': - $this->serverUrl = $this->sandboxServer; - $this->gateUrl = $this->sandboxGateUrl; - break; - - case 'germany': - default: - $this->serverUrl = $this->germanyServer; - break; - } - } -} diff --git a/src/src/Zarinpal/ZarinpalException.php b/src/src/Zarinpal/ZarinpalException.php deleted file mode 100644 index 2951e3d9..00000000 --- a/src/src/Zarinpal/ZarinpalException.php +++ /dev/null @@ -1,29 +0,0 @@ - 'اطلاعات ارسال شده ناقص است.', - -2 => 'IP و یا مرچنت کد پذیرنده صحیح نیست', - -3 => 'رقم باید بالای 100 تومان باشد', - -4 => 'سطح پذیرنده پایین تر از سطح نقره ای است', - -11 => 'درخواست مورد نظر یافت نشد', - -21 => 'هیچ نوع عملیات مالی برای این تراکنش یافت نشد', - -22 => 'تراکنش ناموفق میباشد', - -33 => 'رقم تراکنش با رقم پرداخت شده مطابقت ندارد', - -54 => 'درخواست مورد نظر آرشیو شده', - 100 => 'عملیات با موفقیت انجام شد', - 101 => 'عملیات پرداخت با موفقیت انجام شده ولی قبلا عملیات PaymentVertification بر روی این تراکنش انجام شده است', - ); - - public function __construct($errorId) - { - $this->errorId = intval($errorId); - - parent::__construct(@self::$errors[$this->errorId].' #'.$this->errorId, $this->errorId); - } -}