Skip to content

Commit

Permalink
Merge pull request #448 from omise/release-v3.3.1
Browse files Browse the repository at this point in the history
Bump v3.3.1
  • Loading branch information
ajzkk authored Oct 3, 2023
2 parents 6beafdd + 86f6e33 commit 3324493
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Block/Checkout/Onepage/Success/PromptpayAdditionalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
4 changes: 3 additions & 1 deletion Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
1 change: 1 addition & 0 deletions Gateway/Response/PaymentDetailsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 74 additions & 0 deletions Test/Unit/AlipayAPMBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Omise\Payment\Test\Unit;

use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Omise\Payment\Gateway\Request\APMBuilder;
use Omise\Payment\Helper\OmiseHelper;
use Omise\Payment\Helper\OmiseMoney;
use Omise\Payment\Helper\ReturnUrlHelper;
use Omise\Payment\Model\Capabilities;
use Omise\Payment\Model\Config\Alipay;
use Omise\Payment\Model\Config\Config;
use PHPUnit\Framework\TestCase;
use Omise\Payment\Test\Mock\InfoMock;

class AlipayAPMBuilderTest extends TestCase
{
private $builder;
private $helper;
private $returnUrlHelper;
private $config;
private $capabilities;
private $orderMock;
private $infoMock;

protected function setUp(): void
{
$this->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);
}
}
75 changes: 75 additions & 0 deletions Test/Unit/PaymentDetailsHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Omise\Payment\Test\Unit;

use Omise\Payment\Gateway\Response\PaymentDetailsHandler;
use Omise\Payment\Helper\OmiseHelper;
use PHPUnit\Framework\TestCase;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface;
use Mockery as m;

class PaymentDetailsHandlerTest extends TestCase
{

private $omiseHelperMock;
private $curlMock;
private $builderMock;
private $paymentMock;
private $infoMock;
private $chargeMock;
private $orderMock;
private $currencyMock;

protected function setUp(): void
{
$this->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();
}
}
65 changes: 65 additions & 0 deletions Test/Unit/PromptpayAdditionalInformationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Omise\Payment\Test\Unit;

use Magento\Sales\Model\Order;
use PHPUnit\Framework\TestCase;
use Magento\Checkout\Model\Session;
use Magento\Framework\View\Element\Template\Context;
use Omise\Payment\Block\Checkout\Onepage\Success\PromptpayAdditionalInformation;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\Currency;
use Mockery as m;

class PromptpayAdditionalInformationTest extends TestCase
{
private $contextMock;
private $checkoutSessionMock;
private $orderMock;
private $paymentMock;
private $eventManagerMock;
private $scopeConfigMock;
private $currencyMock;

protected function setUp(): void
{
$this->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);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
}
],
"version": "3.3.0",
"version": "3.3.1",
"minimum-stability": "stable",
"type": "magento2-module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Omise_Payment" setup_version="3.3.0">
<module name="Omise_Payment" setup_version="3.3.1">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@
</strong>
<p style="margin:.5rem 0"><?= $block->escapeHtml(__('PromptPay QR Code.')); ?></p>
<div><img id="img_payment_code" src="<?= $block->escapeHtml($block->getImageCode()) ?>" /></div>
<p>
Payment expires at: <?= $block->escapeHtml($block->getChargeExpiresAt()); ?>
</p>
<p>
<button class="action secondary" onclick="window.print ? window.print() : alert('Print not available')">
<?= $block->escapeHtml(__('Print'))?></button>
</p>

<div style="padding: 15px; margin: 20px 0; border: 1px solid black">
<p><strong>To make payment:</strong></p>
<ul style="list-style: auto; margin-bottom: 0px; padding: 0px 15px;">
<li>Download the QR code or open your preferred bank app to scan it</li>
<li>Check that the payment details are correct</li>
<li>Import the QR code image into your bank app or scan the QR code with your bank app to pay</li>
<li>Share the payment slip from your bank app to the seller</li>
</ul>
</div>

0 comments on commit 3324493

Please sign in to comment.