Skip to content

Commit

Permalink
Merge pull request #25 from marinsagovac/feature/1.7.2
Browse files Browse the repository at this point in the history
Feature/1.7.2
  • Loading branch information
marinsagovac committed Jan 7, 2023
2 parents 3cb3515 + f7e539b commit a642305
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Most recent latest changes is defined on every major, minor and bug fixes.

## Versions

### 1.7.2

* Hotfix on on cancelling order will not empty cart

### 1.7.1

* Change HNB URL tecajna to v3
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ Latest version:

API 2.x.x:

* Version [1.7.2](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.7.2.zip) January/2023
* Version [1.7.1](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.7.1.zip) January/2023
* Version [1.7](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.7.zip) December/2022
* Version [1.6.1](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.6.1.zip) September/2022

Old releases (not recommended):

* Version [1.7](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.7.zip) December/2022
* Version [1.6.1](https://github.com/marinsagovac/woocommerce-tcom-payway/archive/refs/tags/1.6.1.zip) September/2022
* Version [1.5](https://github.com/marinsagovac/woocommerce-tcom-payway/releases/tags/1.5.zip) November/2021
* Version [1.4](https://github.com/marinsagovac/woocommerce-tcom-payway/releases/tags/1.4.zip) June/2021
* Version [1.3.3](https://github.com/marinsagovac/woocommerce-tcom-payway/releases/tag/1.3.3) January/2021
Expand Down
90 changes: 45 additions & 45 deletions classes/class-wc-tpayway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Class WC_TPAYWAY
*
* WC_TPAYWAY with API 2.0
* WC_TPAYWAY with API 2.0.9
*/
class WC_TPAYWAY extends WC_Payment_Gateway
{
Expand Down Expand Up @@ -343,7 +343,7 @@ public function generate_ipg_form($order_id)

$order_format_value = str_pad(($order_total * 100), 12, '0', STR_PAD_LEFT);
$total_amount = number_format($order_total, 2, '', '');
$total_amount_request = number_format($order_total, 2, ',', '');
$total_amount_request = number_format($order_total, 2, ',', '');

$secret_key = $this->acq_id; // Secret key

Expand Down Expand Up @@ -485,18 +485,19 @@ function check_tcompayway_response()

// Return if is error during installation
if (!$_POST['ShoppingCartID']) {
return;
return;
}

if (!$_POST['Amount']) {
return;
}
// End installation
$amount = 0;
} else {
$amount = $_POST['Amount'];
}

$order_id = $_POST['ShoppingCartID'];

$order = new WC_Order($order_id);
$amount = $this->sanitize($_POST['Amount']);
$amount = $this->sanitize($amount);
$status = isset($_POST['Success']) ? (int)$_POST['Success'] : 0;
$reasonCode = isset($_POST['ApprovalCode']) ? (int)$_POST['ApprovalCode'] : 0;

Expand Down Expand Up @@ -546,11 +547,47 @@ function check_tcompayway_response()
$order->payment_complete();

wp_redirect($this->get_return_url($order), 302);
exit;
exit;
}
}

if (isset($_POST['Success'])) {
if (isset($_POST['ResponseCode'])) {
$responseCode = (int)$_POST['ResponseCode'];
if ($responseCode == 15 || $responseCode == 16) {

$order->add_order_note($this->get_response_codes($responseCode) . " (Code $responseCode)");
$order->update_status('cancelled');
$woocommerce->cart->empty_cart();

global $wpdb;
$table_name = $wpdb->prefix . 'tpayway_ipg';
$wpdb->update(
$table_name,
array(
'response_code' => $responseCode,
'response_code_desc' => $this->get_response_codes($responseCode),
'reason_code' => 0,
'status' => 0,
),
array('transaction_id' => $order_id)
);

$text = '<html><meta charset="utf-8"><body><center>';
$text .= __('A payment was not cancelled', 'tcom-payway-wc') . '<br>';
$text .= __('Reason: ', 'tcom-payway-wc');
$text .= $this->get_response_codes($responseCode) . '<br>';
$text .= __('Order Id: ', 'tcom-payway-wc');
$text .= $order_id . '<br>';
$text .= __('Redirecting...', 'tcom-payway-wc');
$text .= '</center><script>setTimeout(function(){ window.location.replace("' . $this->response_url_fail . '"); },3000);</script></body></html>';

echo $text;

exit;
}
}

if ($_POST['Success'] == "0") {
$errorCodes = json_encode($_POST['ErrorCodes']);

Expand Down Expand Up @@ -585,43 +622,6 @@ function check_tcompayway_response()
exit;
}
}

// Cancelled
if (isset($_POST['ResponseCode'])) {
$responseCode = (int)$_POST['ResponseCode'];
if ($responseCode == 15 || $responseCode == 16) {

$order->add_order_note($this->get_response_codes($responseCode) . " (Code $responseCode)");
$order->update_status('cancelled');
$woocommerce->cart->empty_cart();

global $wpdb;
$table_name = $wpdb->prefix . 'tpayway_ipg';
$wpdb->update(
$table_name,
array(
'response_code' => $responseCode,
'response_code_desc' => $this->get_response_codes($responseCode),
'reason_code' => 0,
'status' => 0,
),
array('transaction_id' => $order_id)
);

$text = '<html><meta charset="utf-8"><body><center>';
$text .= __('A payment was not cancelled', 'tcom-payway-wc') . '<br>';
$text .= __('Reason: ', 'tcom-payway-wc');
$text .= $this->get_response_codes($responseCode) . '<br>';
$text .= __('Order Id: ', 'tcom-payway-wc');
$text .= $order_id . '<br>';
$text .= __('Redirecting...', 'tcom-payway-wc');
$text .= '</center><script>setTimeout(function(){ window.location.replace("' . $this->response_url_fail . '"); },3000);</script></body></html>';

echo $text;

exit;
}
}
}

function get_pages($title = false, $indent = true)
Expand Down

0 comments on commit a642305

Please sign in to comment.