From e5f255e82f98c9b74152725406c7614f2c51fbe2 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:40:36 +0700 Subject: [PATCH] Remove zero_interest_installments option from installment banks other than Maybank (#458) * WIP * Removed zero_interest_installment for installments except Maybank. * Fix syntax error * Fixed test issue --------- Co-authored-by: Aashish --- Gateway/Request/APMBuilder.php | 3 +-- Gateway/Request/PaymentDataBuilder.php | 24 ++++++++++++++++++------ Test/Unit/PaymentDataBuilderTest.php | 9 ++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Gateway/Request/APMBuilder.php b/Gateway/Request/APMBuilder.php index 1fd06974..d8dee431 100644 --- a/Gateway/Request/APMBuilder.php +++ b/Gateway/Request/APMBuilder.php @@ -179,8 +179,7 @@ public function build(array $buildSubject) self::SOURCE_TYPE => $installmentId, self::SOURCE_INSTALLMENT_TERMS => $method->getAdditionalInformation( InstallmentDataAssignObserver::TERMS - ), - self::ZERO_INTEREST_INSTALLMENTS => ('installment_mbb' === $installmentId) + ) ]; break; case Truemoney::CODE: diff --git a/Gateway/Request/PaymentDataBuilder.php b/Gateway/Request/PaymentDataBuilder.php index 9def1703..94496e25 100644 --- a/Gateway/Request/PaymentDataBuilder.php +++ b/Gateway/Request/PaymentDataBuilder.php @@ -10,6 +10,7 @@ use Omise\Payment\Model\Config\Cc; use Omise\Payment\Model\Config\Config; use Omise\Payment\Block\Adminhtml\System\Config\Form\Field\Webhook; +use Omise\Payment\Model\Capabilities; class PaymentDataBuilder implements BuilderInterface { @@ -53,14 +54,20 @@ class PaymentDataBuilder implements BuilderInterface */ private $money; + private $capabilities; + /** * @param \Omise\Payment\Helper\OmiseHelper $omiseHelper * @param Omise\Payment\Model\Config\Cc $ccConfig */ - public function __construct(Cc $ccConfig, OmiseMoney $money) - { + public function __construct( + Cc $ccConfig, + OmiseMoney $money, + Capabilities $capabilities + ) { $this->money = $money; $this->ccConfig = $ccConfig; + $this->capabilities = $capabilities; } /** @@ -99,8 +106,9 @@ public function build(array $buildSubject) $requestBody[self::WEBHOOKS_ENDPOINT] = [$webhookUrl]; } - if (Installment::CODE === $method->getMethod()) { - $requestBody[self::ZERO_INTEREST_INSTALLMENTS] = $this->isZeroInterestInstallment($method); + // Set zero_interest_installment to true for installment Maybank only + if ($this->enableZeroInterestInstallments($method)) { + $requestBody[self::ZERO_INTEREST_INSTALLMENTS] = true; } if (Cc::CODE === $method->getMethod()) { @@ -110,9 +118,13 @@ public function build(array $buildSubject) return $requestBody; } - public function isZeroInterestInstallment($method) + /** + * Set zero_interest_installment to true for installment Maybank + */ + public function enableZeroInterestInstallments($method) { + $isInstallment = Installment::CODE === $method->getMethod(); $installmentId = $method->getAdditionalInformation(InstallmentDataAssignObserver::OFFSITE); - return ('installment_mbb' === $installmentId); + return $isInstallment && (Installment::MBB_ID === $installmentId); } } diff --git a/Test/Unit/PaymentDataBuilderTest.php b/Test/Unit/PaymentDataBuilderTest.php index 6ad111ee..383bc7b5 100644 --- a/Test/Unit/PaymentDataBuilderTest.php +++ b/Test/Unit/PaymentDataBuilderTest.php @@ -18,6 +18,7 @@ use Magento\Store\Api\Data\StoreInterface; use Omise\Payment\Model\Config\Installment; use Omise\Payment\Model\Config\Promptpay; +use Omise\Payment\Model\Capabilities; class PaymentDataBuilderTest extends TestCase { @@ -30,6 +31,7 @@ class PaymentDataBuilderTest extends TestCase private $configMock; private $storeManagerMock; private $storeMock; + private $capabilities; protected function setUp(): void { @@ -42,6 +44,7 @@ protected function setUp(): void $this->orderMock = m::mock(OrderInterface::class); $this->storeManagerMock = m::mock(StoreManagerInterface::class); $this->storeMock = m::mock(StoreInterface::class); + $this->capabilities = m::mock(Capabilities::class); } /** @@ -97,7 +100,11 @@ public function testBuild($paymentMethod, $expectedMetadata) $this->paymentDataMock->shouldReceive('getOrder')->andReturn($this->orderMock); $this->paymentDataMock->shouldReceive('getPayment')->andReturn($this->paymentMock); - $model = new PaymentDataBuilder($this->ccConfigMock, $this->omiseMoneyMock); + $model = new PaymentDataBuilder( + $this->ccConfigMock, + $this->omiseMoneyMock, + $this->capabilities + ); $result = $model->build(['payment' => $this->paymentDataMock]); $this->assertEquals(100000, $result['amount']);