diff --git a/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php b/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php index 46541db6..125b96d8 100644 --- a/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php +++ b/Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php @@ -14,7 +14,20 @@ protected function _toHtml() } $data['order_amount'] = $this->getOrderAmount(); $data['image_code'] = $this->getPaymentAdditionalInformation('image_code'); + $data['charge_expires_at'] = $this->getChargeExpiryDate(); $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/CHANGELOG.md b/CHANGELOG.md index dab77ab8..40697a35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## [v3.3.1 _(Oct, 03, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.3.1) +- Added Promptpay QR payment instructions. (PR: [#447](https://github.com/omise/omise-magento/pull/447)) +- Bug fixed on Alipay. (PR: [#446](https://github.com/omise/omise-magento/pull/446)) + ## [v3.3.0 _(Sep, 21, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.3.0) - Added OCBC Digital Payment. (PR: [#440](https://github.com/omise/omise-magento/pull/443)) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 82d106d2..1fd06974 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -159,7 +159,9 @@ public function build(array $buildSubject) switch ($method->getMethod()) { case Alipay::CODE: - $paymentInfo[self::SOURCE] = Alipay::getSourceData(); + $paymentInfo[self::SOURCE] = [ + self::SOURCE_TYPE => Alipay::ID + ]; break; case Tesco::CODE: $paymentInfo[self::SOURCE] = [ diff --git a/Gateway/Response/PaymentDetailsHandler.php b/Gateway/Response/PaymentDetailsHandler.php index 8c532bf7..ce66ffbd 100644 --- a/Gateway/Response/PaymentDetailsHandler.php +++ b/Gateway/Response/PaymentDetailsHandler.php @@ -63,6 +63,7 @@ public function handle(array $handlingSubject, array $response) $payment->setAdditionalInformation('charge_id', $response['charge']->id); $payment->setAdditionalInformation('charge_authorize_uri', $response['charge']->authorize_uri); $payment->setAdditionalInformation('payment_type', $paymentType); + $payment->setAdditionalInformation('charge_expires_at', $response['charge']->expires_at); $transaction = $this->transactionBuilder ->setPayment($payment) diff --git a/Test/Unit/AlipayAPMBuilderTest.php b/Test/Unit/AlipayAPMBuilderTest.php new file mode 100644 index 00000000..917d1002 --- /dev/null +++ b/Test/Unit/AlipayAPMBuilderTest.php @@ -0,0 +1,74 @@ +helper = $this->getMockBuilder(OmiseHelper::class)->disableOriginalConstructor()->getMock(); + $this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); + $this->capabilities = $this->getMockBuilder(Capabilities::class)->disableOriginalConstructor()->getMock(); + $this->orderMock = $this->getMockBuilder(OrderAdapterInterface::class)->getMock(); + $this->infoMock = $this->getMockBuilder(InfoMock::class)->getMock(); + } + + /** + * @covers Omise\Payment\Gateway\Request\APMBuilder + * @covers Omise\Payment\Model\Config\Alipay + */ + public function testApmBuilder() + { + $this->infoMock->method('getMethod')->willReturn(Alipay::CODE); + $this->returnUrlHelper->method('create')->willReturn([ + 'url' => 'https://omise.co/complete', + 'token' => '1234' + ]); + + $this->builder = new APMBuilder( + $this->helper, + $this->returnUrlHelper, + $this->config, + $this->capabilities, + new OmiseMoney(), + ); + + $result = $this->builder->build(['payment' => new PaymentDataObject( + $this->orderMock, + $this->infoMock + )]); + + $this->assertEquals('alipay', $result['source']['type']); + $this->assertEquals('https://omise.co/complete', $result['return_uri']); + } + + /** + * @covers Omise\Payment\Model\Config\Alipay + */ + public function testConstants() + { + $this->assertEquals('omise_offsite_alipay', Alipay::CODE); + $this->assertEquals('alipay', Alipay::ID); + } +} diff --git a/Test/Unit/PaymentDetailsHandlerTest.php b/Test/Unit/PaymentDetailsHandlerTest.php new file mode 100644 index 00000000..9f6aee62 --- /dev/null +++ b/Test/Unit/PaymentDetailsHandlerTest.php @@ -0,0 +1,75 @@ +omiseHelperMock = m::mock(OmiseHelper::class); + $this->curlMock = m::mock(Curl::class); + $this->builderMock = m::mock(BuilderInterface::class); + $this->paymentMock = m::mock(PaymentDataObjectInterface::class); + $this->infoMock = m::mock(OrderPaymentInterface::class); + $this->orderMock = m::mock(OrderInterface::class); + $this->currencyMock = m::mock(); + + $this->chargeMock = m::mock(); + $this->chargeMock->id = 'charge_xxx'; + $this->chargeMock->authorize_uri = 'https://omise.co/authorized'; + $this->chargeMock->expires_at = '2023-09-29T06:49:35Z'; + } + + /** + * @covers Omise\Payment\Gateway\Response\PaymentDetailsHandler + */ + public function testHandler() + { + $this->omiseHelperMock->shouldReceive('isPayableByImageCode')->once(); + $this->builderMock->shouldReceive('setOrder')->once()->andReturn($this->builderMock); + $this->builderMock->shouldReceive('setPayment')->once()->andReturn($this->builderMock); + $this->builderMock->shouldReceive('setTransactionId')->once()->andReturn($this->builderMock); + $this->builderMock->shouldReceive('setAdditionalInformation')->once()->andReturn($this->builderMock); + $this->builderMock->shouldReceive('setFailSafe')->once()->andReturn($this->builderMock); + $this->builderMock->shouldReceive('build')->once()->andReturn($this->builderMock); + + $this->currencyMock->shouldReceive('formatTxt')->once(); + + $this->orderMock->shouldReceive('getBaseCurrency')->once()->andReturn($this->currencyMock); + $this->orderMock->shouldReceive('getTotalDue')->once()->andReturn(1000); + + $this->infoMock->shouldReceive('getMethod')->once()->andReturn('promptpay'); + $this->infoMock->shouldReceive('getOrder')->once()->andReturn($this->orderMock); + $this->infoMock->shouldReceive('setAdditionalInformation')->times(4); + $this->infoMock->shouldReceive('prependMessage')->once(); + $this->infoMock->shouldReceive('addTransactionCommentsToOrder')->once(); + + $this->paymentMock->shouldReceive('getPayment')->andReturn($this->infoMock); + + $model = new PaymentDetailsHandler($this->omiseHelperMock, $this->curlMock, $this->builderMock); + $model->handle(['payment' => $this->paymentMock], [ + 'charge' => $this->chargeMock + ]); + $this->expectNotToPerformAssertions(); + } +} diff --git a/Test/Unit/PromptpayAdditionalInformationTest.php b/Test/Unit/PromptpayAdditionalInformationTest.php new file mode 100644 index 00000000..6c4c1e79 --- /dev/null +++ b/Test/Unit/PromptpayAdditionalInformationTest.php @@ -0,0 +1,65 @@ +contextMock = m::mock(Context::class)->makePartial(); + $this->checkoutSessionMock = m::mock(Session::class); + $this->orderMock = m::mock(Order::class); + $this->eventManagerMock = m::mock(ManagerInterface::class); + $this->scopeConfigMock = m::mock(ScopeConfigInterface::class); + $this->currencyMock = m::mock(Currency::class)->makePartial(); + $this->paymentMock = m::mock(); + } + + /** + * @covers Omise\Payment\Block\Checkout\Onepage\Success\PromptpayAdditionalInformation + * @covers Omise\Payment\Block\Checkout\Onepage\Success\AdditionalInformation + */ + public function testPromptpayAdditionalInformation() + { + $this->paymentMock->shouldReceive('getData')->andReturn([ + "amount_ordered" => 1000, + "additional_information" => [ + "charge_expires_at" => "2023-09-29T06:49:35Z", + "payment_type" => "promptpay" + ] + ]); + $this->eventManagerMock->shouldReceive('dispatch')->times(2); + $this->scopeConfigMock->shouldReceive('getValue')->once(); + + $this->contextMock->shouldReceive('getEventManager')->andReturn($this->eventManagerMock); + $this->contextMock->shouldReceive('getScopeConfig')->andReturn($this->scopeConfigMock); + + $this->orderMock->shouldReceive('getPayment')->andReturn($this->paymentMock); + $this->orderMock->shouldReceive('getOrderCurrency')->andReturn($this->currencyMock); + $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); + } +} diff --git a/composer.json b/composer.json index 7cf6cbc4..a8a9626b 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "email": "support@omise.co" } ], - "version": "3.3.0", + "version": "3.3.1", "minimum-stability": "stable", "type": "magento2-module", "license": "MIT", diff --git a/etc/module.xml b/etc/module.xml index 4f384900..8864faf9 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + 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 9c5e2eb9..8c4571ab 100644 --- a/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml +++ b/view/frontend/templates/checkout/onepage/success/promptpay_additional_info.phtml @@ -6,7 +6,20 @@

escapeHtml(__('PromptPay QR Code.')); ?>

+

+ Payment expires at: escapeHtml($block->getChargeExpiresAt()); ?> +

+ +
+

To make payment:

+
    +
  • Download the QR code or open your preferred bank app to scan it
  • +
  • Check that the payment details are correct
  • +
  • Import the QR code image into your bank app or scan the QR code with your bank app to pay
  • +
  • Share the payment slip from your bank app to the seller
  • +
+