Categories
Uncategorized

whmcs api does not handle add fund api what is the solution?

i can not create add fund invoice from api call and whmcs api dows not support to create add fund invoice from api.

i have created custom hook file that can change type of invoice created with api to add fund in database

create a php file in whmcs/includes/hooks and copy code below in that file

<?php
/**
 * Example Hook Function
 *
 * Please refer to the documentation @ https://docs.whmcs.com/Hooks for more information
 * The code in this hook is commented out by default. Uncomment to use.
 *
 * @package    WHMCS
 * @author     WHMCS Limited <[email protected]>
 * @copyright  Copyright (c) WHMCS Limited 2005-2018
 * @license    https://www.whmcs.com/license/ WHMCS Eula
 * @version    $Id$
 * @link       https://www.whmcs.com/
 */

use WHMCS\Database\Capsule;

if (!defined("WHMCS"))
    die("This file cannot be accessed directly");
add_hook('InvoiceCreated', 1, function($vars) {
    // Perform hook code here...
    $source = $vars['source'];
    $invoiceid = $vars['invoiceid'];   
if($source=='api'){
try {
    $updateinvoicetype = Capsule::table('tblinvoiceitems')
        ->where('description', 'Add Fund')
        ->where('invoiceid', $invoiceid)
        ->update(
            [
                'type' => 'AddFunds',
            ]
        );


} catch (\Exception $e) {

}
} 
});

this hook will update all invoice created from api and when description of invoice is “Add Fund”

Leave a Reply

Your email address will not be published. Required fields are marked *