11<?php
2+
23declare (strict_types=1 );
34
45namespace PhpMonsters \Larapay \Adapter ;
1314 */
1415class Idpay extends AdapterAbstract implements AdapterInterface
1516{
17+ public $ endPointVerify = 'https://api.idpay.ir/v1.1/payment/verify ' ;
18+ public $ reverseSupport = false ;
1619 protected $ WSDL = 'https://api.idpay.ir/v1.1/payment ' ;
17- protected $ endPoint = 'https://idpay.ir/p/ws/{order-id} ' ;
18-
20+ protected $ endPoint = 'https://idpay.ir/p/ws/{order-id} ' ;
1921 protected $ testWSDL = 'https://api.idpay.ir/v1.1/payment ' ;
2022 protected $ testEndPoint = 'https://idpay.ir/p/ws-sandbox/{order-id} ' ;
2123
22- public $ endPointVerify = 'https://api.idpay.ir/v1.1/payment/verify ' ;
24+ /**
25+ * @return array
26+ * @throws Exception
27+ * @throws \PhpMonsters\Larapay\Adapter\Exception
28+ */
29+ public function formParams (): array
30+ {
31+ $ authority = $ this ->requestToken ();
2332
24- public $ reverseSupport = false ;
33+ return [
34+ 'endPoint ' => strtr ($ this ->getEndPoint (), ['{authority} ' => $ authority ]),
35+ ];
36+ }
37+
38+ /**
39+ * @return bool
40+ */
41+ public function canContinueWithCallbackParameters (): bool
42+ {
43+ if (!empty ($ this ->transaction ['gate_refid ' ])) {
44+ return true ;
45+ }
46+
47+ return false ;
48+ }
49+
50+ public function getGatewayReferenceId (): string
51+ {
52+ $ this ->checkRequiredParameters ([
53+ 'merchant_id ' ,
54+ ]);
55+
56+ return strval ($ this ->transaction ['gate_refid ' ]);
57+ }
58+
59+ /**
60+ * @return string
61+ * @throws Exception
62+ * @throws \PhpMonsters\Larapay\Adapter\Exception
63+ */
64+ protected function generateForm (): string
65+ {
66+ $ authority = $ this ->requestToken ();
67+
68+ $ form = view ('larapay::idpay-form ' , [
69+ 'endPoint ' => strtr ($ this ->getEndPoint (), ['{order-id} ' => $ authority ]),
70+ 'submitLabel ' => !empty ($ this ->submit_label ) ? $ this ->submit_label : trans ("larapay::larapay.goto_gate " ),
71+ 'autoSubmit ' => boolval ($ this ->auto_submit ),
72+ ]);
73+
74+ return $ form ->__toString ();
75+ }
2576
2677 /**
2778 * @return string
@@ -30,7 +81,7 @@ class Idpay extends AdapterAbstract implements AdapterInterface
3081 */
3182 protected function requestToken (): string
3283 {
33- if ($ this ->getTransaction ()->checkForRequestToken () == false ) {
84+ if ($ this ->getTransaction ()->checkForRequestToken () === false ) {
3485 throw new Exception ('larapay::larapay.could_not_request_payment ' );
3586 }
3687
@@ -41,25 +92,25 @@ protected function requestToken(): string
4192 ]);
4293
4394 $ sendParams = [
44- 'order_id ' => $ this ->getTransaction ()->bank_order_id ,
45- 'amount ' => intval ($ this ->amount ),
95+ 'order_id ' => $ this ->getTransaction ()->bank_order_id ,
96+ 'amount ' => intval ($ this ->amount ),
4697 'desc ' => $ this ->description ? $ this ->description : '' ,
47- 'mail ' => $ this ->email ? $ this ->email : '' ,
48- 'phone ' => $ this ->mobile ? $ this ->mobile : '' ,
98+ 'mail ' => $ this ->email ? $ this ->email : '' ,
99+ 'phone ' => $ this ->mobile ? $ this ->mobile : '' ,
49100 'callback ' => $ this ->redirect_url ,
50101 ];
51102
52103 $ header = [
53104 'Content-Type: application/json ' ,
54- 'X-API-KEY: ' .$ this ->merchant_id ,
55- 'X-SANDBOX: ' .$ this ->getSandbox ()
105+ 'X-API-KEY: ' .$ this ->merchant_id ,
106+ 'X-SANDBOX: ' .$ this ->getSandbox ()
56107 ];
57108 try {
58109 XLog::debug ('PaymentRequest call ' , $ sendParams );
59110 $ ch = curl_init ();
60111 curl_setopt ($ ch , CURLOPT_URL , $ this ->WSDL );
61112 curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ sendParams ));
62- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
113+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
63114 curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ header );
64115 $ response = curl_exec ($ ch );
65116 $ ch_error = curl_error ($ ch );
@@ -73,47 +124,14 @@ protected function requestToken(): string
73124 XLog::info ('PaymentRequest response ' , $ this ->obj2array ($ result ));
74125 $ this ->getTransaction ()->setGatewayToken (strval ($ result ->id )); // update transaction reference id
75126 return $ result ->id ;
76- } catch (\Exception $ e ) {
127+ } catch (\Exception $ e ) {
77128 throw new Exception ($ e ->getMessage ());
78129 };
79130 }
80131
81-
82- /**
83- * @return string
84- * @throws Exception
85- * @throws \PhpMonsters\Larapay\Adapter\Exception
86- */
87- protected function generateForm (): string
88- {
89- $ authority = $ this ->requestToken ();
90-
91- $ form = view ('larapay::idpay-form ' , [
92- 'endPoint ' => strtr ($ this ->getEndPoint (), ['{order-id} ' => $ authority ]),
93- 'submitLabel ' => !empty ($ this ->submit_label ) ? $ this ->submit_label : trans ("larapay::larapay.goto_gate " ),
94- 'autoSubmit ' => boolval ($ this ->auto_submit ),
95- ]);
96-
97- return $ form ->__toString ();
98- }
99-
100- /**
101- * @return array
102- * @throws Exception
103- * @throws \PhpMonsters\Larapay\Adapter\Exception
104- */
105- public function formParams (): array
106- {
107- $ authority = $ this ->requestToken ();
108-
109- return [
110- 'endPoint ' => strtr ($ this ->getEndPoint (), ['{authority} ' => $ authority ]),
111- ];
112- }
113-
114132 public function getSandbox (): string
115133 {
116- if (config ('larapay.mode ' ) == 'production ' ) {
134+ if (config ('larapay.mode ' ) === 'production ' ) {
117135 return "0 " ;
118136 } else {
119137 return "1 " ;
@@ -127,8 +145,7 @@ public function getSandbox(): string
127145 */
128146 protected function verifyTransaction (): bool
129147 {
130-
131- if ($ this ->getTransaction ()->checkForVerify () == false ) {
148+ if ($ this ->getTransaction ()->checkForVerify () === false ) {
132149 throw new Exception ('larapay::larapay.could_not_verify_payment ' );
133150 }
134151
@@ -137,21 +154,21 @@ protected function verifyTransaction(): bool
137154 ]);
138155
139156 $ sendParams = [
140- 'id ' => $ this ->getTransaction ()->gate_refid ,
141- 'order_id ' => $ this ->getTransaction ()->bank_order_id ,
157+ 'id ' => $ this ->getTransaction ()->gate_refid ,
158+ 'order_id ' => $ this ->getTransaction ()->bank_order_id ,
142159 ];
143160
144161 $ header = [
145162 'Content-Type: application/json ' ,
146- 'X-API-KEY: ' .$ this ->merchant_id ,
147- 'X-SANDBOX: ' .$ this ->getSandbox ()
163+ 'X-API-KEY: ' .$ this ->merchant_id ,
164+ 'X-SANDBOX: ' .$ this ->getSandbox ()
148165 ];
149166
150167 try {
151168 $ ch = curl_init ();
152169 curl_setopt ($ ch , CURLOPT_URL , $ this ->endPointVerify );
153170 curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ sendParams ));
154- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
171+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
155172 curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ header );
156173 $ response = curl_exec ($ ch );
157174 $ ch_error = curl_error ($ ch );
@@ -161,41 +178,18 @@ protected function verifyTransaction(): bool
161178 XLog::info ('PaymentVerification response ' , $ this ->obj2array ($ result ));
162179
163180 if (isset ($ result ->status )) {
164-
165181 if ($ result ->status == 100 || $ result ->status == 101 ) {
166182 $ this ->getTransaction ()->setVerified ();
167- $ this ->getTransaction ()->setReferenceId ((string )$ result ->id );
183+ $ this ->getTransaction ()->setReferenceId ((string ) $ result ->id );
168184 return true ;
169185 } else {
170186 throw new Exception ($ result ->status );
171187 }
172188 } else {
173189 throw new Exception ($ result ->error_code );
174190 }
175-
176- } catch (\Exception $ e ) {
191+ } catch (\Exception $ e ) {
177192 throw new Exception ($ e ->getMessage ());
178193 }
179194 }
180-
181- /**
182- * @return bool
183- */
184- public function canContinueWithCallbackParameters (): bool
185- {
186- if (!empty ($ this ->transaction ['gate_refid ' ])) {
187- return true ;
188- }
189-
190- return false ;
191- }
192-
193- public function getGatewayReferenceId (): string
194- {
195- $ this ->checkRequiredParameters ([
196- 'merchant_id ' ,
197- ]);
198-
199- return strval ($ this ->transaction ['gate_refid ' ]);
200- }
201195}
0 commit comments