Skip to content

Commit

Permalink
Remove zero_interest_installments option from installment banks other…
Browse files Browse the repository at this point in the history
… than Maybank (#458)

* WIP

* Removed zero_interest_installment for installments except Maybank.

* Fix syntax error

* Fixed test issue

---------

Co-authored-by: Aashish <[email protected]>
  • Loading branch information
aashishgurung and Aashish authored Nov 24, 2023
1 parent 0a29929 commit e5f255e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 18 additions & 6 deletions Gateway/Request/PaymentDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
}
}
9 changes: 8 additions & 1 deletion Test/Unit/PaymentDataBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,6 +31,7 @@ class PaymentDataBuilderTest extends TestCase
private $configMock;
private $storeManagerMock;
private $storeMock;
private $capabilities;

protected function setUp(): void
{
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit e5f255e

Please sign in to comment.