PHP SDK Capture/Print return success or errors

I am successfully using the PHP API to create invoices but I would like to know how I can capture the response from the API. For example, the invoice number that’s created, was the call successful, if the call failed, what was the reason or error?

Basically I normally hit an API then capture the response and act on it.

Another example would be setting auto-bill to true, can I get feedback from the API to tell me if the payment failed or not so I know if I should deliver the product, tell the customer the payment failed etc?

Thanks

Not sure I follow, this information should be in the response. What are you getting back?

Sorry… I see, you’re using the PHP SDK.

In that case you’d need to query the invoice afterwards.

How would I know the invoice number in my code to query the invoice lol

The documentation for the PHP API is super limited. There are very few examples. I don’t know how to get anything back from your API. I only see how to create the invoice. How do I capture the data your API is returning such as errors, invoice numbers etc?

I’ve reviewed the code (it’s been a while since I wrote it), I believe calling save() will return the object.

I call save already to create the invoice. How do I for example turn that into a variable or an array to evaluate and print it or make a decision?

Have you checked the response from the save method, ie.

$invoice = $invoice->save()

I guess I can try to echo that or print_r to see what’s In there. Thanks

Thank you @hillel

For anyone trying to accomplish the same, here is some more specifics on, for example how to get the invoice number in the response after creating an invoice using the PHP SDK.

$invoiceOutput = $invoice->save();

$invNum = $invoiceOutput->invoice_number;

print “invoice_number: ${invNum}”;

1 Like