Skip to content

Commit

Permalink
[ENGA3-690]: Added ShopeePay under Thailand and Singpaore. (#404)
Browse files Browse the repository at this point in the history
* WIP

* [ENGA3-690]: Added ShopeePay under Thailand and Singpaore. Added Jump App if the platform is mobile device.

* WIP

* [ENGA3-690]: Added capability check for shopeepay direct and jumpapp.

* [ENGA3-690]: Fixing Magento coding standard alerts.

* [ENGA3-690]: Removed unused variable. Added comments on the logic to choose right backend and source for shopee.

* [ENGA3-690]: Improved code comments.
  • Loading branch information
aashishgurung authored Dec 15, 2022
1 parent b3810ca commit 39dc871
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 9 deletions.
43 changes: 37 additions & 6 deletions Gateway/Request/APMBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use Omise\Payment\Observer\TruemoneyDataAssignObserver;
use Omise\Payment\Helper\OmiseHelper as Helper;
use Omise\Payment\Helper\ReturnUrlHelper;
use Omise\Payment\Model\Config\Config;
use Omise\Payment\Model\Capabilities;

class APMBuilder implements BuilderInterface
{
Expand Down Expand Up @@ -103,10 +105,16 @@ class APMBuilder implements BuilderInterface
* @param $helper \Omise\Payment\Helper\OmiseHelper
* @param $returnUrl \Omise\Payment\Helper\ReturnUrl
*/
public function __construct(Helper $helper, ReturnUrlHelper $returnUrl)
{
public function __construct(
Helper $helper,
ReturnUrlHelper $returnUrl,
Config $config,
Capabilities $capabilities
) {
$this->helper = $helper;
$this->returnUrl = $returnUrl;
$this->config = $config;
$this->capabilities = $capabilities;
}

/**
Expand All @@ -127,9 +135,7 @@ public function build(array $buildSubject)

switch ($method->getMethod()) {
case Alipay::CODE:
$paymentInfo[self::SOURCE] = [
self::SOURCE_TYPE => 'alipay'
];
$paymentInfo[self::SOURCE] = Alipay::getSourceData();
break;
case Tesco::CODE:
$paymentInfo[self::SOURCE] = [
Expand Down Expand Up @@ -280,11 +286,36 @@ public function build(array $buildSubject)
break;
case Shopeepay::CODE:
$paymentInfo[self::SOURCE] = [
self::SOURCE_TYPE => 'shopeepay',
self::SOURCE_TYPE => $this->getShopeepaySource()
];
break;
}

return $paymentInfo;
}

private function getShopeepaySource()
{
$isShopeepayJumpAppEnabled = $this->capabilities->isBackendEnabled(Shopeepay::JUMPAPP_ID);
$isShopeepayEnabled = $this->capabilities->isBackendEnabled(Shopeepay::ID);

// If user is in mobile and jump app is enabled then return shopeepay_jumpapp as source
if ($this->helper->isMobilePlatform() && $isShopeepayJumpAppEnabled) {
return Shopeepay::JUMPAPP_ID;
}

// If above condition fails then it means either
//
// Case 1.
// User is using mobile device but jump app is not enabled.
// This means shopeepay direct is enabled otherwise this code would not execute.
//
// Case 2.
// Jump app is enabled but user is not using mobile device
//
// In both cases we will want to show the shopeepay MPM backend first if MPM is enabled.
// If MPM is not enabled then it means jump app is enabled because this code would never
// execute if none of the shopee backends were disabled.
return $isShopeepayEnabled ? Shopeepay::ID : Shopeepay::JUMPAPP_ID;
}
}
9 changes: 9 additions & 0 deletions Helper/OmiseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class OmiseHelper extends AbstractHelper
DuitnowQR::ID => DuitnowQR::CODE,
MaybankQR::ID => MaybankQR::CODE,
Shopeepay::ID => Shopeepay::CODE,
Shopeepay::JUMPAPP_ID => Shopeepay::CODE,

// offsite internet banking payment
Internetbanking::BBL_ID => Internetbanking::CODE,
Expand Down Expand Up @@ -440,6 +441,14 @@ public function getPlatformType()
return "WEB";
}

/**
* Check if current platform is mobile or not
*/
public function isMobilePlatform()
{
return 'WEB' !== $this->getPlatformType();
}

/**
* Depending on the setting of state to generate invoice, we will either create an invoice or return a created one.
* Invoice will be marked as successfully paid and returned.
Expand Down
5 changes: 5 additions & 0 deletions Model/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public function getBackends()
return $this->capabilitiesAPI->getBackends();
}

public function isBackendEnabled($type)
{
return $this->getBackendsByType($type) ? true : false;
}

/**
*
* @return object
Expand Down
2 changes: 2 additions & 0 deletions Model/Config/Shopeepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class Shopeepay extends Config
* @var string
*/
const ID = 'shopeepay';

const JUMPAPP_ID = 'shopeepay_jumpapp';
}
55 changes: 53 additions & 2 deletions Model/Ui/CapabilitiesConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
use Omise\Payment\Model\Config\Fpx;
use Omise\Payment\Model\Config\Internetbanking;
use Omise\Payment\Model\Config\Mobilebanking;
use Omise\Payment\Model\Config\Shopeepay;
use Omise\Payment\Model\Config\Installment as OmiseInstallmentConfig;
use Omise\Payment\Helper\OmiseHelper;

class CapabilitiesConfigProvider implements ConfigProviderInterface
{
Expand All @@ -23,11 +25,13 @@ class CapabilitiesConfigProvider implements ConfigProviderInterface
public function __construct(
Capabilities $capabilities,
PaymentMethodListInterface $paymentLists,
StoreManagerInterface $storeManager
StoreManagerInterface $storeManager,
OmiseHelper $helper
) {
$this->capabilities = $capabilities;
$this->_paymentLists = $paymentLists;
$this->_storeManager = $storeManager;
$this->helper = $helper;
}

/**
Expand Down Expand Up @@ -59,9 +63,56 @@ public function getConfig()

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

return $configs;
}

/**
* Return the right ShopeePay backend depending on the platform and availability of
* the backend in the capability
*/
private function getShopeeBackendByType($shopeeBackends)
{
$jumpAppBackend = [];
$mpmBackend = [];

// Since ShopeePay will have two types i.e shopeepay and shopeepay_jumpapp,
// we split and store the type in separate variables.
foreach ($shopeeBackends as $backend) {
if ($backend->type === Shopeepay::JUMPAPP_ID) {
$jumpAppBackend[] = $backend;
} else {
$mpmBackend[] = $backend;
}
}

$isShopeepayJumpAppEnabled = $this->capabilities->isBackendEnabled(Shopeepay::JUMPAPP_ID);
$isShopeepayEnabled = $this->capabilities->isBackendEnabled(Shopeepay::ID);

// If user is in mobile and jump app is enabled then return jumpapp backend
if ($this->helper->isMobilePlatform() && $isShopeepayJumpAppEnabled) {
return $jumpAppBackend;
}

// If above condition fails then it means either
//
// Case 1.
// User is using mobile device but jump app is not enabled.
// This means shopeepay direct is enabled otherwise this code would not execute.
//
// Case 2.
// Jump app is enabled but user is not using mobile device
//
// In both cases we will want to show the shopeepay MPM backend first if MPM is enabled.
// If MPM is not enabled then it means jump app is enabled because this code would never
// execute if none of the shopee backends were disabled.
return $isShopeepayEnabled ? $mpmBackend : $jumpAppBackend;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ define(
isPlaceOrderActionAllowed: ko.observable(quote.billingAddress() != null),

code: 'omise_offsite_shopeepay',
restrictedToCurrencies: ['myr'],
restrictedToCurrencies: ['myr', 'thb', 'sgd'],
logo: {
file: "images/shopeepay.png",
width: "73",
Expand Down

0 comments on commit 39dc871

Please sign in to comment.