Tom S. Posted December 6, 2017 Posted December 6, 2017 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?
bfarber Posted December 6, 2017 Posted December 6, 2017 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.
Tom S. Posted April 27, 2018 Author Posted April 27, 2018 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?
HeadStand Posted April 27, 2018 Posted April 27, 2018 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.
Tom S. Posted April 27, 2018 Author Posted April 27, 2018 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?
HeadStand Posted April 27, 2018 Posted April 27, 2018 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 );
SJ77 Posted April 27, 2018 Posted April 27, 2018 @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.
Ilya Hoilik Posted April 27, 2018 Posted April 27, 2018 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"?
Adriano Faria Posted April 27, 2018 Posted April 27, 2018 @SJ77 and @Ilya Hoilik. Tks for the plugin mention, @SJ77 but to correct it: this plugin do not generate a new invoice. It actually adds a new purchase, WITHOUT purchase the file (so, without invoice) in Downloads. ?
SJ77 Posted April 27, 2018 Posted April 27, 2018 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
Recommended Posts
Archived
This topic is now archived and is closed to further replies.