-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from xendit/TPI-7013/whmcs-cron-bug
Fix hook invoice creation error
- Loading branch information
Showing
1 changed file
with
38 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,61 @@ | ||
<?php | ||
/** | ||
* Register hook function call. | ||
* | ||
* @param string $hookPoint The hook point to call. | ||
* @param integer $priority The priority for the hook function. | ||
* @param string|function The function name to call or the anonymous function. | ||
* | ||
* @return This depends on the hook function point. | ||
*/ | ||
|
||
use Xendit\Lib\ActionBase; | ||
use Xendit\Lib\Recurring; | ||
if (!defined('WHMCS')) { | ||
die('You cannot access this file directly.'); | ||
} | ||
|
||
/** | ||
* Hook invoice created | ||
* Hook invoice creation | ||
* | ||
* @param $vars | ||
* @return void | ||
* @return array|void | ||
*/ | ||
add_hook('InvoiceCreation', 1, function ($vars) { | ||
if ($vars['status'] == 'Draft') { | ||
return; | ||
} | ||
function hookInvoiceCreation($vars) | ||
{ | ||
if ($vars['status'] !== 'Draft' && class_exists('\Xendit\Lib\Recurring')) { | ||
$xenditRecurring = new \Xendit\Lib\Recurring(); | ||
$invoice = $xenditRecurring->getInvoice($vars['invoiceid']); | ||
|
||
$xenditRecurring = new Recurring(); | ||
$invoice = $xenditRecurring->getInvoice($vars['invoiceid']); | ||
// if payment method is Xendit | ||
if ($invoice->paymentmethod != $xenditRecurring->getDomainName()) { | ||
return; | ||
} | ||
|
||
// if payment method is Xendit | ||
if ($invoice->paymentmethod != $xenditRecurring->getDomainName()) { | ||
return; | ||
// Save xendit transaction | ||
return $xenditRecurring->storeTransactions($vars['invoiceid']); | ||
} | ||
} | ||
|
||
add_hook('InvoiceCreation', 1, 'hookInvoiceCreation'); | ||
|
||
// Save xendit transaction | ||
$xenditRecurring->storeTransactions($vars['invoiceid']); | ||
}); | ||
|
||
/** | ||
* Hook to show Xendit payment gateway based on currency | ||
* | ||
* @param $vars | ||
* @return array|void | ||
*/ | ||
add_hook("ClientAreaPageCart", 1, function ($vars) { | ||
if ($vars['templatefile'] == 'viewcart') { | ||
$actionBase = new ActionBase(); | ||
function hookClientAreaPageCart($vars) | ||
{ | ||
if ($vars['templatefile'] == 'viewcart' && class_exists('\Xendit\Lib\ActionBase')) { | ||
$actionBase = new \Xendit\Lib\ActionBase(); | ||
$activeCurrency = $vars['currency']['code'] ?? $vars['activeCurrency']->code; | ||
if (!$actionBase->validateCompatibilityVersion() || !in_array($activeCurrency, ActionBase::ALLOW_CURRENCIES)) { | ||
if (!$actionBase->validateCompatibilityVersion() | ||
|| !in_array($activeCurrency, \Xendit\Lib\ActionBase::ALLOW_CURRENCIES) | ||
) { | ||
unset($vars['gateways']["xendit"]); | ||
} | ||
} | ||
return $vars; | ||
}); | ||
} | ||
|
||
add_hook("ClientAreaPageCart", 1, 'hookClientAreaPageCart'); |