Getting the pdf invoice from WHMCS?

拟墨画扇 提交于 2021-02-07 19:21:45

问题


For a small side project, I had to create a call that gets the PDF via WHMCS. I see the API can get the variables, such as quantity, invoice items etc, but I want the same PDF that the system would send if a client had placed an order. I have a PHP app.

UPDATE

Following the awesome advice below, I was able to solve this in one line:

$pdf->Output('invoice.'.$invoicenum.'.pdf', 'F');

Now every time the invoice is viewed, or emailed, the latest version (paid or unpaid) is stored at the location I chose.


回答1:


There is an article Store Pdf Invoice on ftp with this information:

1-Change in this code
INVOICESDIRECTORY - directory where I'm keeping PDF invoices
ADMINDIRECTORY - administration directory
2- Paste it in last line of invoicepdf.tpl file in Your template.

if ($status=="Paid") {
        if(strpos($_SERVER['PHP_SELF'],"ADMINDIRECTORY") === false) {
                if((strpos($_SERVER['PHP_SELF'],"dl.php") !== false) || (strpos($_SERVER['PHP_SELF'],"dl.html") !== false)) {
                        if(!file_exists("./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf")) {
                                $pdf->Output("./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf", "F");
                        }              
                        $fullPath = "./INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf";    
                        if ($fd = fopen ($fullPath, "r")) {
                                $fsize = filesize($fullPath);
                                $path_parts = pathinfo($fullPath);
                                $ext = strtolower($path_parts["extension"]);
                                switch ($ext) {
                                        case "pdf":
                                        header("Content-type: application/pdf"); // add here more headers for diff. extensions
                                        header("Content-Disposition: attachment; filename=\"".str_replace("-", "/", $path_parts["basename"])."\""); // use 'attachment' to force a download
                                        break;
                                        default;
                                        header("Content-type: application/octet-stream");
                                        header("Content-Disposition: filename=\"".str_replace("-", "/", $path_parts["basename"])."\"");
                                }
                                header("Content-length: $fsize");
                                header("Cache-control: private"); //use this to open files directly
                                while(!feof($fd)) {
                                        $buffer = fread($fd, 2048);
                                        echo $buffer;
                                }
                        }
                        fclose ($fd);
                        exit;
                }
        }
        else {
                if(!file_exists("./../INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf")) {
                        $pdf->Output("./../INVOICESDIRECTORY/".str_replace("/", "-", $invoicenum).".pdf", "F");
                }
        }
}



回答2:


A better solution can be found here. This involves creating an API call that base64 encodes the result to you. Much more sophisticated.



来源:https://stackoverflow.com/questions/19994866/getting-the-pdf-invoice-from-whmcs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!