Jump to content

Properly create transaction/invoice without custom gateway.


maxkunes

Recommended Posts

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

 

Link to comment
Share on other sites

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?

7Zu59kW.png

Link to comment
Share on other sites

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. 

 

RXpCuPN.png

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

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.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...