From 54bdc1edb3d0af2b90dfebe295d0cd1dd06de14d Mon Sep 17 00:00:00 2001 From: Zin Kyaw Kyaw <108650842+ajzkk@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:38:17 +0630 Subject: [PATCH 1/6] add count down for promptpay QR expires --- .../PromptpayAdditionalInformation.php | 14 +-- Controller/Callback/Threedsecure.php | 2 +- .../PromptpayAdditionalInformationTest.php | 4 +- .../success/promptpay_additional_info.phtml | 99 ++++++++++++++----- 4 files changed, 79 insertions(+), 40 deletions(-) diff --git a/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php b/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php index 125b96d8..d78d910b 100644 --- a/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php +++ b/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php @@ -14,20 +14,8 @@ protected function _toHtml() } $data['order_amount'] = $this->getOrderAmount(); $data['image_code'] = $this->getPaymentAdditionalInformation('image_code'); - $data['charge_expires_at'] = $this->getChargeExpiryDate(); + $data['charge_expires_at'] = $this->getPaymentAdditionalInformation('charge_expires_at'); $this->addData($data); return parent::_toHtml(); } - - /** - * get expiry date - * @return string - */ - public function getChargeExpiryDate() - { - // Making sure that timezone is Thailand - date_default_timezone_set("Asia/Bangkok"); - $timestamp = strtotime($this->getPaymentAdditionalInformation('charge_expires_at')); - return date("M d, Y h:i A", $timestamp); - } } diff --git a/Controller/Callback/Threedsecure.php b/Controller/Callback/Threedsecure.php index e334fdbd..2f98fe3e 100644 --- a/Controller/Callback/Threedsecure.php +++ b/Controller/Callback/Threedsecure.php @@ -146,7 +146,7 @@ public function execute() if ($result instanceof Invalid) { // restoring the cart $this->checkoutSession->restoreQuote(); - return $this->processFailedCharge($result->getMessage()); + return $this->processFailedCharge($result->getMessage(), false); } // Do not proceed if webhook is enabled diff --git a/Test/Unit/PromptpayAdditionalInformationTest.php b/Test/Unit/PromptpayAdditionalInformationTest.php index 6c4c1e79..9715d67b 100644 --- a/Test/Unit/PromptpayAdditionalInformationTest.php +++ b/Test/Unit/PromptpayAdditionalInformationTest.php @@ -57,9 +57,9 @@ public function testPromptpayAdditionalInformation() $this->checkoutSessionMock->shouldReceive('getLastRealOrder')->andReturn($this->orderMock); $model = new PromptpayAdditionalInformation($this->contextMock, $this->checkoutSessionMock, []); - $this->assertEquals("Sep 29, 2023 01:49 PM", $model->getChargeExpiryDate()); - $html = $model->toHtml(); $this->assertNotNull($html); + + $this->assertEquals("2023-09-29T06:49:35Z", $model->getChargeExpiresAt()); } } diff --git a/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml b/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml index 8c4571ab..828d040c 100644 --- a/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml +++ b/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml @@ -1,25 +1,76 @@ -
- = $block->escapeHtml(__('Amount to pay')) ?>: - - = $block->escapeHtml($block->getOrderAmount()) ?> - - -
= $block->escapeHtml(__('PromptPay QR Code.')); ?>
- -- Payment expires at: = $block->escapeHtml($block->getChargeExpiresAt()); ?> -
-- -
- -To make payment:
-+ = $block->escapeHtml(__('Amount to pay')) ?>: + + = $block->escapeHtml($block->getOrderAmount()) ?> + + +
= $block->escapeHtml(__('PromptPay QR Code.')); ?>
+ ++ Payment expires in: +
++ +
+ +To make payment:
+To make payment:
-= $block->escapeHtml(__('Amount to pay')) ?>: @@ -44,9 +44,9 @@ return num.toString().padStart(2, '0'); } - function hideQrInfo() { + function hideQrInfoAndShowPaymentExpired() { const element = document.getElementById('qr-info') - element.style.display = 'none' + element.innerHTML = 'Payment Expired.' } function updateCountdown() { @@ -61,7 +61,7 @@ if(countDownInterval) { clearInterval(countDownInterval) } - hideQrInfo() + hideQrInfoAndShowPaymentExpired() return; } From caad3c371554bea876f9e0647085135d5c358681 Mon Sep 17 00:00:00 2001 From: Zin Kyaw Kyaw <108650842+ajzkk@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:16:28 +0630 Subject: [PATCH 6/6] show payment expired with default alert box --- .../onepage/success/promptpay_additional_info.phtml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml b/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml index b223f786..116c933f 100644 --- a/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml +++ b/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml @@ -46,7 +46,11 @@ function hideQrInfoAndShowPaymentExpired() { const element = document.getElementById('qr-info') - element.innerHTML = 'Payment Expired.' + element.innerHTML = `
` } function updateCountdown() {