Skip to content

Commit 8880acf

Browse files
Merge pull request #468 from omise/release-v3.6.0
Release v3.6.0
2 parents d32a380 + dbceab2 commit 8880acf

File tree

22 files changed

+406
-200
lines changed

22 files changed

+406
-200
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## [v3.6.0 _(Jan, 23, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.6.0)
4+
- Add truemoney jumpapp. (PR: [#466](https://github.com/omise/omise-magento/pull/466))
5+
- Updated README.md. (PR: [#464](https://github.com/omise/omise-magento/pull/464))
6+
37
## [v3.5.2 _(Dec, 7, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.5.2)
48
- Updated installment interest rates. (PR: [#460](https://github.com/omise/omise-magento/pull/460))
59

Gateway/Request/APMBuilder.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
class APMBuilder implements BuilderInterface
4848
{
49-
5049
/**
5150
* @var string
5251
*/
@@ -122,6 +121,16 @@ class APMBuilder implements BuilderInterface
122121
*/
123122
protected $money;
124123

124+
/**
125+
* @var Capabilities
126+
*/
127+
protected $capabilities;
128+
129+
/**
130+
* @var Config
131+
*/
132+
protected $config;
133+
125134
/**
126135
* @param $helper \Omise\Payment\Helper\OmiseHelper
127136
* @param $returnUrl \Omise\Payment\Helper\ReturnUrl
@@ -183,12 +192,7 @@ public function build(array $buildSubject)
183192
];
184193
break;
185194
case Truemoney::CODE:
186-
$paymentInfo[self::SOURCE] = [
187-
self::SOURCE_TYPE => 'truemoney',
188-
self::SOURCE_PHONE_NUMBER => $method->getAdditionalInformation(
189-
TruemoneyDataAssignObserver::PHONE_NUMBER
190-
),
191-
];
195+
$paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method);
192196
break;
193197
case Conveniencestore::CODE:
194198
$paymentInfo[self::SOURCE] = [
@@ -404,4 +408,25 @@ private function getOrderItems($order)
404408
}
405409
return $itemArray;
406410
}
411+
412+
public function getTruemoneySourceData($method)
413+
{
414+
$isJumpAppEnabled = $this->capabilities->isBackendEnabled(Truemoney::JUMPAPP_ID);
415+
$isWalletEnabled = $this->capabilities->isBackendEnabled(Truemoney::ID);
416+
417+
if (!$isJumpAppEnabled && $isWalletEnabled) {
418+
return [
419+
self::SOURCE_TYPE => Truemoney::ID,
420+
self::SOURCE_PHONE_NUMBER => $method->getAdditionalInformation(
421+
TruemoneyDataAssignObserver::PHONE_NUMBER
422+
)
423+
];
424+
}
425+
426+
// Returning JUMP APP for the following cases:
427+
// Case 1: Both jumpapp and wallet are enabled
428+
// Case 2: jumpapp is enabled and wallet is disabled
429+
// Case 3: Both are disabled.
430+
return [ self::SOURCE_TYPE => Truemoney::JUMPAPP_ID ];
431+
}
407432
}

Helper/OmiseHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class OmiseHelper extends AbstractHelper
122122
// offsite payment
123123
Alipay::ID => Alipay::CODE,
124124
Truemoney::ID => Truemoney::CODE,
125+
Truemoney::JUMPAPP_ID => Truemoney::CODE,
125126
Pointsciti::ID => Pointsciti::CODE,
126127
Fpx::ID => Fpx::CODE,
127128
Alipayplus::ALIPAY_ID => Alipayplus::ALIPAY_CODE,
@@ -187,7 +188,7 @@ class OmiseHelper extends AbstractHelper
187188
Alipay::CODE => "Alipay",
188189
Internetbanking::CODE => "Internet Banking Payment",
189190
Installment::CODE => "Installment Payment",
190-
Truemoney::CODE => "TrueMoney Wallet Payment",
191+
Truemoney::CODE => "TrueMoney Payment",
191192
Pointsciti::CODE => "Citi Pay with Points",
192193
Fpx::CODE => "FPX Payment",
193194
Alipayplus::ALIPAY_CODE => "Alipay (Alipay+ Partner) Payment",

Model/Config/Truemoney.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ class Truemoney extends Config
1515
* @var string
1616
*/
1717
const ID = 'truemoney';
18+
19+
const JUMPAPP_ID = 'truemoney_jumpapp';
1820
}

Model/Ui/CapabilitiesConfigProvider.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Omise\Payment\Helper\OmiseHelper;
66
use Omise\Payment\Model\Capabilities;
77
use Omise\Payment\Model\Config\Shopeepay;
8+
use Omise\Payment\Model\Config\Truemoney;
89
use Omise\Payment\Model\Config\CcGooglePay;
910
use Magento\Store\Model\StoreManagerInterface;
1011
use Magento\Checkout\Model\ConfigProviderInterface;
@@ -33,7 +34,7 @@ public function __construct(
3334
$this->capabilities = $capabilities;
3435
$this->_paymentLists = $paymentLists;
3536
$this->_storeManager = $storeManager;
36-
$this->helper = $helper;
37+
$this->helper = $helper;
3738
}
3839

3940
/**
@@ -46,12 +47,8 @@ public function getConfig()
4647
$listOfActivePaymentMethods = $this->_paymentLists->getActiveList($this->_storeManager->getStore()->getId());
4748
$currency = $this->_storeManager->getStore()->getCurrentCurrencyCode();
4849
$configs = [];
49-
50-
// Retrieve available backends & methods from capabilities api
51-
$backends = $this->capabilities->getBackendsWithOmiseCode();
52-
$tokenization_methods = $this->capabilities->getTokenizationMethodsWithOmiseCode();
53-
$backends = array_merge($backends, $tokenization_methods);
5450
$configs['omise_installment_min_limit'] = $this->capabilities->getInstallmentMinLimit($currency);
51+
$configs['omise_payment_list'] = [];
5552

5653
foreach ($listOfActivePaymentMethods as $method) {
5754
$code = $method->getCode();
@@ -62,19 +59,40 @@ public function getConfig()
6259
$configs['card_brands'] = $this->capabilities->getCardBrands();
6360
}
6461

65-
// filter only active backends
66-
if (array_key_exists($code, $backends)) {
67-
if ($code === 'omise_offsite_shopeepay') {
68-
$configs['omise_payment_list'][$code] = $this->getShopeeBackendByType($backends[$code]);
69-
} else {
70-
$configs['omise_payment_list'][$code] = $backends[$code];
71-
}
72-
}
62+
$this->filterActiveBackends($code, $configs['omise_payment_list']);
7363
}
7464

7565
return $configs;
7666
}
7767

68+
/**
69+
* filter only active backends
70+
* @param $code Payment method code
71+
* @param $paymentList Reference of the payment list
72+
*/
73+
private function filterActiveBackends($code, &$paymentList)
74+
{
75+
// Retrieve available backends & methods from capabilities api
76+
$paymentBackends = $this->capabilities->getBackendsWithOmiseCode();
77+
$tokenizationMethods = $this->capabilities->getTokenizationMethodsWithOmiseCode();
78+
$mergedBackends = array_merge($paymentBackends, $tokenizationMethods);
79+
80+
// filter only active backends
81+
if (!array_key_exists($code, $mergedBackends)) {
82+
return;
83+
}
84+
85+
if ($code === Shopeepay::CODE) {
86+
$backend = $this->getShopeeBackendByType($mergedBackends[$code]);
87+
} elseif ($code === Truemoney::CODE) {
88+
$backend = $this->getTruemoneyBackendByType($mergedBackends[$code]);
89+
} else {
90+
$backend = $configs['omise_payment_list'][$code] = $mergedBackends[$code];
91+
}
92+
93+
$paymentList[$code] = $backend;
94+
}
95+
7896
/**
7997
* Return the right ShopeePay backend depending on the platform and availability of
8098
* the backend in the capability
@@ -116,4 +134,29 @@ private function getShopeeBackendByType($shopeeBackends)
116134
// execute if none of the shopee backends were disabled.
117135
return $isShopeepayEnabled ? $mpmBackend : $jumpAppBackend;
118136
}
137+
138+
private function getTruemoneyBackendByType($truemoneyBackends)
139+
{
140+
$jumpAppBackend = [];
141+
$walletBackend = [];
142+
143+
// Since Truemoney will have two types i.e truemoney and truemoney_jumpapp,
144+
// we split and store the type in separate variables.
145+
foreach ($truemoneyBackends as $backend) {
146+
if ($backend->type === Truemoney::JUMPAPP_ID) {
147+
$jumpAppBackend[] = $backend;
148+
} else {
149+
$walletBackend[] = $backend;
150+
}
151+
}
152+
153+
$isJumpAppEnabled = $this->capabilities->isBackendEnabled(Truemoney::JUMPAPP_ID);
154+
$isWalletEnabled = $this->capabilities->isBackendEnabled(Truemoney::ID);
155+
156+
if (!$isJumpAppEnabled && $isWalletEnabled) {
157+
return $walletBackend;
158+
}
159+
160+
return $jumpAppBackend;
161+
}
119162
}

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<!--- KEEP START --->
2-
[![Omise](https://cdn.omise.co/assets/omise.png)](https://www.omise.co/developers)
2+
[![Opn Payments](https://www.opn.ooo/assets/svg/logo-opn-full.svg)](https://www.opn.ooo)
33

4-
![Code Coverage Badge](./badge.svg)
5-
6-
[Omise](https://www.omise.co/) is a payment service provider operating in Thailand, Japan, and Singapore.
7-
Omise provides a set of APIs that help merchants of any size accept payments online.
4+
[Opn Payments](https://www.opn.ooo) is a payment service provider operating in Thailand, Japan, and Singapore.
5+
Opn Payments provides a set of APIs that help merchants of any size accept payments online.
86
<!--- KEEP END --->
97

10-
**Omise Magento** is our official plugin providing support for processing payments on Magento through Omise.
8+
**Omise Magento** is our official plugin providing support for processing payments on Magento through Opn Payments.
119

1210
## Usage
1311

14-
See our [official docs](https://www.omise.co/magento-plugin) for details on installation and configuration.
12+
See our [official docs](https://docs.opn.ooo/magento-plugin) for details on installation and configuration.
1513

1614
## Contributing
1715

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders;
4+
5+
use Magento\Payment\Gateway\Data\OrderAdapterInterface;
6+
use Omise\Payment\Helper\OmiseHelper;
7+
use Omise\Payment\Helper\ReturnUrlHelper;
8+
use Omise\Payment\Model\Capabilities;
9+
use Omise\Payment\Model\Config\Config;
10+
use PHPUnit\Framework\TestCase;
11+
use Omise\Payment\Test\Mock\InfoMock;
12+
13+
abstract class APMBuilderTest extends TestCase
14+
{
15+
protected $builder;
16+
protected $helper;
17+
protected $returnUrlHelper;
18+
protected $config;
19+
protected $capabilities;
20+
protected $orderMock;
21+
protected $infoMock;
22+
23+
protected function setUp(): void
24+
{
25+
$this->helper = $this->getMockBuilder(OmiseHelper::class)->disableOriginalConstructor()->getMock();
26+
$this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock();
27+
$this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
28+
$this->capabilities = $this->getMockBuilder(Capabilities::class)->disableOriginalConstructor()->getMock();
29+
$this->orderMock = $this->getMockBuilder(OrderAdapterInterface::class)->getMock();
30+
$this->infoMock = $this->getMockBuilder(InfoMock::class)->getMock();
31+
}
32+
}

Test/Unit/APMRequestValidatorTest.php renamed to Test/Unit/Gateway/Request/APMBuilders/APMRequestValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Omise\Payment\Test\Unit;
3+
namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders;
44

55
use PHPUnit\Framework\TestCase;
66
use Omise\Payment\Model\Config\Atome;

0 commit comments

Comments
 (0)