Skip to content

Commit

Permalink
Review and add White Label Installments (#492)
Browse files Browse the repository at this point in the history
* Add WLB installment banks in providers in omise-offsite-installment-method.js. Removed unnecesssary files from offsite-installment-form.html. Updated Model/Config/Installment.php. Few other minor improvements.

* Refactored /omise-offsite-installment-method.js

* Move installment_wlb_ktc to a new line.

* Add test for Model/Api/Capabilities
  • Loading branch information
aashishgurung authored Sep 18, 2024
1 parent 128bfab commit b66bcd6
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 342 deletions.
13 changes: 12 additions & 1 deletion Helper/OmiseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,18 @@ class OmiseHelper extends AbstractHelper
Installment::UOB_ID => Installment::CODE,
Installment::MBB_ID => Installment::CODE,

// offsite installment banking payment
// offsite wlb installment banking payment
Installment::WLB_BAY_ID => Installment::CODE,
Installment::WLB_BBL_ID => Installment::CODE,
Installment::WLB_UOB_ID => Installment::CODE,
Installment::WLB_FIRST_CHOICE_ID => Installment::CODE,
Installment::WLB_KBANK_ID => Installment::CODE,
Installment::WLB_KTC_ID => Installment::CODE,
Installment::WLB_SCB_ID => Installment::CODE,
Installment::WLB_TTB_ID => Installment::CODE,
Installment::WLB_UOB_ID => Installment::CODE,

// offsite mobile banking payment
Mobilebanking::BAY_ID => Mobilebanking::CODE,
Mobilebanking::BBL_ID => Mobilebanking::CODE,
Mobilebanking::KBANK_ID => Mobilebanking::CODE,
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public function getTokenizationMethods()
*/
public function getInstallmentMinLimit()
{
return $this->capabilities['limits']['installment_amount']['min'];
return $this->capabilities ? $this->capabilities['limits']['installment_amount']['min'] : 0;
}
}
19 changes: 19 additions & 0 deletions Model/Config/Installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ class Installment extends Config
const UOB_ID = "installment_uob";

const MBB_ID = "installment_mbb";

/**
* WLB Installments
*/
const WLB_BAY_ID = "installment_wlb_bay";

const WLB_BBL_ID = "installment_wlb_bbl";

const WLB_FIRST_CHOICE_ID = "installment_wlb_first_choice";

const WLB_KBANK_ID = "installment_wlb_kbank";

const WLB_KTC_ID = "installment_wlb_ktc";

const WLB_SCB_ID = "installment_wlb_scb";

const WLB_TTB_ID = "installment_wlb_ttb";

const WLB_UOB_ID = "installment_wlb_uob";
}
4 changes: 0 additions & 4 deletions Observer/InstallmentDataAssignObserver.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?php
namespace Omise\Payment\Observer;

use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;

class InstallmentDataAssignObserver extends OffsiteDataAssignObserver
{
/**
Expand Down
57 changes: 57 additions & 0 deletions Test/Unit/Model/Api/CapabilitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Omise\Payment\Test\Unit\Model\Api;

use PHPUnit\Framework\TestCase;
use Omise\Payment\Model\Api\Capabilities;
use Omise\Payment\Model\Config\Config;
use Mockery as m;

class CapabilitiesTest extends TestCase
{
private $configMock;
private $omiseCapabilitiesMock;

protected function setUp(): void
{
$this->configMock = m::mock(Config::class);
$this->configMock->shouldReceive('canInitialize')->andReturn(true);
$this->omiseCapabilitiesMock = m::mock('alias:OmiseCapabilities');
}

protected function tearDown(): void
{
m::close();
}

/**
* @covers Omise\Payment\Model\Api\Capabilities
*/
public function testGetInstallmentMinLimit()
{
$data = [
'limits' => [
'installment_amount' => [
'min' => 3000
]
]
];
$this->omiseCapabilitiesMock->shouldReceive('retrieve')->andReturn($data);
$capabilities = new Capabilities($this->configMock);
$result = $capabilities->getInstallmentMinLimit();

$this->assertEquals($data['limits']['installment_amount']['min'], $result);
}

/**
* @covers Omise\Payment\Model\Api\Capabilities
*/
public function testGetInstallmentMinLimitReturnsZeroIfCapabilitiesIsNotSet()
{
$this->omiseCapabilitiesMock->shouldReceive('retrieve')->andReturn(null);
$capabilities = new Capabilities($this->configMock);
$result = $capabilities->getInstallmentMinLimit();

$this->assertEquals(0, $result);
}
}
Loading

0 comments on commit b66bcd6

Please sign in to comment.