From 0419e4d35204ddd8d4dab5d255e3868926759896 Mon Sep 17 00:00:00 2001 From: nafezly Date: Thu, 3 Aug 2023 04:31:50 +0300 Subject: [PATCH] updates --- src/Classes/TelrPayment.php | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/Classes/TelrPayment.php diff --git a/src/Classes/TelrPayment.php b/src/Classes/TelrPayment.php new file mode 100644 index 0000000..b6b2eaa --- /dev/null +++ b/src/Classes/TelrPayment.php @@ -0,0 +1,112 @@ +telr_merchant_id = config('nafezly-payments.TELR_MERCHANT_ID'); + $this->telr_api_key = config('nafezly-payments.TELR_API_KEY'); + $this->telr_mode= config('nafezly-payments.TELR_MODE'); + $this->verify_route_name = config('nafezly-payments.VERIFY_ROUTE_NAME'); + } + + + + /** + * @param $amount + * @param null $user_id + * @param null $user_first_name + * @param null $user_last_name + * @param null $user_email + * @param null $user_phone + * @param null $source + * @return string[] + * @throws MissingPaymentInfoException + */ + public function pay($amount = null, $user_id = null, $user_first_name = null, $user_last_name = null, $user_email = null, $user_phone = null, $source = null): array + { + $this->setPassedVariablesToGlobal($amount,$user_id,$user_first_name,$user_last_name,$user_email,$user_phone,$source); + $required_fields = ['amount']; + $this->checkRequiredFields($required_fields, 'BINANCE'); + + $uniqid = uniqid().rand(1000,9999); + $currency = $this->currency==null?"SAR":$this->currency; + + $data = [ + 'ivp_method' => 'create', + 'ivp_store' => $this->telr_merchant_id, + 'ivp_authkey' => $this->telr_api_key, + 'order_ref' => $uniqid, + 'amount' => $this->amount, + 'currency' => $currency, + 'ivp_test'=>$this->telr_mode=="live"?false:true, + 'return_auth'=> route($this->verify_route_name,['payment'=>"telr"]), + 'return_decl'=> route($this->verify_route_name,['payment'=>"telr"]), + 'return_can'=> route($this->verify_route_name,['payment'=>"telr"]) + ]; + $response = Http::post('https://secure.telr.com/gateway/order.json', $data)->json(); + + + if(isset($response['url'])) + return [ + 'payment_id'=>$uniqid, + 'html'=>"", + 'redirect_url'=>$response['url'] + ]; + return [ + 'payment_id'=>$uniqid, + 'html'=>$response, + 'redirect_url'=>"" + ]; + } + + /** + * @param Request $request + * @return array|void + */ + public function verify(Request $request) + { + $response = $request->all(); + $data = [ + 'ivp_method' => 'check', + 'ivp_store' => $this->telr_merchant_id, + 'ivp_authkey' => $this->telr_api_key, + 'order_ref' => $response['order_ref'], + 'order_amount' => $response['amount'], + 'ivp_test'=>$this->telr_mode=="live"?false:true, + ]; + $response = Http::post('https://secure.telr.com/gateway/order.json', $data); + $telrHashCode = $response['code']; + if ($telrHashCode === $telrCallbackData['code']) { + return [ + 'success' => true, + 'payment_id'=>"", + 'message' => __('nafezly::messages.PAYMENT_DONE'), + 'process_data' => $request->all() + ]; + } else { + return [ + 'success' => false, + 'payment_id'=>"", + 'message' => __('nafezly::messages.PAYMENT_FAILED'), + 'process_data' => $request->all() + ]; + } + } +} \ No newline at end of file