Jump to content

Generate Invoice Programmatically


Go to solution Solved by UrDrive,

Recommended Posts

Posted (edited)

I am trying to create an Invoice with a Regular Product Purchase (No Renewal, Lifetime Purchase, No Shipping Required) when someone calls an external php script however, it is failing due to 

Quote

INSERT INTO `nexus_purchases` ( `ps_active`, `ps_start`, `ps_renewal_price`, `ps_renewal_currency`, `ps_invoice_pending`, `ps_invoice_warning_sent`, `ps_member`, `ps_name`, `ps_app`, `ps_type`, `ps_item_id`, `ps_custom_fields`, `ps_original_invoice`, `ps_tax`, `ps_extra`, `ps_show` ) VALUES ( true, 1606777260, 0, '', 0, false, 1, 'TEST DONT BUY', 'nexus', 'package', 26, '[]', NULL, 0, 'null', 1 )
IPS\Db\Exception: Column 'ps_original_invoice' cannot be null (1048)
#0 /var/www/html/community/system/Db/Db.php(948): IPS\_Db->preparedQuery('/*community::co...', Array)
#1 /var/www/html/community/system/Patterns/ActiveRecord.php(487): IPS\_Db->insert('nexus_purchases', Array)
#2 /var/www/html/community/system/Node/Model.php(2389): IPS\Patterns\_ActiveRecord->save()
#3 /var/www/html/community/applications/nexus/sources/Invoice/Invoice.php(1800): IPS\Node\_Model->save()
#4 /var/www/html/community/website/licencekeys/activate.php(16): IPS\nexus\_Invoice->markPaid()
#5 {main}

 

My Script

require $_SERVER['DOCUMENT_ROOT'] . '/community/init.php';

\IPS\Session\Front::i();
	
$member = \IPS\Member::loggedIn();

$package = \IPS\nexus\Package::load( 26 ); 

$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\Member::load( $member->member_id );
$invoice->currency = "USD";
$invoice->title = $package->title;
$invoice->total = $package->price();
$item = $package->createItemForCart( $package->price() ); 
$invoice->addItem( $item );
$invoice->markPaid();
$invoice->save();

 

Edited by UrDrive
  • Solution
Posted
1 minute ago, Sonya* said:

Try to add


$invoice->original_invoice = 0;

 

Thank you for your reply, I actually just fixed it by saving the invoice first and then marking it as paid.

 

<?php
require $_SERVER['DOCUMENT_ROOT'] . '/community/init.php';

\IPS\Session\Front::i();
	
$member = \IPS\Member::loggedIn();

$package = \IPS\nexus\Package::load( 26 ); 

$invoice = new \IPS\nexus\Invoice;
$invoice->member = \IPS\Member::load( $member->member_id );
$invoice->currency = "USD";
$invoice->title = $package->title;
$invoice->total = $package->price();
$item = $package->createItemForCart( $package->price() ); 
$invoice->addItem( $item );
$invoice->save();

$invoice->markPaid();
?>

 

  • Recently Browsing   0 members

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