Jump to content

How to generate invoice programmatically


Tom S.

Recommended Posts

I would like the ability to generate an invoice manually using my own script.

something along the lines of:

IPS\nexus\Invoice::generate($nexus_product_id, $currency_code, etc...)

The invoice would be for guests so it wouldn't need to be attached to a particular member. 

Is something like this possible?

Link to comment
Share on other sites

Invoices should be owned by a member.

Having said that, yes, you can generate one programatically.

$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\Member::load( Y );
...
$invoice->save();

Take a look in applications/nexus/modules/admin/payments/invoices.php step 'invoice_generate_items' for an example.

Link to comment
Share on other sites

  • 4 months later...

I'm struggling to manually create an invoice because I don't know what values to put in:

$invoice->items 

I see it comes from

$invoice->items = isset( $data['items'] ) ? json_encode( $data['items'] ) : json_encode( array() );

But I don't know what the structure of '$data['items']' should look like.

Could someone advise?

Link to comment
Share on other sites

You need to first create the item object and then add it to the invoice. If you're using a custom item, then you need to create a corresponding extension in your app (extensions/nexus/Item). Use the Developer Center to create the extension with an empty template.

Then to add your item, you would do (at minimum):

$item = new \IPS\myapp\extensions\nexus\Item\MyItem( 'item_title', new \IPS\nexus\Money( "10", "USD" ) );
$item->id = 1; // or whatever your item ID is, depending on what you're building
$invoice->addItem( $item );

There are other properties you can set in your item, but it really depends on what you're trying to do and what your needs are.

Link to comment
Share on other sites

5 minutes ago, HeadStand said:

You need to first create the item object and then add it to the invoice. If you're using a custom item, then you need to create a corresponding extension in your app (extensions/nexus/Item). Use the Developer Center to create the extension with an empty template.

Then to add your item, you would do (at minimum):


$item = new \IPS\myapp\extensions\nexus\Item\MyItem( 'item_title', new \IPS\nexus\Money( "10", "USD" ) );
$item->id = 1; // or whatever your item ID is, depending on what you're building
$invoice->addItem( $item );

There are other properties you can set in your item, but it really depends on what you're trying to do and what your needs are.

Thanks. I don't wish to create a custom item. I want to add an item that already exists in the store.

Can I create the item object for a specific existing item easily?

Link to comment
Share on other sites

22 minutes ago, Tom S. said:

Thanks. I don't wish to create a custom item. I want to add an item that already exists in the store.

Can I create the item object for a specific existing item easily?

$package = \IPS\nexus\Package::load( 1 ); // use whatever product ID you need here
$item = $package->createItemForCart( $package->price() ); // you can also use a custom price here with new \IPS\nexus\Money
$invoice->addItem( $item );

 

Link to comment
Share on other sites

30 minutes ago, SJ77 said:

@Ilya Hoilik in response to your confused face, this tool makes it very easy to generate an invoice programmatically. Placed it here for posterity if anyone searching those terms finds this thread and this becomes useful for their needs.

I really don't understand how that plugin can help topic owner "to generate an invoice manually using my own script".

Do you mean I can post links to my payment gateways in every topic where words like 'nexus', 'invoice', 'payment' and so on are present? Just because "posterity searching those terms finds this thread and this becomes useful for their needs"?

Link to comment
Share on other sites

2 hours ago, Ilya Hoilik said:

I really don't understand how that plugin can help topic owner "to generate an invoice manually using my own script".

Do you mean I can post links to my payment gateways in every topic where words like 'nexus', 'invoice', 'payment' and so on are present? Just because "posterity searching those terms finds this thread and this becomes useful for their needs"?

No I mean I’m sure sure what the end goal is of the op. This may solve the issue not sure

in retrospect I see now that I likely misread the op 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...