hasajacykacperek Posted January 24, 2020 Share Posted January 24, 2020 (edited) Hello, can i debug a print function (print_r($whmcsinvoice);) from hook InvoicePaid? My code like this: add_hook('InvoicePaid', 1, function ($vars) { $command = 'GetInvoice'; $postData = array( 'invoiceid' => $invoiceid, ); $results = localAPI($command, $postData); $whmcsinvoice = json_decode($results); print_r($whmcsinvoice); $services_data = []; foreach($whmcsinvoice['items']['item'] as $item) { $services_data .= [ 'data' =>[ 'name' => $item['name'], 'tax_symbol' => 23, 'gross_price' => $item['amount'], ] ]; } $services = array_values($services_data); $invoice_data = [ 'invoice' => [ 'payment_method' => $whmcsinvoice['paymentmethod'], 'client_company_name' => "WHMCS User ID: ".$whmcsinvoice['userid'], 'net_price' => str_replace('.', '', $whmcsinvoice['subtotal']), 'tax_price' => str_replace('.', '', $whmcsinvoice['tax']), 'gross_price' => str_replace('.', '', $whmcsinvoice['total']), //'services' => $services 'services' => [ 'name' => "WHMCS_SERVICES" ] ] ]; $data = json_encode($invoice_data); $ch = curl_init(); $options = [ CURLOPT_URL => "https://api.infakt.pl/v3/invoices.json", CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-inFakt-ApiKey: XXXXXXXXXXXXXXXXXXXXXX'], CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data, ]; curl_setopt_array( $ch, $options ); $response = curl_exec($ch); $infakt = get_object_vars(json_decode($response)); curl_close ($ch); $chpay = curl_init(); $options = [ CURLOPT_URL => "https://api.infakt.pl/v3/invoices/".$infakt['id']."/paid.json", CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-inFakt-ApiKey: XXXXXXXXXXXXXXXXXXXXXX'], CURLOPT_POST => true, CURLOPT_POSTFIELDS => '{"paid_date":"'.$whmcsinvoice['datepaid'].'"}' ]; curl_setopt_array( $chpay, $options ); curl_exec($chpay); curl_close ($chpay); }); thanks! Edited January 24, 2020 by WHMCS Peter Removed live API Key data 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted January 24, 2020 WHMCS Staff Share Posted January 24, 2020 Hi! In this case, I'd consider logging the value to the Activity Log for development purposes. to ensure that the value can be evaluated. To achieve this, you can add this line: logActivity(print_r($whmcsinvoice, true)); More information: https://developers.whmcs.com/advanced/logging/ 0 Quote Link to comment Share on other sites More sharing options...
hasajacykacperek Posted January 24, 2020 Author Share Posted January 24, 2020 Thanks for reply! I don't know if it's for a long text, field is blank logActivity(); works fine 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted January 24, 2020 WHMCS Staff Share Posted January 24, 2020 Hi! I'd recommend removing the json_decode. WHMCS returns an array by default on the localAPI so json_decode should not be required. 0 Quote Link to comment Share on other sites More sharing options...
hasajacykacperek Posted January 24, 2020 Author Share Posted January 24, 2020 Thanks!! Its working Variable $invoiceid returns all times "1" I looked for: https://developers.whmcs.com/hooks-reference/invoices-and-quotes/#invoicepaid 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted January 24, 2020 WHMCS Staff Share Posted January 24, 2020 Perfect. I'm glad I could help! 0 Quote Link to comment Share on other sites More sharing options...
hasajacykacperek Posted January 24, 2020 Author Share Posted January 24, 2020 1 minute ago, WHMCS Peter said: Perfect. I'm glad I could help! Returns "1" its the next problem, for example invoice have id "20", variable $invoiceid have "1" 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted January 24, 2020 WHMCS Staff Share Posted January 24, 2020 $invoiceid is not being defined in your code. It should be $vars['invoiceid']. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.