|
3 | 3 | /**
|
4 | 4 | * Class WC_TPAYWAY
|
5 | 5 | *
|
6 |
| - * WC_TPAYWAY with API 2.0 |
| 6 | + * WC_TPAYWAY with API 2.0.9 |
7 | 7 | */
|
8 | 8 | class WC_TPAYWAY extends WC_Payment_Gateway
|
9 | 9 | {
|
@@ -343,7 +343,7 @@ public function generate_ipg_form($order_id)
|
343 | 343 |
|
344 | 344 | $order_format_value = str_pad(($order_total * 100), 12, '0', STR_PAD_LEFT);
|
345 | 345 | $total_amount = number_format($order_total, 2, '', '');
|
346 |
| - $total_amount_request = number_format($order_total, 2, ',', ''); |
| 346 | + $total_amount_request = number_format($order_total, 2, ',', ''); |
347 | 347 |
|
348 | 348 | $secret_key = $this->acq_id; // Secret key
|
349 | 349 |
|
@@ -485,18 +485,19 @@ function check_tcompayway_response()
|
485 | 485 |
|
486 | 486 | // Return if is error during installation
|
487 | 487 | if (!$_POST['ShoppingCartID']) {
|
488 |
| - return; |
| 488 | + return; |
489 | 489 | }
|
490 | 490 |
|
491 | 491 | if (!$_POST['Amount']) {
|
492 |
| - return; |
493 |
| - } |
494 |
| - // End installation |
| 492 | + $amount = 0; |
| 493 | + } else { |
| 494 | + $amount = $_POST['Amount']; |
| 495 | + } |
495 | 496 |
|
496 | 497 | $order_id = $_POST['ShoppingCartID'];
|
497 | 498 |
|
498 | 499 | $order = new WC_Order($order_id);
|
499 |
| - $amount = $this->sanitize($_POST['Amount']); |
| 500 | + $amount = $this->sanitize($amount); |
500 | 501 | $status = isset($_POST['Success']) ? (int)$_POST['Success'] : 0;
|
501 | 502 | $reasonCode = isset($_POST['ApprovalCode']) ? (int)$_POST['ApprovalCode'] : 0;
|
502 | 503 |
|
@@ -546,11 +547,47 @@ function check_tcompayway_response()
|
546 | 547 | $order->payment_complete();
|
547 | 548 |
|
548 | 549 | wp_redirect($this->get_return_url($order), 302);
|
549 |
| - exit; |
| 550 | + exit; |
550 | 551 | }
|
551 | 552 | }
|
552 | 553 |
|
553 | 554 | if (isset($_POST['Success'])) {
|
| 555 | + if (isset($_POST['ResponseCode'])) { |
| 556 | + $responseCode = (int)$_POST['ResponseCode']; |
| 557 | + if ($responseCode == 15 || $responseCode == 16) { |
| 558 | + |
| 559 | + $order->add_order_note($this->get_response_codes($responseCode) . " (Code $responseCode)"); |
| 560 | + $order->update_status('cancelled'); |
| 561 | + $woocommerce->cart->empty_cart(); |
| 562 | + |
| 563 | + global $wpdb; |
| 564 | + $table_name = $wpdb->prefix . 'tpayway_ipg'; |
| 565 | + $wpdb->update( |
| 566 | + $table_name, |
| 567 | + array( |
| 568 | + 'response_code' => $responseCode, |
| 569 | + 'response_code_desc' => $this->get_response_codes($responseCode), |
| 570 | + 'reason_code' => 0, |
| 571 | + 'status' => 0, |
| 572 | + ), |
| 573 | + array('transaction_id' => $order_id) |
| 574 | + ); |
| 575 | + |
| 576 | + $text = '<html><meta charset="utf-8"><body><center>'; |
| 577 | + $text .= __('A payment was not cancelled', 'tcom-payway-wc') . '<br>'; |
| 578 | + $text .= __('Reason: ', 'tcom-payway-wc'); |
| 579 | + $text .= $this->get_response_codes($responseCode) . '<br>'; |
| 580 | + $text .= __('Order Id: ', 'tcom-payway-wc'); |
| 581 | + $text .= $order_id . '<br>'; |
| 582 | + $text .= __('Redirecting...', 'tcom-payway-wc'); |
| 583 | + $text .= '</center><script>setTimeout(function(){ window.location.replace("' . $this->response_url_fail . '"); },3000);</script></body></html>'; |
| 584 | + |
| 585 | + echo $text; |
| 586 | + |
| 587 | + exit; |
| 588 | + } |
| 589 | + } |
| 590 | + |
554 | 591 | if ($_POST['Success'] == "0") {
|
555 | 592 | $errorCodes = json_encode($_POST['ErrorCodes']);
|
556 | 593 |
|
@@ -585,43 +622,6 @@ function check_tcompayway_response()
|
585 | 622 | exit;
|
586 | 623 | }
|
587 | 624 | }
|
588 |
| - |
589 |
| - // Cancelled |
590 |
| - if (isset($_POST['ResponseCode'])) { |
591 |
| - $responseCode = (int)$_POST['ResponseCode']; |
592 |
| - if ($responseCode == 15 || $responseCode == 16) { |
593 |
| - |
594 |
| - $order->add_order_note($this->get_response_codes($responseCode) . " (Code $responseCode)"); |
595 |
| - $order->update_status('cancelled'); |
596 |
| - $woocommerce->cart->empty_cart(); |
597 |
| - |
598 |
| - global $wpdb; |
599 |
| - $table_name = $wpdb->prefix . 'tpayway_ipg'; |
600 |
| - $wpdb->update( |
601 |
| - $table_name, |
602 |
| - array( |
603 |
| - 'response_code' => $responseCode, |
604 |
| - 'response_code_desc' => $this->get_response_codes($responseCode), |
605 |
| - 'reason_code' => 0, |
606 |
| - 'status' => 0, |
607 |
| - ), |
608 |
| - array('transaction_id' => $order_id) |
609 |
| - ); |
610 |
| - |
611 |
| - $text = '<html><meta charset="utf-8"><body><center>'; |
612 |
| - $text .= __('A payment was not cancelled', 'tcom-payway-wc') . '<br>'; |
613 |
| - $text .= __('Reason: ', 'tcom-payway-wc'); |
614 |
| - $text .= $this->get_response_codes($responseCode) . '<br>'; |
615 |
| - $text .= __('Order Id: ', 'tcom-payway-wc'); |
616 |
| - $text .= $order_id . '<br>'; |
617 |
| - $text .= __('Redirecting...', 'tcom-payway-wc'); |
618 |
| - $text .= '</center><script>setTimeout(function(){ window.location.replace("' . $this->response_url_fail . '"); },3000);</script></body></html>'; |
619 |
| - |
620 |
| - echo $text; |
621 |
| - |
622 |
| - exit; |
623 |
| - } |
624 |
| - } |
625 | 625 | }
|
626 | 626 |
|
627 | 627 | function get_pages($title = false, $indent = true)
|
|
0 commit comments