diff --git a/README.md b/README.md index 2717b40..185876c 100755 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # PayWeb_WooCommerce -## PayGate WooCommerce plugin v1.4.0 for WooCommerce v4.3.1 +## PayGate WooCommerce plugin v1.4.1 for WooCommerce v4.5.2 This is the PayGate PayWeb3 plugin for WooCommerce. Please feel free to contact the PayGate support team at support@paygate.co.za should you require any assistance. ## Installation [![How To Setup PayGate PayWeb for WooCommerce](https://www.appinlet.com/wp-content/uploads/2018/09/WooCommerce-Integration.jpg)](https://www.youtube.com/watch?v=MMcEG7FmoEM "How To Setup PayGate PayWeb for WooCommerce") -Please navigate to the [releases page](https://github.com/PayGate/PayWeb_WooCommerce/releases), download the latest release (v1.4.0) and unzip. You will them be able to follow the integration guide PDF which is included in the zip. +Please navigate to the [releases page](https://github.com/PayGate/PayWeb_WooCommerce/releases), download the latest release (v1.4.1) and unzip. You will them be able to follow the integration guide PDF which is included in the zip. ## Collaboration diff --git a/changelog.txt b/changelog.txt index eb197cb..bac8479 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ += 1.4.1 - Sep 18, 2020 +* Add alternate cart handling if cart is not cleared upon successful transaction. +* Compatibility with WordPress 5.5.1. + = 1.4.0 - Aug 03, 2020 * Tested with WooCommerce 4.3.1. * Add payment types selection on checkout (SiD, eWallet etc.) diff --git a/classes/WC_Gateway_PayGate.php b/classes/WC_Gateway_PayGate.php index 4d15f47..61b24bf 100644 --- a/classes/WC_Gateway_PayGate.php +++ b/classes/WC_Gateway_PayGate.php @@ -48,6 +48,7 @@ class WC_Gateway_PayGate extends WC_Payment_Gateway const REDIRECT = 'redirect'; const IFRAME = 'iframe'; const DISABLENOTIFY = 'disablenotify'; + const ALTERNATECARTHANDLING = 'alternatecarthandling'; const TRANSACTION_STATUS = 'TRANSACTION_STATUS'; const RESULT_CODE = 'RESULT_CODE'; const RESULT_DESC = 'RESULT_DESC'; @@ -343,6 +344,16 @@ public function init_form_fields() self::DESC_TIP => true, self::DEFAULT_CONST => 'no', ), + self::ALTERNATECARTHANDLING => array( + self::TITLE => __('Alternate Cart Handling', self::ID), + self::TYPE => self::CHECKBOX, + self::DESCRIPTION => __( + 'Enable this if your cart is not cleared upon successful transaction.', + self::ID + ), + self::DESC_TIP => true, + self::DEFAULT_CONST => 'no', + ), self::DESCRIPTION => array( self::TITLE => __('Description', self::ID), self::TYPE => 'textarea', @@ -578,10 +589,13 @@ public function process_payment($order_id) */ public function get_ajax_return_data_json($order_id) { - if (session_status() === PHP_SESSION_NONE) { - session_start(); + if (session_status() !== PHP_SESSION_NONE) { + $_SESSION['POST'] = $_POST; + } + + if ($this->settings[self::ALTERNATECARTHANDLING] == 'yes') { + WC()->cart->empty_cart(); } - $_SESSION['POST'] = $_POST; $initiate = new WC_Gateway_PayGate_Portal(); $returnParams = $initiate->initiate_transaction($order_id); diff --git a/classes/WC_Gateway_PayGate_Portal.php b/classes/WC_Gateway_PayGate_Portal.php index 921e9ef..437d603 100644 --- a/classes/WC_Gateway_PayGate_Portal.php +++ b/classes/WC_Gateway_PayGate_Portal.php @@ -176,6 +176,10 @@ public function generate_paygate_form($order_id) $order = new WC_Order($order_id); $parsed_response = $this->initiate_transaction($order_id); + if ($this->settings[self::ALTERNATECARTHANDLING] == 'yes') { + WC()->cart->empty_cart(); + } + if ( ! is_wp_error($parsed_response)) { unset($parsed_response[self::CHECKSUM]); $checksum = md5(implode('', $parsed_response) . $this->encryption_key); @@ -489,6 +493,19 @@ protected function setVaultableMethod() */ protected function processOrderFinal($status, $order, $transaction_id, $result_desc, $pay_request_id) { + if ($this->settings[self::ALTERNATECARTHANDLING] == 'yes') { + // Alternative cart mechanism + if (count($order->get_items()) > 0) { + foreach ($order->get_items() as $product) { + $product_id = isset($product['product_id']) ? (int)$product['product_id'] : 0; + $quantity = isset($product['quantity']) ? (int)$product['quantity'] : 1; + $variation_id = isset($product['variation_id']) ? (int)$product['variation_id'] : 0; + $variation = isset($product['variation']) ? (array)$product['variation'] : array(); + WC()->cart->add_to_cart($product_id, $quantity, $variation_id, $variation); + } + WC()->cart->calculate_totals(); + } + } switch ($status) { case 1: $this->processOrderFinalSuccess($order, $transaction_id, $pay_request_id); diff --git a/gateway-paygate.php b/gateway-paygate.php index e2a227c..ef8ba07 100755 --- a/gateway-paygate.php +++ b/gateway-paygate.php @@ -3,8 +3,8 @@ * Plugin Name: PayGate PayWeb3 plugin for WooCommerce * Plugin URI: https://github.com/PayGate/PayWeb_WooCommerce * Description: Accept payments for WooCommerce using PayGate's PayWeb3 service - * Version: 1.4.0 - * Tested: 5.4.2 + * Version: 1.4.1 + * Tested: 5.5.1 * Author: PayGate (Pty) Ltd * Author URI: https://www.paygate.co.za/ * Developer: App Inlet (Pty) Ltd @@ -33,10 +33,6 @@ function woocommerce_paygate_init() return; } - if ( ! headers_sent() && session_status() === PHP_SESSION_NONE) { - session_start(); - } - require_once plugin_basename('classes/WC_Gateway_PayGate.php'); add_filter('woocommerce_payment_gateways', 'woocommerce_add_paygate_gateway'); @@ -79,7 +75,7 @@ function woocommerce_paygate_init() 'homepage' => 'https://github.com/PayGate/PayWeb_WooCommerce', 'sslverify' => true, 'requires' => '4.0', - 'tested' => '5.4.2', + 'tested' => '5.5.1', 'readme' => 'README.md', 'access_token' => '', );