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

Release v3.6.0 #468

Merged
merged 12 commits into from
Jan 23, 2024
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
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

51 changes: 0 additions & 51 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## [v3.6.0 _(Jan, 23, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.6.0)
- Add truemoney jumpapp. (PR: [#466](https://github.com/omise/omise-magento/pull/466))
- Updated README.md. (PR: [#464](https://github.com/omise/omise-magento/pull/464))

## [v3.5.2 _(Dec, 7, 2023)_](https://github.com/omise/omise-magento/releases/tag/v3.5.2)
- Updated installment interest rates. (PR: [#460](https://github.com/omise/omise-magento/pull/460))

Expand Down
39 changes: 32 additions & 7 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

class APMBuilder implements BuilderInterface
{

/**
* @var string
*/
Expand Down Expand Up @@ -122,6 +121,16 @@ class APMBuilder implements BuilderInterface
*/
protected $money;

/**
* @var Capabilities
*/
protected $capabilities;

/**
* @var Config
*/
protected $config;

/**
* @param $helper \Omise\Payment\Helper\OmiseHelper
* @param $returnUrl \Omise\Payment\Helper\ReturnUrl
Expand Down Expand Up @@ -183,12 +192,7 @@ public function build(array $buildSubject)
];
break;
case Truemoney::CODE:
$paymentInfo[self::SOURCE] = [
self::SOURCE_TYPE => 'truemoney',
self::SOURCE_PHONE_NUMBER => $method->getAdditionalInformation(
TruemoneyDataAssignObserver::PHONE_NUMBER
),
];
$paymentInfo[self::SOURCE] = $this->getTruemoneySourceData($method);
break;
case Conveniencestore::CODE:
$paymentInfo[self::SOURCE] = [
Expand Down Expand Up @@ -404,4 +408,25 @@ private function getOrderItems($order)
}
return $itemArray;
}

public function getTruemoneySourceData($method)
{
$isJumpAppEnabled = $this->capabilities->isBackendEnabled(Truemoney::JUMPAPP_ID);
$isWalletEnabled = $this->capabilities->isBackendEnabled(Truemoney::ID);

if (!$isJumpAppEnabled && $isWalletEnabled) {
return [
self::SOURCE_TYPE => Truemoney::ID,
self::SOURCE_PHONE_NUMBER => $method->getAdditionalInformation(
TruemoneyDataAssignObserver::PHONE_NUMBER
)
];
}

// Returning JUMP APP for the following cases:
// Case 1: Both jumpapp and wallet are enabled
// Case 2: jumpapp is enabled and wallet is disabled
// Case 3: Both are disabled.
return [ self::SOURCE_TYPE => Truemoney::JUMPAPP_ID ];
}
}
3 changes: 2 additions & 1 deletion Helper/OmiseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class OmiseHelper extends AbstractHelper
// offsite payment
Alipay::ID => Alipay::CODE,
Truemoney::ID => Truemoney::CODE,
Truemoney::JUMPAPP_ID => Truemoney::CODE,
Pointsciti::ID => Pointsciti::CODE,
Fpx::ID => Fpx::CODE,
Alipayplus::ALIPAY_ID => Alipayplus::ALIPAY_CODE,
Expand Down Expand Up @@ -187,7 +188,7 @@ class OmiseHelper extends AbstractHelper
Alipay::CODE => "Alipay",
Internetbanking::CODE => "Internet Banking Payment",
Installment::CODE => "Installment Payment",
Truemoney::CODE => "TrueMoney Wallet Payment",
Truemoney::CODE => "TrueMoney Payment",
Pointsciti::CODE => "Citi Pay with Points",
Fpx::CODE => "FPX Payment",
Alipayplus::ALIPAY_CODE => "Alipay (Alipay+ Partner) Payment",
Expand Down
2 changes: 2 additions & 0 deletions Model/Config/Truemoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class Truemoney extends Config
* @var string
*/
const ID = 'truemoney';

const JUMPAPP_ID = 'truemoney_jumpapp';
}
71 changes: 57 additions & 14 deletions Model/Ui/CapabilitiesConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omise\Payment\Helper\OmiseHelper;
use Omise\Payment\Model\Capabilities;
use Omise\Payment\Model\Config\Shopeepay;
use Omise\Payment\Model\Config\Truemoney;
use Omise\Payment\Model\Config\CcGooglePay;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Checkout\Model\ConfigProviderInterface;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function __construct(
$this->capabilities = $capabilities;
$this->_paymentLists = $paymentLists;
$this->_storeManager = $storeManager;
$this->helper = $helper;
$this->helper = $helper;
}

/**
Expand All @@ -46,12 +47,8 @@ public function getConfig()
$listOfActivePaymentMethods = $this->_paymentLists->getActiveList($this->_storeManager->getStore()->getId());
$currency = $this->_storeManager->getStore()->getCurrentCurrencyCode();
$configs = [];

// Retrieve available backends & methods from capabilities api
$backends = $this->capabilities->getBackendsWithOmiseCode();
$tokenization_methods = $this->capabilities->getTokenizationMethodsWithOmiseCode();
$backends = array_merge($backends, $tokenization_methods);
$configs['omise_installment_min_limit'] = $this->capabilities->getInstallmentMinLimit($currency);
$configs['omise_payment_list'] = [];

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

// filter only active backends
if (array_key_exists($code, $backends)) {
if ($code === 'omise_offsite_shopeepay') {
$configs['omise_payment_list'][$code] = $this->getShopeeBackendByType($backends[$code]);
} else {
$configs['omise_payment_list'][$code] = $backends[$code];
}
}
$this->filterActiveBackends($code, $configs['omise_payment_list']);
}

return $configs;
}

/**
* filter only active backends
* @param $code Payment method code
* @param $paymentList Reference of the payment list
*/
private function filterActiveBackends($code, &$paymentList)
{
// Retrieve available backends & methods from capabilities api
$paymentBackends = $this->capabilities->getBackendsWithOmiseCode();
$tokenizationMethods = $this->capabilities->getTokenizationMethodsWithOmiseCode();
$mergedBackends = array_merge($paymentBackends, $tokenizationMethods);

// filter only active backends
if (!array_key_exists($code, $mergedBackends)) {
return;
}

if ($code === Shopeepay::CODE) {
$backend = $this->getShopeeBackendByType($mergedBackends[$code]);
} elseif ($code === Truemoney::CODE) {
$backend = $this->getTruemoneyBackendByType($mergedBackends[$code]);
} else {
$backend = $configs['omise_payment_list'][$code] = $mergedBackends[$code];
}

$paymentList[$code] = $backend;
}

/**
* Return the right ShopeePay backend depending on the platform and availability of
* the backend in the capability
Expand Down Expand Up @@ -116,4 +134,29 @@ private function getShopeeBackendByType($shopeeBackends)
// execute if none of the shopee backends were disabled.
return $isShopeepayEnabled ? $mpmBackend : $jumpAppBackend;
}

private function getTruemoneyBackendByType($truemoneyBackends)
{
$jumpAppBackend = [];
$walletBackend = [];

// Since Truemoney will have two types i.e truemoney and truemoney_jumpapp,
// we split and store the type in separate variables.
foreach ($truemoneyBackends as $backend) {
if ($backend->type === Truemoney::JUMPAPP_ID) {
$jumpAppBackend[] = $backend;
} else {
$walletBackend[] = $backend;
}
}

$isJumpAppEnabled = $this->capabilities->isBackendEnabled(Truemoney::JUMPAPP_ID);
$isWalletEnabled = $this->capabilities->isBackendEnabled(Truemoney::ID);

if (!$isJumpAppEnabled && $isWalletEnabled) {
return $walletBackend;
}

return $jumpAppBackend;
}
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<!--- KEEP START --->
[![Omise](https://cdn.omise.co/assets/omise.png)](https://www.omise.co/developers)
[![Opn Payments](https://www.opn.ooo/assets/svg/logo-opn-full.svg)](https://www.opn.ooo)

![Code Coverage Badge](./badge.svg)

[Omise](https://www.omise.co/) is a payment service provider operating in Thailand, Japan, and Singapore.
Omise provides a set of APIs that help merchants of any size accept payments online.
[Opn Payments](https://www.opn.ooo) is a payment service provider operating in Thailand, Japan, and Singapore.
Opn Payments provides a set of APIs that help merchants of any size accept payments online.
<!--- KEEP END --->

**Omise Magento** is our official plugin providing support for processing payments on Magento through Omise.
**Omise Magento** is our official plugin providing support for processing payments on Magento through Opn Payments.

## Usage

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

## Contributing

Expand Down
32 changes: 32 additions & 0 deletions Test/Unit/Gateway/Request/APMBuilders/APMBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders;

use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Omise\Payment\Helper\OmiseHelper;
use Omise\Payment\Helper\ReturnUrlHelper;
use Omise\Payment\Model\Capabilities;
use Omise\Payment\Model\Config\Config;
use PHPUnit\Framework\TestCase;
use Omise\Payment\Test\Mock\InfoMock;

abstract class APMBuilderTest extends TestCase
{
protected $builder;
protected $helper;
protected $returnUrlHelper;
protected $config;
protected $capabilities;
protected $orderMock;
protected $infoMock;

protected function setUp(): void
{
$this->helper = $this->getMockBuilder(OmiseHelper::class)->disableOriginalConstructor()->getMock();
$this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock();
$this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$this->capabilities = $this->getMockBuilder(Capabilities::class)->disableOriginalConstructor()->getMock();
$this->orderMock = $this->getMockBuilder(OrderAdapterInterface::class)->getMock();
$this->infoMock = $this->getMockBuilder(InfoMock::class)->getMock();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Omise\Payment\Test\Unit;
namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders;

use PHPUnit\Framework\TestCase;
use Omise\Payment\Model\Config\Atome;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
<?php

namespace Omise\Payment\Test\Unit;
namespace Omise\Payment\Test\Unit\Gateway\Request\APMBuilders;

use Magento\Payment\Gateway\Data\OrderAdapterInterface;
use Magento\Payment\Gateway\Data\PaymentDataObject;
use Omise\Payment\Gateway\Request\APMBuilder;
use Omise\Payment\Helper\OmiseHelper;
use Omise\Payment\Helper\OmiseMoney;
use Omise\Payment\Helper\ReturnUrlHelper;
use Omise\Payment\Model\Capabilities;
use Omise\Payment\Model\Config\Alipay;
use Omise\Payment\Model\Config\Config;
use PHPUnit\Framework\TestCase;
use Omise\Payment\Test\Mock\InfoMock;
use Omise\Payment\Test\Unit\Gateway\Request\APMBuilders\APMBuilderTest;

class AlipayAPMBuilderTest extends TestCase
class AlipayAPMBuilderTest extends APMBuilderTest
{
private $builder;
private $helper;
private $returnUrlHelper;
private $config;
private $capabilities;
private $orderMock;
private $infoMock;

protected function setUp(): void
{
$this->helper = $this->getMockBuilder(OmiseHelper::class)->disableOriginalConstructor()->getMock();
$this->returnUrlHelper = $this->getMockBuilder(ReturnUrlHelper::class)->disableOriginalConstructor()->getMock();
$this->config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$this->capabilities = $this->getMockBuilder(Capabilities::class)->disableOriginalConstructor()->getMock();
$this->orderMock = $this->getMockBuilder(OrderAdapterInterface::class)->getMock();
$this->infoMock = $this->getMockBuilder(InfoMock::class)->getMock();
}

/**
* @covers Omise\Payment\Gateway\Request\APMBuilder
* @covers Omise\Payment\Model\Config\Alipay
Expand Down
Loading
Loading