Skip to content

Commit

Permalink
restock (#52)
Browse files Browse the repository at this point in the history
* Restock items in IPN refund

* Fix logo size
  • Loading branch information
agamystar authored May 31, 2023
1 parent 5de8ca7 commit 9f31a59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Binary file modified icons/paytabs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 21 additions & 3 deletions includes/paytabs_payment_methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ public function init_form_fields()
. "<br>Supported events: <strong>Capture (Full)</strong>, <strong>Void (Full)</strong>, <strong>Refund (Full & Partial)</strong>.",
'required' => false,
),
'restock_items' => array(
'title' => __('Restock refunded items (IPN)', 'PayTabs'),
'type' => 'checkbox',
'description' => 'Refund isssued on PayTabs Dashboard will be reflected on your Store (if IPN option enabled), This option will Restock all the orders\' items if the refund amount matched the remaining refund amount, So <strong>use carefully if there is a cross use between the Woo admin refund & PayTabs dashboard refund</strong>.',
'default' => 'yes'
),
'failed_send_note' => array(
'title' => __('Send a note on payment failure', 'PayTabs'),
'type' => 'checkbox',
Expand Down Expand Up @@ -1001,18 +1007,30 @@ public function pt_process_ipn($ipn_data)
return;
}

$restock = $this->get_option('restock_items') == 'yes';
$line_items = [];
if ($restock) {
if ($order->get_remaining_refund_amount() == $pt_tran_total) {
// IPN does not contain the refunded items
// if the refund match the total remaining amount => restock all items
// issue happens if the Woo admin create a Refund, then another Refund triggered from IPN => items restock twice
$line_items = $order->get_items();
}
}

$refund = wc_create_refund([
'amount' => $pt_tran_total,
'reason' => 'PayTabs dashboard',
'order_id' => $pt_order_id,
'refund_payment' => false,
// 'refund_id' => 0,
// 'line_items' => $line_items,
// 'restock_items' => false
'line_items' => $line_items,
'restock_items' => $restock,
]);

if (!is_wp_error($refund)) {
PaytabsHelper::log("{$pt_tran_type} done, {$pt_order_id} - {$pt_tran_ref}", 1);
$cnt = count($line_items);
PaytabsHelper::log("{$pt_tran_type} done, {$pt_order_id} - {$pt_tran_ref} - Refund ({$refund->get_id()}) - Restock ($restock - $cnt items)", 1);
$this->pt_set_tran_ref($order, $pt_tran_type, $pt_tran_ref);
// $this->setNewStatus($order, true, $pt_tran_type, true);
} else {
Expand Down
4 changes: 2 additions & 2 deletions paytabs-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin URI: https://paytabs.com/
* Description: PayTabs is a <strong>3rd party payment gateway</strong>. Ideal payment solutions for your internet business.
* Version: 4.16.2
* Version: 4.16.3
* Requires PHP: 7.0
* Author: PayTabs
* Author URI: [email protected]
Expand All @@ -21,7 +21,7 @@



define('PAYTABS_PAYPAGE_VERSION', '4.16.2');
define('PAYTABS_PAYPAGE_VERSION', '4.16.3');
define('PAYTABS_PAYPAGE_DIR', plugin_dir_path(__FILE__));
define('PAYTABS_PAYPAGE_ICONS_URL', plugins_url("icons/", __FILE__));
define('PAYTABS_PAYPAGE_IMAGES_URL', plugins_url("images/", __FILE__));
Expand Down

0 comments on commit 9f31a59

Please sign in to comment.