Skip to content

Commit

Permalink
Merge pull request #38 from appinlet/release/1.4.1
Browse files Browse the repository at this point in the history
Release/1.4.1
  • Loading branch information
appinlet authored Sep 18, 2020
2 parents d8627b7 + 8bb230c commit 097b911
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 [email protected] 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

Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.)
Expand Down
20 changes: 17 additions & 3 deletions classes/WC_Gateway_PayGate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions classes/WC_Gateway_PayGate_Portal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions gateway-paygate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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' => '',
);
Expand Down

0 comments on commit 097b911

Please sign in to comment.