Jump to content

How to generate invoice programmatically


Tom S.

Recommended Posts

Posted

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?

Posted

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.

  • 4 months later...
Posted

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?

Posted

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.

Posted
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?

Posted
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 );

 

Posted

@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.

Posted
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"?

Posted
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 

Archived

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

  • Recently Browsing   0 members

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