From 87c2c7268b171bb430db24dbf8182c341f9a3cd5 Mon Sep 17 00:00:00 2001 From: "dimaspolohov@yandex.ru" Date: Mon, 9 Oct 2023 13:36:02 +0300 Subject: [PATCH 1/3] Autocancel option remove --- includes/Gateways/ReepayCheckout.php | 11 ----------- includes/Gateways/ReepayGateway.php | 8 -------- includes/OrderFlow/OrderStatuses.php | 2 +- reepay-woocommerce-payment.php | 1 - tests/unit/orderFlow/OrderStatusesTest.php | 7 ------- 5 files changed, 1 insertion(+), 28 deletions(-) diff --git a/includes/Gateways/ReepayCheckout.php b/includes/Gateways/ReepayCheckout.php index cea76f5c..caeb30c3 100644 --- a/includes/Gateways/ReepayCheckout.php +++ b/includes/Gateways/ReepayCheckout.php @@ -81,7 +81,6 @@ public function __construct() { $this->payment_type = $this->settings['payment_type'] ?: $this->payment_type; $this->payment_methods = $this->settings['payment_methods'] ?: $this->payment_methods; $this->skip_order_lines = $this->settings['skip_order_lines'] ?: $this->skip_order_lines; - $this->enable_order_autocancel = $this->settings['enable_order_autocancel'] ?: $this->enable_order_autocancel; $this->failed_webhooks_email = $this->settings['failed_webhooks_email'] ?: $this->failed_webhooks_email; $this->handle_failover = $this->settings['handle_failover'] ?: $this->handle_failover; @@ -381,16 +380,6 @@ public function init_form_fields() { ), 'default' => 'no', ), - 'enable_order_autocancel' => array( - 'title' => __( 'The automatic order auto-cancel', 'reepay-checkout-gateway' ), - 'description' => __( 'The automatic order auto-cancel', 'reepay-checkout-gateway' ), - 'type' => 'select', - 'options' => array( - 'yes' => 'Enable auto-cancel', - 'no' => 'Ignore / disable auto-cancel', - ), - 'default' => 'no', - ), 'payment_button_text' => array( 'title' => __( 'Payment button text', 'reepay-checkout-gateway' ), 'type' => 'text', diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index 80a75ad8..dcc517fa 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -135,13 +135,6 @@ abstract class ReepayGateway extends WC_Payment_Gateway { */ public string $skip_order_lines = 'no'; - /** - * If automatically cancel unpaid orders should be ignored - * - * @var string - */ - public string $enable_order_autocancel = 'no'; - /** * Email address for notification about failed webhooks * @@ -1396,7 +1389,6 @@ protected function apply_parent_settings() { $this->debug = (string) reepay()->get_setting( 'debug' ); $this->payment_type = (string) reepay()->get_setting( 'payment_type' ); $this->skip_order_lines = (string) reepay()->get_setting( 'skip_order_lines' ); - $this->enable_order_autocancel = (string) reepay()->get_setting( 'enable_order_autocancel' ); $this->handle_failover = (string) reepay()->get_setting( 'handle_failover' ); } diff --git a/includes/OrderFlow/OrderStatuses.php b/includes/OrderFlow/OrderStatuses.php index 46dc89a1..bf3e1a08 100644 --- a/includes/OrderFlow/OrderStatuses.php +++ b/includes/OrderFlow/OrderStatuses.php @@ -373,7 +373,7 @@ public function is_paid( bool $is_paid, WC_Order $order ): bool { * @see wc_cancel_unpaid_orders() */ public function cancel_unpaid_order( bool $maybe_cancel, WC_Order $order ): bool { - if ( $maybe_cancel && rp_is_order_paid_via_reepay( $order ) && 'yes' !== reepay()->get_setting( 'enable_order_autocancel' ) ) { + if ( $maybe_cancel && rp_is_order_paid_via_reepay( $order ) ) { $maybe_cancel = false; } diff --git a/reepay-woocommerce-payment.php b/reepay-woocommerce-payment.php index b0910707..b9b2859c 100755 --- a/reepay-woocommerce-payment.php +++ b/reepay-woocommerce-payment.php @@ -160,7 +160,6 @@ public function get_setting( string $name ) { 'debug' => ! empty( $gateway_settings['debug'] ) ? $gateway_settings['debug'] : '', 'payment_type' => ! empty( $gateway_settings['payment_type'] ) ? $gateway_settings['payment_type'] : '', 'skip_order_lines' => ! empty( $gateway_settings['skip_order_lines'] ) ? $gateway_settings['skip_order_lines'] : '', - 'enable_order_autocancel' => ! empty( $gateway_settings['enable_order_autocancel'] ) ? $gateway_settings['enable_order_autocancel'] : '', 'is_webhook_configured' => ! empty( $gateway_settings['is_webhook_configured'] ) ? $gateway_settings['is_webhook_configured'] : '', 'handle_failover' => ! empty( $gateway_settings['handle_failover'] ) ? $gateway_settings['handle_failover'] : '', 'payment_button_text' => ! empty( $gateway_settings['payment_button_text'] ) ? $gateway_settings['payment_button_text'] : '', diff --git a/tests/unit/orderFlow/OrderStatusesTest.php b/tests/unit/orderFlow/OrderStatusesTest.php index 5ae5341d..3a420edc 100644 --- a/tests/unit/orderFlow/OrderStatusesTest.php +++ b/tests/unit/orderFlow/OrderStatusesTest.php @@ -593,7 +593,6 @@ public function test_is_paid( bool $default_value, bool $status_sync_enabled, bo * * @param bool $default_value * @param bool $paid_via_reepay - * @param bool $enabled_order_autocancel * @param bool $expected_value * * @testWith @@ -611,12 +610,6 @@ public function test_cancel_unpaid_order( bool $default_value, bool $paid_via_re $this->order_generator->set_prop( 'payment_method', reepay()->gateways()->checkout() ); } - self::$options->set_options( - array( - 'enable_order_autocancel' => $enabled_order_autocancel ? 'yes' : 'no', - ) - ); - $this->assertSame( $expected_value, $this->order_statuses->cancel_unpaid_order( $default_value, $this->order_generator->order() ), From 19a298c108e81d42dee787ae64e7cac656aa5e9e Mon Sep 17 00:00:00 2001 From: "dimaspolohov@yandex.ru" Date: Wed, 11 Oct 2023 12:54:17 +0300 Subject: [PATCH 2/3] PW WooCommerce Gift Cards add support --- includes/Gateways/ReepayGateway.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/includes/Gateways/ReepayGateway.php b/includes/Gateways/ReepayGateway.php index dcc517fa..1ab2e3f7 100644 --- a/includes/Gateways/ReepayGateway.php +++ b/includes/Gateways/ReepayGateway.php @@ -1555,6 +1555,21 @@ public function get_order_items( WC_Order $order, $only_not_settled = false ): a ); } + + // Add "PW Gift Cards" support. + foreach( $order->get_items( 'pw_gift_card' ) as $line ) { + $amount = apply_filters( 'pwgc_to_order_currency', floatval( $line->get_amount() ) * -1, $order ); + + $items[] = array( + // translators: gift card code. + 'ordertext' => sprintf( __( 'PW gift card (%s)', 'reepay-checkout-gateway' ), $line->get_card_number() ), + 'quantity' => 1, + 'amount' => rp_prepare_amount( $amount, $order->get_currency() ), + 'vat' => 0, + 'amount_incl_vat' => $prices_incl_tax, + ); + } + // Add "Gift Up!" discount. if ( defined( 'GIFTUP_ORDER_META_CODE_KEY' ) && defined( 'GIFTUP_ORDER_META_REQUESTED_BALANCE_KEY' ) From 6769743e52c7de158a90c301db7314dbe1e49258 Mon Sep 17 00:00:00 2001 From: "dimaspolohov@yandex.ru" Date: Fri, 13 Oct 2023 13:11:13 +0300 Subject: [PATCH 3/3] Fix subscription change status --- includes/OrderFlow/Webhook.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/OrderFlow/Webhook.php b/includes/OrderFlow/Webhook.php index 91bf7eec..1d8bd8c0 100644 --- a/includes/OrderFlow/Webhook.php +++ b/includes/OrderFlow/Webhook.php @@ -251,11 +251,14 @@ public function process( array $data ) { } } - OrderStatuses::set_settled_status( - $order, - false, - $data['transaction'] - ); + if( empty( $order->get_meta( '_reepay_subscription_handle' ) )){ + OrderStatuses::set_settled_status( + $order, + false, + $data['transaction'] + ); + } + update_post_meta( $order->get_id(), '_reepay_capture_transaction', $data['transaction'] );