-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added promptpay QR pyament instructions (#447)
* add promptpay qr process info * add test for charge expiry date * fix m2 coding standard * add test for toHtml * remove disableOriginalConstructor from interface mock * add test for payment dtetail hanldler * fix m2 coding standard * remove full stop * remove payment mock * EOF
- Loading branch information
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters