forked from paghiper/whmcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoicepdf.tpl
58 lines (40 loc) · 1.74 KB
/
invoicepdf.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Adiciona boleto bancário como página adicional na fatura anexa no WHMCS
* @author Henrique Cruz | henriquecruz.com.br
* @copyright Copyright (c) 2019 https://henriquecruz.com.br
*/
$whmcs_url = rtrim(\App::getSystemUrl(),"/");
$json_url = $whmcs_url."/modules/gateways/paghiper.php?invoiceid=".$invoiceid."&uuid=".$clientsdetails['userid']."&mail=".$clientsdetails['email']."&json=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
$result = json_decode($json);
$transaction_id = (isset($result->transaction_id)) ? $result->transaction_id : '';
$pdf_url = (isset($result->bank_slip)) ? $result->bank_slip->url_slip_pdf : $result->url_slip_pdf;
if ((in_array($status, array('Unpaid', 'Payment Pending'))) && (isset($pdf_url) && !empty($pdf_url)) && (isset($transaction_id) && !empty($transaction_id))){
$basedir = dirname(__FILE__).'/../../modules/gateways/paghiper/';
/* Bloco inicializador do boleto */
require_once($basedir.'inc/fpdi/fpdi.php');
$pdf = new FPDI();
// TODO: Implementar header e footer aqui
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $pdf_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rawdata = curl_exec($ch);
$filename = $basedir.'tmp/'.$transaction_id.'.pdf';
$fp = fopen($filename, 'w');
fwrite($fp, $rawdata);
fclose($fp);
$pdf->setSourceFile($filename);
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0, 210);
/* Bloco inicializador do template comum */
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
} ?>