Skip to content

Commit

Permalink
Merge pull request #19 from xendit/TPI-7013/whmcs-cron-bug
Browse files Browse the repository at this point in the history
Fix hook invoice creation error
  • Loading branch information
andykim authored May 4, 2022
2 parents 8d55a05 + 4f746ab commit 3c0de24
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions modules/gateways/xendit/hooks.php
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');

0 comments on commit 3c0de24

Please sign in to comment.