maxkunes Posted May 7, 2018 Posted May 7, 2018 I was wondering if anyone could help me understand how to properly create a new transaction/invoice without use of a custom payment gateway. I basically want to, through php, create a transaction for a product on my site and mark it as paid. This transaction should function as normal and I guess should have a invoice and purchase for it in the database. I would like to have this transaction also function as normal as it should expire in x days. I've so far been able to create the invoice but my understanding is I have to add an item to the invoice to actually link a product in my store to it. I'm not sure what class to use from nexus\items. Edit : (I just saw this now, sorry, I should have searched first) But now I have a new issue : $package = \IPS\nexus\Package::load( 1 ); // This product id is correct $item = $package->createItemForCart( $package->price() ); $invoice->addItem( $item ); Image of issue Yes I am logged in, and the cookies confirm thatm Thanks, Max
bfarber Posted May 7, 2018 Posted May 7, 2018 The easiest way to solve that error in your custom script is to add the following after require 'init.php'; \IPS\Dispatcher\External::i();
maxkunes Posted May 7, 2018 Author Posted May 7, 2018 5 hours ago, bfarber said: The easiest way to solve that error in your custom script is to add the following after require 'init.php'; \IPS\Dispatcher\External::i(); This worked perfectly thanks! Also if anyone is wondering, this seems to work fine for me : $package = \IPS\nexus\Package::load( 1 ); $invoice = new \IPS\nexus\Invoice; $invoice->member = \IPS\Member::load(2); $invoice->currency = "USD"; $invoice->title = "Test Invoice"; $invoice->total = $package->price(); $item = $package->createItemForCart( $package->price() ); $invoice->addItem( $item ); $invoice->markPaid(); $invoice->save(); One final question : I have figured out that this honors the package (product) will give group on purchase, and that it removes the group when the invoice is cancelled. But does this honor the system that each product has regarding when it will expire? What I'm asking is will this custom invoice/purchase exprire after 30 days?
maxkunes Posted May 8, 2018 Author Posted May 8, 2018 Regarding to my previous question, this seems to not work as expected. When creating an invoice and paying it as shown above, it does not seem to honor any renewal settings set by the product. Notice the ps_expire/ps_renwals/ps_renwal_price is all 0. On a proper purchase done through the store, these would all have appropriate values. The product is set up correctly as my main site is using the store for this stuff, so I'm not making a mistake with the product configuration. Manually setting the ps_expire column seems to be sufficient, but I am still confused why this occurs in the first place.
bfarber Posted May 8, 2018 Posted May 8, 2018 You should create an instance of \IPS\nexus\Purchase\RenewalTerm and assign it to $item->renewalTerm before calling addItem()
Tom S. Posted May 8, 2018 Posted May 8, 2018 1 hour ago, bfarber said: You should create an instance of \IPS\nexus\Purchase\RenewalTerm and assign it to $item->renewalTerm before calling addItem() I was actually wondering about this.
maxkunes Posted May 8, 2018 Author Posted May 8, 2018 2 hours ago, Tom S. said: I was actually wondering about this. Yea, its not really documented anywhere. Anyways I have gotten everything to work, thanks everyone.
HeadStand Posted May 8, 2018 Posted May 8, 2018 9 hours ago, bfarber said: You should create an instance of \IPS\nexus\Purchase\RenewalTerm and assign it to $item->renewalTerm before calling addItem() I could have sworn that createItemForCart handles that....? Commerce checkout itself does not add the renewal term, it relies on that method. There has to be another issue here. Also, @maxkunes you shouldn't manually set the invoice total, it's recalculated automatically every time you add an item and save.
bfarber Posted May 8, 2018 Posted May 8, 2018 It does not. I actually pulled the above from the next method in Package.php, addItemsToCartData(), which does this: ... /* Create the item */ $item = $this->createItemForCart( new \IPS\nexus\Money( $price, $memberCurrency ) ); $item->renewalTerm = $renewalTerm; $item->quantity = $quantity; $item->details = $details; ...
HeadStand Posted May 8, 2018 Posted May 8, 2018 8 hours ago, bfarber said: It does not. I actually pulled the above from the next method in Package.php, addItemsToCartData(), which does this: ... /* Create the item */ $item = $this->createItemForCart( new \IPS\nexus\Money( $price, $memberCurrency ) ); $item->renewalTerm = $renewalTerm; $item->quantity = $quantity; $item->details = $details; ... How did I miss that? ?
Recommended Posts
Archived
This topic is now archived and is closed to further replies.