1
1
<?php
2
+
2
3
declare (strict_types=1 );
3
4
4
5
namespace PhpMonsters \Larapay \Adapter ;
13
14
*/
14
15
class Idpay extends AdapterAbstract implements AdapterInterface
15
16
{
17
+ public $ endPointVerify = 'https://api.idpay.ir/v1.1/payment/verify ' ;
18
+ public $ reverseSupport = false ;
16
19
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} ' ;
19
21
protected $ testWSDL = 'https://api.idpay.ir/v1.1/payment ' ;
20
22
protected $ testEndPoint = 'https://idpay.ir/p/ws-sandbox/{order-id} ' ;
21
23
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 ();
23
32
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
+ }
25
76
26
77
/**
27
78
* @return string
@@ -30,7 +81,7 @@ class Idpay extends AdapterAbstract implements AdapterInterface
30
81
*/
31
82
protected function requestToken (): string
32
83
{
33
- if ($ this ->getTransaction ()->checkForRequestToken () == false ) {
84
+ if ($ this ->getTransaction ()->checkForRequestToken () === false ) {
34
85
throw new Exception ('larapay::larapay.could_not_request_payment ' );
35
86
}
36
87
@@ -41,25 +92,25 @@ protected function requestToken(): string
41
92
]);
42
93
43
94
$ 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 ),
46
97
'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 : '' ,
49
100
'callback ' => $ this ->redirect_url ,
50
101
];
51
102
52
103
$ header = [
53
104
'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 ()
56
107
];
57
108
try {
58
109
XLog::debug ('PaymentRequest call ' , $ sendParams );
59
110
$ ch = curl_init ();
60
111
curl_setopt ($ ch , CURLOPT_URL , $ this ->WSDL );
61
112
curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ sendParams ));
62
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
113
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
63
114
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ header );
64
115
$ response = curl_exec ($ ch );
65
116
$ ch_error = curl_error ($ ch );
@@ -73,47 +124,14 @@ protected function requestToken(): string
73
124
XLog::info ('PaymentRequest response ' , $ this ->obj2array ($ result ));
74
125
$ this ->getTransaction ()->setGatewayToken (strval ($ result ->id )); // update transaction reference id
75
126
return $ result ->id ;
76
- } catch (\Exception $ e ) {
127
+ } catch (\Exception $ e ) {
77
128
throw new Exception ($ e ->getMessage ());
78
129
};
79
130
}
80
131
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
-
114
132
public function getSandbox (): string
115
133
{
116
- if (config ('larapay.mode ' ) == 'production ' ) {
134
+ if (config ('larapay.mode ' ) === 'production ' ) {
117
135
return "0 " ;
118
136
} else {
119
137
return "1 " ;
@@ -127,8 +145,7 @@ public function getSandbox(): string
127
145
*/
128
146
protected function verifyTransaction (): bool
129
147
{
130
-
131
- if ($ this ->getTransaction ()->checkForVerify () == false ) {
148
+ if ($ this ->getTransaction ()->checkForVerify () === false ) {
132
149
throw new Exception ('larapay::larapay.could_not_verify_payment ' );
133
150
}
134
151
@@ -137,21 +154,21 @@ protected function verifyTransaction(): bool
137
154
]);
138
155
139
156
$ 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 ,
142
159
];
143
160
144
161
$ header = [
145
162
'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 ()
148
165
];
149
166
150
167
try {
151
168
$ ch = curl_init ();
152
169
curl_setopt ($ ch , CURLOPT_URL , $ this ->endPointVerify );
153
170
curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ sendParams ));
154
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
171
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
155
172
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ header );
156
173
$ response = curl_exec ($ ch );
157
174
$ ch_error = curl_error ($ ch );
@@ -161,41 +178,18 @@ protected function verifyTransaction(): bool
161
178
XLog::info ('PaymentVerification response ' , $ this ->obj2array ($ result ));
162
179
163
180
if (isset ($ result ->status )) {
164
-
165
181
if ($ result ->status == 100 || $ result ->status == 101 ) {
166
182
$ this ->getTransaction ()->setVerified ();
167
- $ this ->getTransaction ()->setReferenceId ((string )$ result ->id );
183
+ $ this ->getTransaction ()->setReferenceId ((string ) $ result ->id );
168
184
return true ;
169
185
} else {
170
186
throw new Exception ($ result ->status );
171
187
}
172
188
} else {
173
189
throw new Exception ($ result ->error_code );
174
190
}
175
-
176
- } catch (\Exception $ e ) {
191
+ } catch (\Exception $ e ) {
177
192
throw new Exception ($ e ->getMessage ());
178
193
}
179
194
}
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
- }
201
195
}
0 commit comments