From 9ae7762a1960001a3ea8006ca9431094403c0c88 Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Mon, 26 Apr 2021 17:19:10 +0700 Subject: [PATCH 1/8] prevent CF wp plugin conflict cause payment page to reload in loop - replace `DOMContentLoaded` event listener with usual closure func used in WP plugin JS asset - to prevent issue when using Cloudflare WP plugin, which use rocket-loader js , which somehow cause `DOMContentLoaded` event to be fired twice - which cause execSnapCont executed twice, which cause bug of payment page get auto-refreshed due to auto refresh mechanism --- public/js/midtrans-payment-page-main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/js/midtrans-payment-page-main.js b/public/js/midtrans-payment-page-main.js index 80b0897..fd55bc2 100644 --- a/public/js/midtrans-payment-page-main.js +++ b/public/js/midtrans-payment-page-main.js @@ -1,8 +1,8 @@ // wc_midtrans var is passed from payment-page backend via inline script. -var payButton = document.getElementById("pay-button"); +;(function( $, window, document ) { + var payButton = document.getElementById("pay-button"); -document.addEventListener("DOMContentLoaded", function(event) { function MixpanelTrackResult(token, merchant_id, cms_name, cms_version, plugin_name, plugin_version, status, result) { var eventNames = { pay: 'pg-pay', @@ -225,4 +225,5 @@ document.addEventListener("DOMContentLoaded", function(event) { handlePayAction(); payButton.innerHTML = "Proceed To Payment"; -}); \ No newline at end of file +})( jQuery, window, document ); +// well jQuery is not actually used, just for formality \ No newline at end of file From 2bd5dcc8d77b6b66135ff0948e8166cbad8c92da Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Mon, 26 Apr 2021 17:20:46 +0700 Subject: [PATCH 2/8] prevent payment page reload if snap.pay fail-retries exhausted --- public/js/midtrans-payment-page-main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/midtrans-payment-page-main.js b/public/js/midtrans-payment-page-main.js index fd55bc2..d581a28 100644 --- a/public/js/midtrans-payment-page-main.js +++ b/public/js/midtrans-payment-page-main.js @@ -131,10 +131,12 @@ } catch (e){ retryCount++; if(retryCount >= 10){ - location.reload(); payButton.innerHTML = "Loading..."; return; + // stop retrying, let the pay button trigger page refresh + payButton.innerHTML = "Proceed To Payment"; + return 0; } console.log(e); - console.log("Snap not ready yet... Retrying in 1000ms!"); + console.log("Snap.pay() fail to execute... Retrying in 1000ms!"); } finally { if (snapExecuted) { clearInterval(intervalFunction); From 63032de4611615c65dafca65bbdfd2d73258c033 Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Mon, 26 Apr 2021 17:23:05 +0700 Subject: [PATCH 3/8] improve comments --- class/class.midtrans-gateway-notif-handler.php | 3 ++- class/midtrans-admin-settings.php | 1 + public/js/midtrans-payment-page-main.js | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/class/class.midtrans-gateway-notif-handler.php b/class/class.midtrans-gateway-notif-handler.php index afde05b..df1d5cc 100644 --- a/class/class.midtrans-gateway-notif-handler.php +++ b/class/class.midtrans-gateway-notif-handler.php @@ -111,7 +111,7 @@ public function handleMidtransNotificationRequest() { } // if or pending/challenge else if( !empty($sanitized['order_id']) && !empty($sanitized['transaction_status']) && $sanitized['status_code'] == 201) { - // @FIXME: $this->ignore_pending_status is broken, it doesn't refer to plugin class + // @FIXME: $this->ignore_pending_status is broken, it doesn't refer to plugin class, but refer to this own class if(property_exists($this,'ignore_pending_status') && $this->ignore_pending_status == 'yes'){ wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit; @@ -265,6 +265,7 @@ public function handleMidtransValidNotificationRequest( $midtrans_notification ) $order->update_meta_data('_mt_payment_transaction_id',$midtrans_notification->transaction_id); $order->save(); + // @FIXME: $this->ignore_pending_status is broken, it doesn't refer to plugin class, but refer to this own class if(property_exists($this,'ignore_pending_status') && $this->ignore_pending_status == 'yes'){ exit; } diff --git a/class/midtrans-admin-settings.php b/class/midtrans-admin-settings.php index 8fd05f3..6025fbd 100644 --- a/class/midtrans-admin-settings.php +++ b/class/midtrans-admin-settings.php @@ -130,6 +130,7 @@ 'description' => __( 'By default, item stock only reduced if payment status on Midtrans reach pending/success (customer choose payment channel and click pay on payment pop-up). Enable this if you want to immediately reduce item stock when payment pop-up generated/displayed.', 'midtrans-woocommerce' ), 'default' => 'no' ), + // @FIXME: likely buggy, config will not be applied, check gateway-notif-handler.php class to fix the bug 'ignore_pending_status' => array( 'title' => __( 'Ignore Midtrans Transaction Pending Status', 'midtrans-woocommerce' ), 'type' => 'checkbox', diff --git a/public/js/midtrans-payment-page-main.js b/public/js/midtrans-payment-page-main.js index d581a28..deaa3ec 100644 --- a/public/js/midtrans-payment-page-main.js +++ b/public/js/midtrans-payment-page-main.js @@ -50,8 +50,9 @@ var retryCount = 0; var snapExecuted = false; var intervalFunction = 0; - // Continously retry to execute SNAP popup if fail, with 1000ms delay between retry + function execSnapCont(ccDetails){ + // Continously retry to execute SNAP popup if fail, periodically w/ 1000ms delay between retry intervalFunction = setInterval(function() { try{ snap.pay(SNAP_TOKEN, @@ -183,6 +184,7 @@ var clickCount = 0; function handlePayAction() { if(clickCount >= 2){ + // refresh page, hoping reloading all frontend state will fix Snap fail to open location.reload(); payButton.innerHTML = "Loading..."; return; @@ -191,6 +193,7 @@ var isPaymentRequestPlugin = wc_midtrans.is_payment_request_plugin; // Check if this is paymentRequest sub-plugin & paymentRequest is supported if(isPaymentRequestPlugin && window.PaymentRequest){ + // utilize Chrome in-built paymentRequest browser feature for Card txn var payRequest = createPaymentRequest(); payRequest .show() @@ -212,6 +215,7 @@ execSnapCont(ccDetails); }) } else { + // execute snap normally execSnapCont(ccDetails); } clickCount++; From 15e0fe55aa0a5b71a27cc25cfc8a86193a3c1961 Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Mon, 26 Apr 2021 17:25:14 +0700 Subject: [PATCH 4/8] improve config field structure, wording & desc --- README.md | 8 +++- .../class.midtrans-gateway-paymentrequest.php | 2 +- class/class.midtrans-gateway-subscription.php | 2 +- class/class.midtrans-gateway.php | 2 +- class/midtrans-admin-settings.php | 43 +++++++++++-------- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 34d3e5c..c67c293 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,13 @@ Note: This section is optional and only for advanced usage. Available for customization from plugin config: - Payment text label of the payment options - Payment text description of the payment options -- You can also input html tags as the text, to insert something like image +- On both configuration fields above can also input html tags as the text, to insert something like image. For example you can input like this to show images: + +```html +Online Payment via Midtrans +``` + +You can change the image, like if you want to show the logo of banks or payment providers that you are accepting. Additional payment options (radio button) can be activated: - Installment diff --git a/class/class.midtrans-gateway-paymentrequest.php b/class/class.midtrans-gateway-paymentrequest.php index b8214b4..3541a5d 100755 --- a/class/class.midtrans-gateway-paymentrequest.php +++ b/class/class.midtrans-gateway-paymentrequest.php @@ -43,7 +43,7 @@ function init_form_fields() { 'title' => __( 'Acquiring Bank', 'midtrans-woocommerce'), 'type' => 'text', 'label' => __( 'Acquiring Bank', 'midtrans-woocommerce' ), - 'description' => __( 'Leave blank for default.
Specify your acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), + 'description' => __( 'You should leave it empty, it will be auto configured.
Alternatively may specify your card-payment acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), 'default' => '' ), 'bin_number' => array( diff --git a/class/class.midtrans-gateway-subscription.php b/class/class.midtrans-gateway-subscription.php index 8219991..7cc5f27 100644 --- a/class/class.midtrans-gateway-subscription.php +++ b/class/class.midtrans-gateway-subscription.php @@ -60,7 +60,7 @@ function init_form_fields() { 'title' => __( 'Acquiring Bank', 'midtrans-woocommerce'), 'type' => 'text', 'label' => __( 'Acquiring Bank', 'midtrans-woocommerce' ), - 'description' => __( 'Leave blank for default.
Specify your acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), + 'description' => __( 'You should leave it empty, it will be auto configured.
Alternatively may specify your card-payment acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), 'default' => '' ), 'bin_number' => array( diff --git a/class/class.midtrans-gateway.php b/class/class.midtrans-gateway.php index 93cc9d9..c32427e 100755 --- a/class/class.midtrans-gateway.php +++ b/class/class.midtrans-gateway.php @@ -80,7 +80,7 @@ function init_form_fields() { 'title' => __( 'Acquiring Bank', 'midtrans-woocommerce'), 'type' => 'text', 'label' => __( 'Acquiring Bank', 'midtrans-woocommerce' ), - 'description' => __( 'Leave blank for default.
Specify your acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), + 'description' => __( 'You should leave it empty, it will be auto configured.
Alternatively may specify your card-payment acquiring bank for this payment option.
Options: BCA, BRI, DANAMON, MAYBANK, BNI, MANDIRI, CIMB, etc (Only choose 1 bank).' , 'midtrans-woocommerce' ), 'default' => '' ) )); diff --git a/class/midtrans-admin-settings.php b/class/midtrans-admin-settings.php index 6025fbd..65c83bb 100644 --- a/class/midtrans-admin-settings.php +++ b/class/midtrans-admin-settings.php @@ -17,19 +17,6 @@ 'label' => __( 'Enable Midtrans Payment', 'midtrans-woocommerce' ), 'default' => 'no' ), - 'title' => array( - 'title' => __( 'Title', 'midtrans-woocommerce' ), - 'type' => 'text', - 'description' => __( 'This controls the title which the user sees during checkout.', 'midtrans-woocommerce' ), - 'default' => $this->getDefaultTitle(), - 'desc_tip' => true, - ), - 'description' => array( - 'title' => __( 'Customer Message', 'midtrans-woocommerce' ), - 'type' => 'textarea', - 'description' => __( 'This controls the description which the user sees during checkout', 'midtrans-woocommerce' ), - 'default' => $this->getDefaultDescription(), - ), 'merchant_id' => array( 'title' => __("Merchant ID", 'midtrans-woocommerce'), 'type' => 'text', @@ -74,11 +61,29 @@ 'default' => '', 'class' => 'production_settings toggle-midtrans' ), + 'title' => array( + 'title' => __( 'Payment Title', 'midtrans-woocommerce' ), + 'type' => 'text', + 'description' => __( 'This controls the payment label title which the user sees during checkout. This support HTML tags like <img> tag, if you want to include images.', 'midtrans-woocommerce' ), + 'default' => $this->getDefaultTitle(), + // 'desc_tip' => true, + ), + 'description' => array( + 'title' => __( 'Payment Description', 'midtrans-woocommerce' ), + 'type' => 'textarea', + 'description' => __( 'You can customize here the expanded description which the user sees during checkout when they choose this payment. This support HTML tags like <img> tag, if you want to include images.', 'midtrans-woocommerce' ), + 'default' => $this->getDefaultDescription(), + ), + 'advanced_config_separator' => array( + 'title' => __( 'Advanced Config Section - Optional, you can leave them default.', 'midtrans-woocommerce' ), + 'type' => 'title', + 'description' => __( '-- Configurations below is optional and don\'t need to be changed, you can leave them default. Unless you know you want advanced configuration --','midtrans-woocommerce'), + ), 'enable_3d_secure' => array( 'title' => __( 'Enable 3D Secure', 'midtrans-woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable 3D Secure?', 'midtrans-woocommerce' ), - 'description' => __( 'You must enable 3D Secure. + 'description' => __( 'You should enable 3D Secure. Please contact us if you wish to disable this feature in the Production environment.', 'midtrans-woocommerce' ), 'default' => 'yes' ), @@ -91,10 +96,10 @@ 'default' => 'no' ), 'enable_redirect' => array( - 'title' => __( 'Redirect payment page', 'midtrans-woocommerce' ), + 'title' => __( 'Redirect payment mode', 'midtrans-woocommerce' ), 'type' => 'checkbox', - 'label' => __( 'Enable payment page redirection?', 'midtrans-woocommerce' ), - 'description' => __( 'This will redirect customer to Midtrans hosted payment page instead of popup payment page on your website.
Leave it disabled if you are not sure', 'midtrans-woocommerce' ), + 'label' => __( 'Enable redirection for payment page?', 'midtrans-woocommerce' ), + 'description' => __( 'This will redirect customer to Midtrans hosted payment page instead of popup payment page on your website.
Useful if you encounter issue with payment page on your website.', 'midtrans-woocommerce' ), 'class' => 'toggle-advanced', 'default' => 'no' ), @@ -114,7 +119,7 @@ 'title' => __( 'Use Dashboard Finish url', 'midtrans-woocommerce' ), 'type' => 'checkbox', 'label' => 'Use dashboard configured payment finish url?', - 'description' => __( 'This will allow use of Dashboard configured payment finish url instead of auto configured url', 'midtrans-woocommerce' ), + 'description' => __( 'This will alternatively redirect customer to Dashboard configured payment finish url instead of auto configured url, after payment is completed', 'midtrans-woocommerce' ), 'default' => 'no' ), 'ganalytics_id' => array( @@ -135,7 +140,7 @@ 'title' => __( 'Ignore Midtrans Transaction Pending Status', 'midtrans-woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Ignore Midtrans Transaction Pending Status?', 'midtrans-woocommerce' ), - 'description' => __( 'This will prevent customer for being redirected to "order received" page, on unpaid async payment type.
Backend pending notification will also ignored, and not trigger change to "on-hold".
Leave it disabled if you are not sure', 'midtrans-woocommerce' ), + 'description' => __( 'This will prevent customer for being redirected to "order received" page, on unpaid async payment type.
Backend pending notification will also ignored, and will not change to "on-hold" status.
Leave it disabled if you are not sure', 'midtrans-woocommerce' ), 'class' => 'toggle-advanced', 'default' => 'no' ), From 9a044a20351169b752a8fc24a8f01f494a960abc Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Tue, 27 Apr 2021 16:14:29 +0700 Subject: [PATCH 5/8] fix: ignore_pending_status config not applied on notif handler - bug was not reading the config value on notif handler. - fixed to read config value from main plugin class config (does not read from sub plugin class config) --- .../class.midtrans-gateway-notif-handler.php | 41 +++++++++++++++---- class/midtrans-admin-settings.php | 2 +- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/class/class.midtrans-gateway-notif-handler.php b/class/class.midtrans-gateway-notif-handler.php index df1d5cc..2ba394e 100644 --- a/class/class.midtrans-gateway-notif-handler.php +++ b/class/class.midtrans-gateway-notif-handler.php @@ -49,6 +49,22 @@ public function doEarlyAckResponse() { return $raw_notification; } + /** + * getPluginOptions + * @param string $plugin_id plugin id of the paid order + * @return array plugin options + */ + public function getPluginOptions($plugin_id = 'midtrans'){ + // Get current plugin options + $plugin_options = array(); + try { + $plugin_options = get_option( 'woocommerce_' . $plugin_id . '_settings' ); + } catch (Exception $e) { + WC_Midtrans_Logger::log( 'Fail to getPluginOptions', 'midtrans-error' ); + }; + return $plugin_options; + } + /** * Called by hook function when HTTP notification / API call received * Handle Midtrans payment notification @@ -81,14 +97,14 @@ public function handleMidtransNotificationRequest() { WC_Midtrans_Logger::log( 'Can\'t find order id' . $raw_notification['order_id'] . ' on WooCommerce dashboard', 'midtrans-error' ); exit; } - // Get plugin id + // Get current plugin id else $plugin_id = $wcorder->get_payment_method(); // Verify Midtrans notification $midtrans_notification = WC_Midtrans_API::getMidtransNotif( $plugin_id ); // If notification verified, handle it if (in_array($midtrans_notification->status_code, array(200, 201, 202, 407))) { if (wc_get_order($midtrans_notification->order_id) != false) { - do_action( "midtrans-handle-valid-notification", $midtrans_notification ); + do_action( "midtrans-handle-valid-notification", $midtrans_notification, $plugin_id ); } } exit; @@ -111,13 +127,17 @@ public function handleMidtransNotificationRequest() { } // if or pending/challenge else if( !empty($sanitized['order_id']) && !empty($sanitized['transaction_status']) && $sanitized['status_code'] == 201) { - // @FIXME: $this->ignore_pending_status is broken, it doesn't refer to plugin class, but refer to this own class - if(property_exists($this,'ignore_pending_status') && $this->ignore_pending_status == 'yes'){ + $order_id = $sanitized['order_id']; + $order = new WC_Order( $order_id ); + $plugin_id = $order->get_payment_method(); + + $plugin_options = $this->getPluginOptions($plugin_id); + if( array_key_exists('ignore_pending_status',$plugin_options) + && $plugin_options['ignore_pending_status'] == 'yes' + ){ wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); exit; } - $order_id = $sanitized['order_id']; - $order = new WC_Order( $order_id ); wp_redirect($order->get_checkout_order_received_url()); } //if deny, redirect to order checkout page again @@ -223,7 +243,7 @@ public function handlePendingPaymentPdfUrlUpdate(){ * notification * @return void */ - public function handleMidtransValidNotificationRequest( $midtrans_notification ) { + public function handleMidtransValidNotificationRequest( $midtrans_notification, $plugin_id = 'midtrans' ) { global $woocommerce; $order = new WC_Order( $midtrans_notification->order_id ); @@ -265,11 +285,14 @@ public function handleMidtransValidNotificationRequest( $midtrans_notification ) $order->update_meta_data('_mt_payment_transaction_id',$midtrans_notification->transaction_id); $order->save(); - // @FIXME: $this->ignore_pending_status is broken, it doesn't refer to plugin class, but refer to this own class - if(property_exists($this,'ignore_pending_status') && $this->ignore_pending_status == 'yes'){ + $plugin_options = $this->getPluginOptions($plugin_id); + if( array_key_exists('ignore_pending_status',$plugin_options) + && $plugin_options['ignore_pending_status'] == 'yes' + ){ exit; } $order->update_status('on-hold',__('Awaiting payment: Midtrans-'.$midtrans_notification->payment_type,'midtrans-woocommerce')); + error_log($plugin_options['ignore_pending_status']); } else if ($midtrans_notification->transaction_status == 'refund' || $midtrans_notification->transaction_status == 'partial_refund') { $refund_request = $this->validateRefundNotif( $midtrans_notification ); diff --git a/class/midtrans-admin-settings.php b/class/midtrans-admin-settings.php index 65c83bb..a52f539 100644 --- a/class/midtrans-admin-settings.php +++ b/class/midtrans-admin-settings.php @@ -135,7 +135,7 @@ 'description' => __( 'By default, item stock only reduced if payment status on Midtrans reach pending/success (customer choose payment channel and click pay on payment pop-up). Enable this if you want to immediately reduce item stock when payment pop-up generated/displayed.', 'midtrans-woocommerce' ), 'default' => 'no' ), - // @FIXME: likely buggy, config will not be applied, check gateway-notif-handler.php class to fix the bug + // @Note: only main plugin class config will be applied on notif handler, sub plugin class config will not affect it, check gateway-notif-handler.php class to fix 'ignore_pending_status' => array( 'title' => __( 'Ignore Midtrans Transaction Pending Status', 'midtrans-woocommerce' ), 'type' => 'checkbox', From ffcada58a7ac9347bd827db87acd327779b49ca4 Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Tue, 27 Apr 2021 16:15:02 +0700 Subject: [PATCH 6/8] func name refactor --- class/class.midtrans-gateway-api.php | 2 +- class/class.midtrans-gateway-notif-handler.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/class/class.midtrans-gateway-api.php b/class/class.midtrans-gateway-api.php index a82a12f..7289254 100644 --- a/class/class.midtrans-gateway-api.php +++ b/class/class.midtrans-gateway-api.php @@ -134,7 +134,7 @@ public static function createRefund( $order_id, $params, $plugin_id="midtrans" ) * Get Midtrans Notification. * @return object Midtrans Notification response. */ - public static function getMidtransNotif( $plugin_id="midtrans") { + public static function getStatusFromMidtransNotif( $plugin_id="midtrans") { self::fetchAndSetMidtransApiConfig( $plugin_id ); return new Midtrans\Notification(); } diff --git a/class/class.midtrans-gateway-notif-handler.php b/class/class.midtrans-gateway-notif-handler.php index 2ba394e..c3902c2 100644 --- a/class/class.midtrans-gateway-notif-handler.php +++ b/class/class.midtrans-gateway-notif-handler.php @@ -12,9 +12,7 @@ class WC_Gateway_Midtrans_Notif_Handler { /** * Constructor. - * - * @param bool $is_production Use production or not. - * @param string $server_key ServerKey to receive HTTP notification from Midtrans. + * */ public function __construct() { // Register hook for handling HTTP notification (HTTP call to `http://[your web]/?wc-api=WC_Gateway_Midtrans`) @@ -100,7 +98,7 @@ public function handleMidtransNotificationRequest() { // Get current plugin id else $plugin_id = $wcorder->get_payment_method(); // Verify Midtrans notification - $midtrans_notification = WC_Midtrans_API::getMidtransNotif( $plugin_id ); + $midtrans_notification = WC_Midtrans_API::getStatusFromMidtransNotif( $plugin_id ); // If notification verified, handle it if (in_array($midtrans_notification->status_code, array(200, 201, 202, 407))) { if (wc_get_order($midtrans_notification->order_id) != false) { From 4803a0d55df222e495ee898644e223de8b1dae5b Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Tue, 27 Apr 2021 16:31:25 +0700 Subject: [PATCH 7/8] annotate code --- class/class.midtrans-gateway-notif-handler.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/class/class.midtrans-gateway-notif-handler.php b/class/class.midtrans-gateway-notif-handler.php index c3902c2..de13e25 100644 --- a/class/class.midtrans-gateway-notif-handler.php +++ b/class/class.midtrans-gateway-notif-handler.php @@ -6,6 +6,9 @@ /** * WC_Gateway_Midtrans_Notif_Handler class. * Handles responses from Midtrans Notification. + * @todo : refactor, this shouldn't be a class + * maybe just a bunch of function to include in main class + * to avoid complex param & config value passing */ class WC_Gateway_Midtrans_Notif_Handler // extends WC_Gateway_ @@ -83,8 +86,9 @@ public function handleMidtransNotificationRequest() { isset($_POST['response'])? sanitize_text_field($_POST['response']): null; // check whether the request is POST or GET, - // if request == POST, request is for payment notification, then update the payment status - if(empty($sanitized['order_id']) && empty($sanitizedPost['id']) && empty($sanitized['id']) && empty($sanitizedPost['response'])) { // Check if POST, then create new notification + // @TODO: refactor this conditions, this doesn't quite represent conditions for a POST request + if(empty($sanitized['order_id']) && empty($sanitizedPost['id']) && empty($sanitized['id']) && empty($sanitizedPost['response'])) { + // Request is POST, proceed to create new notification, then update the payment status $raw_notification = $this->doEarlyAckResponse(); // Handle pdf url update $this->handlePendingPaymentPdfUrlUpdate(); @@ -107,8 +111,8 @@ public function handleMidtransNotificationRequest() { } exit; } - // if request == GET, request is for finish OR failed URL, then redirect to WooCommerce's order complete/failed else { + // The request == GET, this will handle redirect url from Snap finish OR failed, proceed to redirect to WooCommerce's order complete/failed page $sanitized['transaction_status'] = isset($_GET['transaction_status'])? sanitize_text_field($_GET['transaction_status']): null; $sanitized['status_code'] = From 5f00d3d0814e5b86d8066772d2f343e1a906fc26 Mon Sep 17 00:00:00 2001 From: rizdaprasetya Date: Tue, 27 Apr 2021 16:32:07 +0700 Subject: [PATCH 8/8] bump version --- midtrans-gateway.php | 2 +- readme.txt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/midtrans-gateway.php b/midtrans-gateway.php index f43ef63..1f79183 100644 --- a/midtrans-gateway.php +++ b/midtrans-gateway.php @@ -3,7 +3,7 @@ Plugin Name: Midtrans - WooCommerce Payment Gateway Plugin URI: https://github.com/veritrans/SNAP-Woocommerce Description: Accept all payment directly on your WooCommerce site in a seamless and secure checkout environment with Midtrans -Version: 2.21.0 +Version: 2.22.0 Author: Midtrans Author URI: http://midtrans.co.id License: GPLv2 or later diff --git a/readme.txt b/readme.txt index 385b697..263f7f8 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: yocki, rizdaprasetya Tags: midtrans, snap, payment, payment-gateway, credit-card, commerce, e-commerce, woocommerce, veritrans Requires at least: 3.9.1 Tested up to: 5.7 -Stable tag: 2.21.0 +Stable tag: 2.22.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -70,6 +70,11 @@ The best way please email to support@midtrans.com, but bugs can be reported in o == Changelog == += 2.22.0 - 2021-04-27 = +* prevent issue of 3rd party Cloudflare plugin breaking payment page (reload repetitively) +* improve configuration page structure and description +* enhance "ignore pending status" config + = 2.21.0 - 2021-03-08 = * improve compatibility: prepare future WP >5.7 CSP on js script tag * minor payment page js enhancement @@ -232,6 +237,11 @@ The best way please email to support@midtrans.com, but bugs can be reported in o == Upgrade Notice == += 2.22.0 - 2021-04-27 = +* prevent issue of 3rd party Cloudflare plugin breaking payment page (reload repetitively) +* improve configuration page structure and description +* enhance "ignore pending status" config + = 2.21.0 - 2021-03-08 = * improve compatibility: prepare future WP >5.7 CSP on js script tag * minor payment page js enhancement