Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove zero_interest_installments option from installment banks other than Maybank #458

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading