pmesariya / freshbooks-php-library

Automatically exported from code.google.com/p/freshbooks-php-library
0 stars 0 forks source link

Unable to get() and update() Invoices #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that the library (as it currently stands) doesn't allow for usage of 
get() to grab Invoice data. As far as I can work out, there is also no way to 
update() invoices.

Example usage:

FreshBooks_HttpClient::init(FRESHBOOKS_URL,FRESHBOOKS_TOKEN);

$invoice = new Freshbooks_Invoice();
$invoice->invoice_id = '00000324300';

if (!$invoice->get('00000324300')) {
    die($invoice->lastError);
}
else {
    print_r($invoice);
}

This returns the error message: 'invoice_id' not found. Invoice not found.

I've also tried supplying the Invoice ID in other formats, e.g: invouce Number 
(0000172) and that doesn't help either.

Original issue reported on code.google.com by jspit...@gmail.com on 28 Dec 2013 at 3:44

GoogleCodeExporter commented 9 years ago
There is also reference to this in Issue #1 with a potentially useful 
explanation on why it doesn't work as it should:

What steps will reproduce the problem?
1. Use FreshBooks_Invoice::get() to get an existing invoice.
2. Call FreshBooks_Invoice::update() to update the invoice.
3. Examine the value for the $invoiceId field of the invoice.

What is the expected output?
The $invoiceId field of the invoice object should still contain the invoice ID.

What do you see instead?
The invoice ID is empty. This is because in
FreshBooks_ElementAction::update(), _internalPrepareCreate() is called
instead of _internalPrepareUpdate(), and _internalCreate() is called
instead of _internalUpdate() .

What version of the product are you using?
FreshBooks PHP 1.2

Original comment by jspit...@gmail.com on 28 Dec 2013 at 3:46

GoogleCodeExporter commented 9 years ago
Managed to fix this for the purpose of what I was trying to do with it (mark an 
invoice as paid.)

Here's an example of how to do it:

    $payment = new Freshbooks_Payment();

    $payment->invoiceId = '00000324300';

    // To mark payment as 'PAID', this amount must be the full amount outstanding on the invoice
    $payment->amount    = '2.44';

    $payment->type      = 'Bank Transfer';

    $payment->create()
        or die("Unable to mark Invoice as paid: " . $payment->lastError);

Hope that helps.

Original comment by jspit...@gmail.com on 28 Dec 2013 at 8:31