Question

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)

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top