简体   繁体   中英

Recurly - Get invoice PDF (pdf from pdf string)

I'm working with recurly for billing my customers. But how can I get an invoice pdf?
What I have so far is a table with the invoices. I show the state, plan, started date, ended date of the invoice. Then I also have a link like this:

/user/invoicepdf/invoicenr/1502

The link goes to my invoicepdfaction and sends the invoicenr parameter.

In my invoicepdfaction I have this:

public function invoicepdfAction() {
    header('Content-Type:', 'application/pdf');
    header('Content-Disposition:', 'inline;');

    $request = $this->getRequest();
    $invoice_number = $request->getParam('invoicenr');

    try {
        $pdf = Recurly_Invoice::getInvoicePdf($invoice_number, 'en-US');
        var_dump($pdf);
    } catch (Recurly_NotFoundError $e) {
        print "Invoice not found.\n";
    }
}

My var_dump shows this .

But how can I show the pdf in the browser? (Or download it directly)

This usually works for me:

$request = $this->getRequest();
$invoice_number = $request->getParam('invoicenr');

try {
    header('Content-type: application/pdf');
    header('Accept-Language: en-US');
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    $pdf = Recurly_Invoice::getInvoicePdf($invoice_number, 'en-US');
    print($pdf);
} catch (Recurly_NotFoundError $e) {
    print "Invoice not found.\n";
}     

You can always submit a support ticket to support@recurly.com as they provide support for all their client libraries.

That should be the binary PDF file. Have you tried saving it to the disk an opening it up in Acrobat or Preview?

I'm not sure how Zend would have your return it but you should be able to just echo the contents back to the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM