Skip to content

Commit

Permalink
Merge pull request #16 from xendit/TPI-6978/whmcs-check-version-compa…
Browse files Browse the repository at this point in the history
…tibility

Check WHMCS version compatible with our plugin
  • Loading branch information
andykim authored Apr 27, 2022
2 parents 7a5d107 + 10581b0 commit 84c3d4e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/gateways/xendit/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
*/
add_hook("ClientAreaPageCart", 1, function ($vars) {
if ($vars['templatefile'] == 'viewcart') {
$actionBase = new ActionBase();
$activeCurrency = $vars['activeCurrency']->code;
if (!in_array($activeCurrency, ActionBase::ALLOW_CURRENCIES)) {
if (!$actionBase->validateCompatibilityVersion() || !in_array($activeCurrency, ActionBase::ALLOW_CURRENCIES)) {
unset($vars['gateways']["xendit"]);
}
}
Expand Down
30 changes: 30 additions & 0 deletions modules/gateways/xendit/lib/ActionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class ActionBase
{
const ALLOW_CURRENCIES = ['IDR', 'PHP', 'USD'];
const WHMCS_MIN_VERSION_SUPPORT = 7.9;

protected $moduleDomain = 'xendit';
protected $xenditRequest;
Expand Down Expand Up @@ -44,6 +45,24 @@ public function getXenditConfig()
*/
public function createConfig()
{
if (!$this->validateCompatibilityVersion()) {
return array(
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'Xendit Payment Gateway',
),
'description' => array(
'FriendlyName' => '',
'Type' => 'hidden',
'Size' => '72',
'Default' => '',
'Description' => '<div class="alert alert-danger top-margin-5 bottom-margin-5">
Your WHMCS version not compatibility with Xendit Payment Gateway. <a href="https://marketplace.whmcs.com/product/6411-xendit-payment-gateway" target="_blank">See more</a>
</div>',
),
);
}

return array(
'FriendlyName' => array(
'Type' => 'System',
Expand Down Expand Up @@ -298,4 +317,15 @@ public function roundUpTotal(float $total): float
{
return ceil($total);
}

/***
* @param string|null $currentVersion
* @return bool
*/
public function validateCompatibilityVersion(string $currentVersion = null): bool
{
global $CONFIG;
$version = !empty($currentVersion) ? $currentVersion : $CONFIG['Version'];
return version_compare($version, self::WHMCS_MIN_VERSION_SUPPORT, ">=");
}
}
23 changes: 23 additions & 0 deletions modules/gateways/xendit/tests/WHMCSModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,27 @@ public function testCallbackPaidTotal()
);
}
}

public function testVersionCompatibility()
{
$actionBase = new \Xendit\Lib\ActionBase();
$versions = [
"7.5" => false,
"7.6" => false,
"7.7.2" => false,
"7.8.1" => false,
"7.9" => true,
"8.0.1" => true,
"8.1.1" => true,
"8.2" => true,
"8.4" => true
];
foreach ($versions as $version => $expect) {
if ($expect) {
$this->assertTrue($actionBase->validateCompatibilityVersion($version));
} else {
$this->assertFalse($actionBase->validateCompatibilityVersion($version));
}
}
}
}

0 comments on commit 84c3d4e

Please sign in to comment.