invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 41 forks source link

Create Recurring Invoice & First Invoice #15

Closed AugmentBLU closed 7 years ago

AugmentBLU commented 7 years ago

Hello,

I was wondering if it's possible to create a recurring invoice and to send the first invoice right away? I see you can set the is_recurring etc but it doesn't seem to send the payable invoice.

I tried

$dt = Carbon::now();
$invoice = $client->createInvoice();
$invoice->addInvoiceItem('item', '', 14.99, 1);
$invoice->email_invoice = true;
$invoice->is_recurring = true;
$invoice->frequency_id = 4;
$invoice->start_date = $dt->toDateString();
$invoice->due_date = $dt->toDateString();
$invoice->save();

Do we have to create a standard invoice and the recurring invoice separately so there's at least one invoice to pay right away and then when then recurring frequency is met it then auto generates the invoice from there?

hillelcoren commented 7 years ago

One option may be to call the Artisan command php artisan ninja:send-invoices

AugmentBLU commented 7 years ago

@hillelcoren thanks, wouldn't this attempt to send all invoices due for that day again - is there anyway to single out the newly created invoice if so?

hillelcoren commented 7 years ago

The app won't send any of the invoices twice.

Note: calling the send reminders command would send duplicate emails.

AugmentBLU commented 7 years ago

Great, makes sense.

If I'm using the SDK on a different server from the Invoice Ninja install, what would be the recommended method to call the Artisan command? Or would it be best to run a scheduler on the Invoice Ninja server every few minutes?

hillelcoren commented 7 years ago

Having it run regularly is probably the easiest solution

AugmentBLU commented 7 years ago

I guess this works to some degree. I wanted to forward the person straight to the payment page after registration but this won't work due to the invoice not being created during the registration process.

hillelcoren commented 7 years ago

Maybe you could use buy now buttons instead?

AugmentBLU commented 7 years ago

I've just been looking at the Buy Now feature, it seems that it creates records in the DB even if the user leaves the page before paying. Won't that get messy having records left behind when a user decides not to pay or returns? I just noticed it's also creating empty client accounts when arriving on the pay page.

Also, if I have a registration form on my site and use the buy now link as a redirect, I have already ran the SDK client create but when they arrive on the pay page, it's asking for their details again. Is there any way for it to pull in the data that's been used to create the client already?

hillelcoren commented 7 years ago

That's correct, the SDK would probably be a better choice.

If you want to try modifying the code you may be able to get this working by copying this code

https://github.com/invoiceninja/invoiceninja/blob/master/app/Http/Controllers/OnlinePaymentController.php#L365

To here:

https://github.com/invoiceninja/invoiceninja/blob/master/app/Http/Controllers/InvoiceApiController.php#L187

AugmentBLU commented 7 years ago

Great, I'll give this a shot tomorrow.

Hopefully I can get this all working as expected and it will be the second license I'll be purchasing from you.

AugmentBLU commented 7 years ago

In case anyone else comes across this idea... it works quite well with what you last posted.

Cheers!