PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / trunk
پارسی دیت – Parsi Date vtrunk
6.2.1 6.2 6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / inc / App / Integration / WooCommerce / wc-gateways / wpp-parsian-gateway.php
wp-parsidate / inc / App / Integration / WooCommerce / wc-gateways Last commit date
blocks 3 months ago lib 1 month ago index.php 3 months ago wpp-mellat-gateway.php 3 months ago wpp-melli-gateway.php 3 months ago wpp-parsian-gateway.php 3 months ago wpp-pasargad-gateway.php 3 months ago
wpp-parsian-gateway.php
604 lines
1 <?php
2
3 use WPParsidate\App\Integration\WooCommerce\WcGateways;
4 use WPParsidate\Helper\Assets;
5
6 defined( 'ABSPATH' ) or exit( 'No direct script access allowed' );
7
8 if ( ! function_exists( 'wpp_parsian_payment_gateway_init' ) ) {
9 function wpp_parsian_payment_gateway_init() {
10 if ( ! class_exists( 'WC_Parsian_Gateway' ) && ! class_exists( 'WPP_WC_Parsian_Gateway' ) ) {
11
12 /**
13 * WPP_WC_Parsian_Gateway class to add Parsian Bank payment gateway to WooCommerce
14 *
15 * @package WP-Parsidate
16 * @subpackage Plugins/WooCommerce/PaymentGateways
17 * @since 5.0.0
18 */
19 class WPP_WC_Parsian_Gateway extends WC_Payment_Gateway {
20
21 private $gateway_name;
22 public $redirect_uri;
23 public $description;
24 public $success_massage;
25 public $failed_massage;
26 public $cancelled_massage;
27 public $title;
28 public $parsian_login_account;
29
30 public function __construct() {
31 $this->id = 'parsian';
32 $this->gateway_name = esc_html__( 'Parsian Bank', 'wp-parsidate' );
33 $this->method_title = $this->gateway_name;
34 $this->method_description = $this->gateway_name . ' ' . esc_html__( 'payment gateway (By WP-Parsidate)',
35 'wp-parsidate' );
36 $this->has_fields = true;
37 $this->icon = apply_filters( $this->id . '_logo',
38 Assets::url( "images/woocommerce/$this->id-logo.png" ) );
39 $this->redirect_uri = WC()->api_request_url( $this->get_class() );
40
41 $this->init_form_fields();
42 $this->init_settings();
43
44 $this->parsian_login_account = $this->get_option( 'parsian_login_account' );
45 $this->title = $this->get_option( 'title' );
46 $this->description = $this->get_option( 'description' );
47 $this->success_massage = $this->get_option( 'success_massage' );
48 $this->failed_massage = $this->get_option( 'failed_massage' );
49 $this->cancelled_massage = $this->get_option( 'cancelled_massage' );
50
51 add_action( 'woocommerce_update_options_payment_gateways_' . $this->id,
52 array( $this, 'process_admin_options' ) );
53 add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) );
54 add_action( 'woocommerce_api_' . $this->get_class(), array( $this, 'callback' ) );
55 }
56
57 public function get_class() {
58 return strtolower( get_class( $this ) );
59 }
60
61 public function init_form_fields() {
62 $this->form_fields = apply_filters( 'wpp_wc_' . $this->id . '_gateway_config', array(
63 'enabled' => array(
64 'title' => esc_html__( 'Enabled/Disabled', 'wp-parsidate' ),
65 'type' => 'checkbox',
66 /* translators: %s: Bank name */
67 'label' => sprintf( esc_html__( 'Activate or deactivate %s gateway', 'wp-parsidate' ),
68 $this->gateway_name ),
69 'default' => 'no'
70 ),
71 'parsian_login_account' => array(
72 'title' => esc_html__( 'Gateway password', 'wp-parsidate' ),
73 'type' => 'text',
74 'required' => true,
75 ),
76 'title' => array(
77 'title' => esc_html__( 'Gateway title', 'wp-parsidate' ),
78 'type' => 'text',
79 'description' => esc_html__( 'This name is displayed to the customer during the purchase process',
80 'wp-parsidate' ),
81 'default' => $this->gateway_name
82 ),
83 'description' => array(
84 'title' => esc_html__( 'Gateway description', 'wp-parsidate' ),
85 'type' => 'textarea',
86 'description' => esc_html__( 'The description that will be displayed during the purchase process for the gateway',
87 'wp-parsidate' ),
88 /* translators: %s: Bank name */
89 'default' => sprintf( esc_html__( "Secure payment by all Shatab's cards through %s",
90 'wp-parsidate' ), $this->gateway_name )
91 ),
92 'success_massage' => array(
93 'title' => esc_html__( 'Successful payment message', 'wp-parsidate' ),
94 'type' => 'textarea',
95 'description' => esc_html__( 'Enter the text of the message you want to display to the user after successful payment.',
96 'wp-parsidate' ),
97 'default' => esc_html__( 'Thank you for your purchase. Your order has been successfully placed.',
98 'wp-parsidate' )
99 ),
100 'failed_massage' => array(
101 'title' => esc_html__( 'Payment failed message', 'wp-parsidate' ),
102 'type' => 'textarea',
103 'description' => esc_html__( 'Enter the text of the message you want to display to the user after an unsuccessful payment.',
104 'wp-parsidate' ),
105 'default' => esc_html__( 'Your payment has failed. Please try again or contact us in case of problems.',
106 'wp-parsidate' )
107 ),
108 'cancelled_massage' => array(
109 'title' => esc_html__( 'Payment cancellation message', 'wp-parsidate' ),
110 'type' => 'textarea',
111 'description' => esc_html__( 'Enter the text of the message you want to display after the user cancels the payment. This message will be displayed after returning from the bank.',
112 'wp-parsidate' ),
113 'default' => esc_html__( 'The payment remained incomplete due to your cancellation.',
114 'wp-parsidate' )
115 )
116 )
117 );
118 }
119
120 public static function send_pay_request(
121 $login_account,
122 $amount,
123 $order_id,
124 $redirect,
125 $additional = ''
126 ) {
127 $args = array(
128 'LoginAccount' => $login_account,
129 'Amount' => $amount,
130 'OrderId' => $order_id,
131 'CallBackUrl' => $redirect,
132 'AdditionalData' => $additional
133 );
134
135 if ( WcGateways::getInstance()->is_soap_enabled() ) {
136 try {
137 $client = new SoapClient( 'https://pec.shaparak.ir/NewIPGServices/Sale/SaleService.asmx?WSDL',
138 array(
139 'soap_version' => 'SOAP_1_1',
140 'cache_wsdl' => WSDL_CACHE_NONE,
141 'encoding' => 'UTF-8'
142 ) );
143 $result = $client->SalePaymentRequest( array( "requestData" => $args ) );
144 $output = array(
145 'Status' => $result->SalePaymentRequestResult->Status,
146 'Token' => $result->SalePaymentRequestResult->Token
147 );
148 } catch ( Exception $e ) {
149 $output = array( 'Status' => '-1', 'Token' => '' );
150 }
151 } else {
152 $output = array( 'Status' => '-2', 'Token' => '' );
153 }
154
155 return (object) $output;
156 }
157
158 public static function verify_request( $login_account, $token ) {
159 $args = array(
160 'LoginAccount' => $login_account,
161 'Token' => $token
162 );
163 if ( WcGateways::getInstance()->is_soap_enabled() ) {
164 try {
165 $client = new SoapClient( 'https://pec.shaparak.ir/NewIPGServices/Confirm/ConfirmService.asmx?WSDL',
166 array(
167 'soap_version' => 'SOAP_1_1',
168 'cache_wsdl' => WSDL_CACHE_NONE,
169 'encoding' => 'UTF-8'
170 ) );
171 $result = $client->ConfirmPayment( array( "requestData" => $args ) );
172 $output['Status'] = $result->ConfirmPaymentResult->Status;
173 $output['RRN'] = $result->ConfirmPaymentResult->RRN;
174 $output['CardNumberMasked'] = $result->ConfirmPaymentResult->CardNumberMasked ?? '';
175 } catch ( Exception $e ) {
176 $output = array( 'Status' => '-1', 'RRN' => '' );
177 }
178 } else {
179 $output = array( 'Status' => '-2', 'RRN' => '' );
180 }
181
182 return (object) $output;
183 }
184
185 public static function reversal_request( $login_account, $token ) {
186 $args = array(
187 'LoginAccount' => $login_account,
188 'Token' => $token
189 );
190
191 if ( WcGateways::getInstance()->is_soap_enabled() ) {
192 try {
193 $client = new SoapClient( 'https://pec.shaparak.ir/NewIPGServices/Reverse/ReversalService.asmx?WSDL',
194 array(
195 'soap_version' => 'SOAP_1_1',
196 'cache_wsdl' => WSDL_CACHE_NONE,
197 'encoding' => 'UTF-8'
198 ) );
199 $result = $client->ReversalRequest( array( "requestData" => $args ) );
200 $output['Status'] = $result->ReversalRequestResult->Status;
201 $output['Token'] = $result->ReversalRequestResult->Token;
202 } catch ( Exception $e ) {
203 $output = array( 'Status' => '-1', 'Token' => '' );
204 }
205 } else {
206 $output = array( 'Status' => '-2', 'Token' => '' );
207 }
208
209 return (object) $output;
210 }
211
212 public static function error_response_handler( $code = '' ) {
213 $error_responses = array(
214 '-32768' => esc_html__( 'An unexpected error has occurred', 'wp-parsidate' ),
215 '-1552' => esc_html__( 'Transaction reversal is not allowed', 'wp-parsidate' ),
216 '-1551' => esc_html__( 'The transaction has already been reversed', 'wp-parsidate' ),
217 '-1550' => esc_html__( 'It is not possible to reverse the transaction in the current state',
218 'wp-parsidate' ),
219 '-1549' => esc_html__( 'The time allowed to request a transaction reversal has expired',
220 'wp-parsidate' ),
221 '-1548' => esc_html__( 'The bill payment request service call failed', 'wp-parsidate' ),
222 '-1540' => esc_html__( 'Transaction confirmation is unsuccessful', 'wp-parsidate' ),
223 '-1536' => esc_html__( 'The top-up charge request service call failed', 'wp-parsidate' ),
224 '-1533' => esc_html__( 'The transaction has already been confirmed', 'wp-parsidate' ),
225 '1532' => esc_html__( 'The transaction was confirmed by the recipient', 'wp-parsidate' ),
226 '-1531' => esc_html__( 'The transaction was unsuccessful due to your withdrawal from the bank',
227 'wp-parsidate' ),
228 '-1530' => esc_html__( 'The merchant is not authorized to confirm this transaction',
229 'wp-parsidate' ),
230 '-1528' => esc_html__( 'Payment information not found', 'wp-parsidate' ),
231 '-1527' => esc_html__( 'The purchase transaction payment request operation failed',
232 'wp-parsidate' ),
233 '-1507' => esc_html__( 'The transaction was sent back to the switch', 'wp-parsidate' ),
234 '-1505' => esc_html__( 'The transaction was confirmed by the merchant', 'wp-parsidate' ),
235 '-132' => esc_html__( 'The transaction amount is less than the minimum allowed',
236 'wp-parsidate' ),
237 '-131' => esc_html__( 'Token is invalid', 'wp-parsidate' ),
238 '-130' => esc_html__( 'Token has expired', 'wp-parsidate' ),
239 '-128' => esc_html__( 'The IP address format is not valid', 'wp-parsidate' ),
240 '-127' => esc_html__( 'The URL is not valid', 'wp-parsidate' ),
241 '-126' => esc_html__( "The merchant's identification code is not valid", 'wp-parsidate' ),
242 '-121' => esc_html__( 'The given string is not entirely numeric', 'wp-parsidate' ),
243 '-120' => esc_html__( 'The length of the input data is not valid', 'wp-parsidate' ),
244 '-119' => esc_html__( 'The organization is invalid', 'wp-parsidate' ),
245 '-118' => esc_html__( 'The value sent is not a number', 'wp-parsidate' ),
246 '-117' => esc_html__( 'The string length is less than the allowed limit', 'wp-parsidate' ),
247 '-116' => esc_html__( 'The length of the string exceeds the allowed limit', 'wp-parsidate' ),
248 '-115' => esc_html__( 'The payment ID is invalid', 'wp-parsidate' ),
249 '-114' => esc_html__( 'The bill ID is invalid', 'wp-parsidate' ),
250 '-113' => esc_html__( 'The input parameter is empty', 'wp-parsidate' ),
251 '-112' => esc_html__( 'The order number is duplicate', 'wp-parsidate' ),
252 '-111' => esc_html__( "The transaction amount is more than the merchant's limit",
253 'wp-parsidate' ),
254 '-108' => esc_html__( 'The ability to reverse the transaction is disabled for the merchant',
255 'wp-parsidate' ),
256 '-107' => esc_html__( 'The ability to send transaction confirmation is disabled for the merchant',
257 'wp-parsidate' ),
258 '-106' => esc_html__( 'Charging is disabled for the merchant', 'wp-parsidate' ),
259 '-105' => esc_html__( 'The top-up feature is disabled for the merchant', 'wp-parsidate' ),
260 '-104' => esc_html__( 'The ability to pay the bill is inactive for the merchant',
261 'wp-parsidate' ),
262 '-103' => esc_html__( 'The purchase feature is disabled for the merchant', 'wp-parsidate' ),
263 '-102' => esc_html__( 'The transaction was successfully rolled back', 'wp-parsidate' ),
264 '-101' => esc_html__( 'The merchant could not be authenticated', 'wp-parsidate' ),
265 '-100' => esc_html__( 'The merchant is inactive', 'wp-parsidate' ),
266 '-1' => esc_html__( 'Server error', 'wp-parsidate' ),
267 '0' => esc_html__( 'The operation is successful', 'wp-parsidate' ),
268 '1' => esc_html__( 'The card issuer refused to complete the transaction', 'wp-parsidate' ),
269 '2' => esc_html__( 'The confirmation operation of this transaction has already been done successfully',
270 'wp-parsidate' ),
271 '3' => esc_html__( 'The store merchant is invalid', 'wp-parsidate' ),
272 '5' => esc_html__( 'The transaction was abandoned', 'wp-parsidate' ),
273 '6' => esc_html__( 'An unknown error occurred', 'wp-parsidate' ),
274 '8' => esc_html__( 'By recognizing the identity of the card holder, the transaction is successful',
275 'wp-parsidate' ),
276 '9' => esc_html__( 'The received request is being followed up', 'wp-parsidate' ),
277 '10' => esc_html__( "The transaction with an amount lower than the requested amount (deficiency in the customer's account) has been accepted",
278 'wp-parsidate' ),
279 '12' => esc_html__( 'The transaction is invalid', 'wp-parsidate' ),
280 '13' => esc_html__( 'The transaction amount is incorrect', 'wp-parsidate' ),
281 '14' => esc_html__( 'The sent card number is invalid (does not exist)', 'wp-parsidate' ),
282 '15' => esc_html__( 'Card issuer is invalid (does not exist)', 'wp-parsidate' ),
283 '17' => esc_html__( 'The requesting customer has been deleted', 'wp-parsidate' ),
284 '20' => esc_html__( 'In a situation where the switch needs to query the card to accept the transaction, it may make a request from the card (terminal), this message indicates that the answer is invalid.',
285 'wp-parsidate' ),
286 '21' => esc_html__( 'If the response to the terminal request does not require any specific response or function, we will have this message.',
287 'wp-parsidate' ),
288 '22' => esc_html__( 'The transaction was suspected of malpractice (card, terminal, card holder), so it was not accepted',
289 'wp-parsidate' ),
290 '30' => esc_html__( 'The message format has errors', 'wp-parsidate' ),
291 '31' => esc_html__( 'The merchant is not supported by the switch', 'wp-parsidate' ),
292 '32' => esc_html__( "The transaction is incompletely completed (for example, a deposit transaction that is completed from the customer's point of view, but needs to be completed)",
293 'wp-parsidate' ),
294 '33' => esc_html__( 'The card has expired', 'wp-parsidate' ),
295 '38' => esc_html__( 'The number of incorrect password entries has exceeded the limit.',
296 'wp-parsidate' ),
297 '39' => esc_html__( 'There is no credit card account', 'wp-parsidate' ),
298 '40' => esc_html__( 'The requested operation is not supported', 'wp-parsidate' ),
299 '41' => esc_html__( 'The card has been declared lost', 'wp-parsidate' ),
300 '43' => esc_html__( 'The card has been declared stolen', 'wp-parsidate' ),
301 '45' => esc_html__( 'The bill can not be paid', 'wp-parsidate' ),
302 '51' => esc_html__( 'The account balance is insufficient', 'wp-parsidate' ),
303 '54' => esc_html__( 'The card has expired', 'wp-parsidate' ),
304 '55' => esc_html__( 'The card password is invalid', 'wp-parsidate' ),
305 '56' => esc_html__( 'The card is invalid', 'wp-parsidate' ),
306 '57' => esc_html__( 'The relevant transaction is not allowed by the card holder',
307 'wp-parsidate' ),
308 '58' => esc_html__( "It is not allowed to perform the relevant transaction by the operator's terminal",
309 'wp-parsidate' ),
310 '59' => esc_html__( 'The card is suspected of fraud', 'wp-parsidate' ),
311 '61' => esc_html__( 'The transaction amount is over the limit', 'wp-parsidate' ),
312 '62' => esc_html__( 'The card is limited', 'wp-parsidate' ),
313 '63' => esc_html__( 'The security measures have been violated', 'wp-parsidate' ),
314 '65' => esc_html__( 'The number of transaction requests exceeds the limit',
315 'wp-parsidate' ),
316 '68' => esc_html__( 'The response required to complete or complete the transaction has arrived too late',
317 'wp-parsidate' ),
318 '69' => esc_html__( 'The number of times the password has been repeated has exceeded the limit',
319 'wp-parsidate' ),
320 '75' => esc_html__( 'The number of incorrect password entries has exceeded the limit',
321 'wp-parsidate' ),
322 '78' => esc_html__( 'The card is not active', 'wp-parsidate' ),
323 '79' => esc_html__( 'The account connected to the card is invalid or has errors',
324 'wp-parsidate' ),
325 '80' => esc_html__( 'The transaction request has been rejected', 'wp-parsidate' ),
326 '81' => esc_html__( 'The card was not accepted', 'wp-parsidate' ),
327 '83' => esc_html__( 'The switch card service provider has not accepted the transaction',
328 'wp-parsidate' ),
329 '84' => esc_html__( 'In transactions that require communication with the exporter, if the exporter is not active, this message will be sent in response.',
330 'wp-parsidate' ),
331 '91' => esc_html__( 'The transaction authorization system is temporarily disabled or the time set for the authorization has expired',
332 'wp-parsidate' ),
333 '92' => esc_html__( 'The destination of the transaction was not found', 'wp-parsidate' ),
334 '93' => esc_html__( 'It is not possible to complete the transaction', 'wp-parsidate' )
335 );
336
337 return $error_responses[ $code ] ?? esc_html__( 'The payment of the transaction was unsuccessful due to cancellation on the bank page',
338 'wp-parsidate' );
339 }
340
341 public static function display_error(
342 $pay_status = '',
343 $tran_id = '',
344 $order_id = '',
345 $is_callback = 1
346 ) {
347 $page_html = '<div dir="rtl" style="font-family:inherit;font-size:12px;line-height: 25px;color:#000000;margin:-25px 0 -23px 0">';
348 $succeed_color = 'style="color:#008800"';
349 $failed_color = 'style="color: #ff0000"';
350 $desc_style = 'style="text-align:center;font-size:12px;margin:15px 0 20px;line-height:25px"';
351 $back_to_checkout = sprintf(
352 '<a href="%s" style="text-decoration:none;box-shadow:none;color:inherit;padding-right:calc(24px + .25em);position:relative"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M20 11.2H6.8l3.7-3.7-1-1L3.9 12l5.6 5.5 1-1-3.7-3.7H20z"></path></svg> %s</a><br/>',
353 esc_url_raw( wc_get_checkout_url() ),
354 esc_html__( 'Back to checkout', 'wp-parsidate' )
355 );
356
357 if ( 'retry' === $pay_status ) {
358 $page_title = esc_html__( 'Temporary error in payment', 'wp-parsidate' );
359 $order_note = esc_html__( 'When the customer returned from the bank, the bank server did not respond, the customer was asked to refresh the page',
360 'wp-parsidate' );
361 $page_html .= '<div style="color:#ff0000;font-weight:bold;font-size:12px;margin:25px">::: ' . esc_html__( 'Temporary error in payment',
362 'wp-parsidate' ) . ' :::</div>
363 <div style="margin-bottom:21px;font-size:12px">' . esc_html__( 'The server of the internet portal has temporarily encountered a problem, to complete the transaction moments later, click on the button below',
364 'wp-parsidate' ) . '</div>
365 <div style="margin:20px 0 25px 0;color:#008800" id="reqreload"><button onclick="reload_page()">' . esc_html__( 'Try again',
366 'wp-parsidate' ) . '</button></div>
367 <script>
368 function reload_page(){
369 document.getElementById("reqreload").innerHTML = "' . esc_html__( 'Trying again please wait..',
370 'wp-parsidate' ) . '";
371 location.reload();
372 }
373 </script>
374 ';
375 } else {
376 $error_messages = array(
377 'reversal_done' => array(
378 'color' => $failed_color,
379 'title' => esc_html__( 'Service delivery error', 'wp-parsidate' ),
380 /* translators: %s: Tracking number */
381 'message' => sprintf( esc_html__( 'Your payment with the tracking number %s has been successfully processed at the bank, but there has been a problem with the service',
382 'wp-parsidate' ), esc_html( $tran_id ) ),
383 'description' => esc_html__( 'The order to return the money to your account has been registered in the bank, if the payment is not returned to your account within the next few hours, contact support (the maximum time to return to the account is 72 hours)',
384 'wp-parsidate' ),
385 'order_note' => esc_html__( "The customer paid the amount, but when returning from the bank, there was a problem in providing the service, the order to return the money to the customer's account was registered in the bank.",
386 'wp-parsidate' ),
387 ),
388 'reversal_error' => array(
389 'color' => $failed_color,
390 'title' => esc_html__( 'Service delivery error', 'wp-parsidate' ),
391 /* translators: %s: Tracking number */
392 'message' => sprintf( esc_html__( 'Your payment with the tracking number %s has been successfully made in the bank, but there is a problem in providing the service!',
393 'wp-parsidate' ), esc_html( $tran_id ) ),
394 'description' => esc_html__( 'The order to return the money to your account has been registered in the bank, if the payment is not returned to your account within the next few hours, contact support (the maximum time to return to the account is 72 hours)',
395 'wp-parsidate' ),
396 'order_note' => esc_html__( "The customer paid the amount, but when he returned from the bank, there was a problem in providing the service, there was an error in registering the order to return the money to the customer's account, this customer should either be provided with the service or the amount should be returned to his bank account.",
397 'wp-parsidate' ),
398 ),
399 'already_been_completed' => array(
400 'color' => $succeed_color,
401 'title' => esc_html__( 'The order has already been paid', 'wp-parsidate' ),
402 /* translators: %s: Tracking number */
403 'message' => sprintf( esc_html__( 'Your order has already been successfully placed with tracking number %s',
404 'wp-parsidate' ), esc_html( $tran_id ) ),
405 'description' => '',
406 'order_note' => ''
407 ),
408 'order_not_for_this_person' => array(
409 'color' => $failed_color,
410 'title' => esc_html__( 'The order number is incorrect', 'wp-parsidate' ),
411 'message' => esc_html__( 'The order number is incorrect', 'wp-parsidate' ),
412 'description' => esc_html__( 'The order number is incorrect; Call for support if needed',
413 'wp-parsidate' ),
414 'order_note' => ''
415 ),
416 'error_creating_order' => array(
417 'color' => $failed_color,
418 'title' => esc_html__( 'Problem with placing an order', 'wp-parsidate' ),
419 'message' => esc_html__( 'The order number is incorrect', 'wp-parsidate' ),
420 'description' => esc_html__( 'There is a problem with placing an order, please contact support',
421 'wp-parsidate' ),
422 'order_note' => ''
423 )
424 );
425
426 if ( array_key_exists( $pay_status, $error_messages ) ) {
427 $page_title = $error_messages[ $pay_status ]['title'];
428 $order_note = $error_messages[ $pay_status ]['order_note'];
429 $page_html .= sprintf(
430 '<span %s><strong>%s</strong></span><br/><p %s>%s<br>%s</p>%s',
431 $error_messages[ $pay_status ]['color'],
432 $page_title,
433 $desc_style,
434 $error_messages[ $pay_status ]['message'],
435 $error_messages[ $pay_status ]['description'],
436 $back_to_checkout
437 );
438 } elseif ( $is_callback == 0 ) {
439 $page_title = $order_note = esc_html__( 'Error sending to the bank', 'wp-parsidate' );
440 $page_html .= sprintf(
441 '<span %s><strong>%s</strong></span><br/><p %s>%s</p>%s',
442 $failed_color,
443 $page_title,
444 $desc_style,
445 self::error_response_handler( $pay_status ),
446 $back_to_checkout
447 );
448 } else {
449 $page_title = esc_html__( 'Payment was not made', 'wp-parsidate' );
450 $order_note = esc_html__( 'Payment was not made', 'wp-parsidate' ) .
451 ' - ' . self::error_response_handler( $pay_status );
452 $page_html .= sprintf(
453 '<span %s><strong>%s</strong></span><br/><p %s>%s<br>%s</p>%s',
454 $failed_color,
455 $page_title,
456 $desc_style,
457 self::error_response_handler( $pay_status ),
458 esc_html__( 'If the payment has been deducted from your bank account, it will be automatically returned to your account by the bank (the final return time to the account is 72 hours) - contact support if needed.',
459 'wp-parsidate' ),
460 $back_to_checkout,
461 );
462 }
463 }
464
465 $page_html .= '</div>';
466 $order = wc_get_order( $order_id );
467
468 if ( ! empty( $order ) && ! empty( $order_note ) && 'order_not_for_this_person' !== $pay_status ) {
469 $order->add_order_note( $order_note );
470 }
471
472 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
473 wp_die( $page_html, $page_title );
474 }
475
476 public static function redirect_to_bank( $url = '' ): void {
477 if ( ! empty( $url ) ) {
478 if ( headers_sent() ) {
479 echo '<script type="text/javascript">window.location.assign("' . esc_url_raw( $url ) . '")</script>';
480 } else {
481 header( "Location: $url" );
482 }
483
484 exit();
485 }
486 }
487
488 public function process_payment( $order_id ) {
489 $order = wc_get_order( $order_id );
490
491 return array(
492 'result' => 'success',
493 'redirect' => $order->get_checkout_payment_url( true )
494 );
495 }
496
497 public function receipt_page( $order_id ) {
498 if ( $order_id > 0 ) {
499 $order = wc_get_order( $order_id );
500 $currency = strtolower( $order->get_currency() );
501 $amount = absint( $order->get_total() );
502
503 if ( in_array( $currency, array(
504 'irt',
505 'toman',
506 'iran toman',
507 'iranian toman',
508 'iran-toman',
509 'iran_toman',
510 'تو�
511 ان',
512 'تو�
513 ان ایران'
514 ) ) ) {
515 $amount *= 10;
516 } elseif ( 'irht' === $currency ) {
517 $amount *= 1000 * 10;
518 } elseif ( 'irhr' === $currency ) {
519 $amount *= 1000;
520 }
521
522 $login_account = $this->parsian_login_account;
523 $callback_url = $this->redirect_uri . "?order_id=" . $order_id;
524 $order_id .= wp_rand( 1, 10000 );
525 $request = self::send_pay_request( $login_account, $amount, $order_id, $callback_url );
526
527 if ( $request->Status === '0' && $request->Token > 0 ) {
528 self::redirect_to_bank( 'https://pec.shaparak.ir/NewIPG/?Token=' . $request->Token );
529
530 exit();
531 }
532
533 $error_code = $request->Status;
534 } else {
535 $error_code = 'error_creating_order';
536 }
537
538 self::display_error( $error_code, '', $order_id, 0 );
539
540 return false;
541 }
542
543 public function callback() {
544 $token = sanitize_text_field( wp_unslash( $_REQUEST['Token'] ?? '' ) );
545 $status = sanitize_text_field( wp_unslash( $_REQUEST['status'] ?? '' ) );
546 $order_id = (int) sanitize_text_field( wp_unslash( $_REQUEST['order_id'] ?? '' ) );
547
548 //$order_id = isset( $_GET['order_id'] ) ? (int) $_GET['order_id'] : 0;
549 $order = wc_get_order( $order_id );
550
551 if ( $order ) {
552 if ( $status === '0' && $token > 0 ) {
553
554 $login_account = $this->parsian_login_account;
555 $request = self::verify_request( $login_account, $token );
556
557 if ( $request->Status == '0' && $request->RRN > 0 ) {
558
559 // Set Payment Completed
560 $order->payment_complete( $request->RRN );
561
562 // Add Order Note
563 $order->add_order_note( sprintf( 'پرداخت با �
564 وفقیت انجا�
565 شد. کد پیگیری: %s',
566 $request->RRN ) );
567
568 // Remove cart.
569 WC()->cart->empty_cart();
570
571 // Action
572 do_action( 'wpp_wc_' . $this->id . '_gateway_completed_payment', $order, [
573 'RRN' => $request->RRN,
574 'Token' => $token
575 ] );
576
577 // Redirect
578 wp_safe_redirect( esc_url_raw( $this->get_return_url( $order ) ) );
579 exit;
580 }
581
582 $reversal_request = self::reversal_request( $login_account, $token );
583 if ( $reversal_request == '0' ) {
584 $error_code = 'reversal_done';
585 } else {
586 $error_code = 'reversal_error';
587 }
588 } else {
589 $error_code = '-32768';
590 }
591 } else {
592 $error_code = 'order_not_exist';
593 }
594
595 self::display_error( $error_code, $token, $order_id );
596 exit;
597 }
598 }
599 }
600 }
601
602 add_action( 'before_woocommerce_init', 'wpp_parsian_payment_gateway_init', 15 );
603 }
604