Zen Cart Logo
Forums / General Questions / How to detect if an order has been paid?

How to detect if an order has been paid?

Views: 1,732

Results 1 to 10 of 10
21 Jun 2014, 10:50 PM
#1
chuckles_net avatar

chuckles_net

New Zenner

Join Date:
Apr 2014
Location:
western Pennsylvania
Posts:
10
Plugin Contributions:
0

How to detect if an order has been paid?

I am selling some software that will include a 30-day free trial. I keep track of the user's first install date and after 30 days, it forces them to activate the product.

I installed Zencart and I added a Product Activation Key field to the orders_products table. I updated the orders class so that it generates the PAK and adds it to the table. I've created a PHP-based gateway for my software to check that field and confirm the PAK.

Once the order has been paid, I want my gateway to allow the customer to activate the product. I'm struggling a bit with how to tell if the order has been paid. I want to allow cash, paypal and credit card payments. What fields/tables should I check to confirm that an order has been paid, for each of these payment types?

When I take in a cash payment, it looks like I just want to go the Zencart admin screen, go to Customers->Orders and update the status drop-down. This sets the orders_status field in the orders_products table, which my software can check. Is my approach for cash correct?

Thanks!!!

22 Jun 2014, 3:39 AM
#2
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: How to detect if an order has been paid?

chuckles_net:

I am selling some software that will include a 30-day free trial. I keep track of the user's first install date and after 30 days, it forces them to activate the product.

I installed Zencart and I added a Product Activation Key field to the orders_products table. I updated the orders class so that it generates the PAK and adds it to the table. I've created a PHP-based gateway for my software to check that field and confirm the PAK.

Once the order has been paid, I want my gateway to allow the customer to activate the product. I'm struggling a bit with how to tell if the order has been paid. I want to allow cash, paypal and credit card payments. What fields/tables should I check to confirm that an order has been paid, for each of these payment types?

When I take in a cash payment, it looks like I just want to go the Zencart admin screen, go to Customers->Orders and update the status drop-down. This sets the orders_status field in the orders_products table, which my software can check. Is my approach for cash correct?

Thanks!!!

Your common field for all orders is orders_id

Transactions are recorded in the table orders_status_history and it includes the orders_status_id

Depending on what your orders_status_id is set to for a completed payment, you will need to test for that id.

Eg, my description of a fully paid and shipped order is 'Shipped / Completed' which in my case has id=3.

22 Jun 2014, 4:43 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to detect if an order has been paid?

Out-of-the-box, Zen Cart ONLY stores orders which have been approved by the payment module selected at order-time. So, if that payment module actually collects payment, then the order is paid.

However, if you've altered the code to do differently, or have configured your payment module to NOT actually take any payment, then ALL your subsequent handling of orders (including your manual collection of payment externally) must be done yourself. In that case there's no "built-in" way to magically "know" that you've collected payment externally.
So, as suggested above, you can simply use whatever order-status you want to denote that you've manually collected payment, and update those orders by hand.

22 Jun 2014, 6:11 AM
#4
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: How to detect if an order has been paid?

So, with DrByte's explanation

DrByte:

Out-of-the-box, Zen Cart ONLY stores orders which have been approved by the payment module selected at order-time. So, if that payment module actually collects payment, then the order is paid.

However, if you've altered the code to do differently, or have configured your payment module to NOT actually take any payment, then ALL your subsequent handling of orders (including your manual collection of payment externally) must be done yourself. In that case there's no "built-in" way to magically "know" that you've collected payment externally.
So, as suggested above, you can simply use whatever order-status you want to denote that you've manually collected payment, and update those orders by hand.

let's look at this scenario:

  1. customer downloads your software and installs it. After 30 days your trial software stops working and your customer is prompted to return to your site to pay $xx.xx

  2. the customer pays with any payment option they can choose from and an order with unique order_id is created.

a. the order is paid via PayPal and PayPal automatically sets the order status to 'Processing'. You can configure the PP module to set the order status to 'completed' (say the id is '3')

b. customer creates an order and makes a direct bank deposit. You check that the money is in your account and manually set the order status to '3'

c. etc

  1. After completion of a transaction the customer is prompted to enter the order id into your software (remember the order id is unique). Your software now queries your store database and checks if order id so-and-so has order status = '3'. If true the software is validated and continues to work. If false then you need to prompt the customer again with whatever you want to tell them.

  2. To do all of this you could create a script on your site which does the validation AND at the same time sets another value order_software_validated (true or false) in a newly created column in the table order_status_history to ensure that your customer does not give the order id to a friend who may want to cheat and use your software for free. So, in point 3. above the default value for order_software_validated is 'false' and is set to 'true' as validation is being executed. If a friend wants to use your software for free and enters the order id the software checks for payment status AND for order_software_validated = true / false. If 'true' is found then the friend can't use the software.

22 Jun 2014, 3:45 PM
#5
chuckles_net avatar

chuckles_net

New Zenner

Join Date:
Apr 2014
Location:
western Pennsylvania
Posts:
10
Plugin Contributions:
0

Re: How to detect if an order has been paid?

First off, thanks to everyone for the feedback! I think you are confirming what I was expecting, but let me clarify to be sure.

The reason I'm going into such detail here is that I haven't yet set up Credit Card or PayPal processing. I need to start coding, but I can't really test this stuff until I set up those payment options.

I haven't made any changes that affect the payment modules.

As DrZen says: "I won't get a Credit Card/PayPal order if the payment transaction to those entities hasn't transpired."

As Frank18 says: "Depending on what your orders_status_id is set to for a completed payment, you will need to test for that id." I haven't done anything to change what that value should be.

Looking at this statement, "the order is paid via PayPal and PayPal automatically sets the order status to 'Processing'", I read that as (for CC/PP payments), the orders_status field is set to "2" after the payment has been processed, correct?

So, here's the scenario I envision...

Customer downloads and installs my software on their PC. (Note: I don't support Macs or Androids.) My software keeps track of the 30-day expiration date and stops working after that, unless they pay.

They make the purchase on my Zencart. My custom code generates a unique Product Activation Key (PAK) and keeps it in the orders_products table.
A. If they pay by cash, the orders_products record is created with a value of "1" in the orders_status field. When I receive payment, I bump the orders_status field to a "2" and I email the PAK to the customer.
B. If they pay by CC/PP, the orders_products record is created with a value of "2" in the orders_status field and the PAK is sent to the customer as part of their order confirmation.
So from my point of view, I am using "Actiavte" where Zencart calls it "Delivered". I don't think there's any conflict there.

The customer uses screens in my software to activate their order. This changes the orders_status field to a "3" (via my gateway process). During that processing, it also collects the MAC address of the Network Interface Card (NIC)on the customer's computer and keeps that in the orders_products table. As I read on other websites, this seems to be the only unique property of a PC I can reliably get ahold of.

My software on the customer's computer sets up some things that tells it it is OK. But, it does check my gateway each time my software is invoked.
A. If the internet or my website is unavailable, it believes the settings on the comupter.
B. If the website is available, it double-checks the status against the NIC. If it sees their Email and PAK on a different NIC, it will suspend the software by setting the orders_status field to a new value I added, called "5".

To allow the customer to move my software to another computer, I have screens that allow them to "Unactivate" their copy. Doing so sets the orders_status to "4". It can then be activated on a different machine using the same email/PAK.

I am re-using the value of "4" on the orders_status field, which originally meant "Update". Should I have done this? What does the generic "Update" status really mean to Zencart. Maybe I should have made this a "6"?

The other thing to keep in mind is that my software is very special purpose, so I'm not worried about Joe Public hacking it. If he does, then I haven't really lost any revenue. My clients are, in general, not very computer-savy. If I was selling to "the world", I would probably want more security, but for now this approach should work for me.

Any thoughts? Thanks again!

22 Jun 2014, 9:38 PM
#6
chuckles_net avatar

chuckles_net

New Zenner

Join Date:
Apr 2014
Location:
western Pennsylvania
Posts:
10
Plugin Contributions:
0

Re: How to detect if an order has been paid?

Rats! I just looked again at the table layouts. The orders_status field is in the orders table, not in orders_products. If a customer buys 2 or more copies at one time, then I would get one record in orders and 2 records in orders_products, correct? If so, I think I need a status field in orders_products, so that each copy is tracked separately?

The plot thickens...

22 Jun 2014, 9:51 PM
#7
chuckles_net avatar

chuckles_net

New Zenner

Join Date:
Apr 2014
Location:
western Pennsylvania
Posts:
10
Plugin Contributions:
0

Re: How to detect if an order has been paid?

chuckles_net:

Rats! I just looked again at the table layouts. The orders_status field is in the orders table, not in orders_products. If a customer buys 2 or more copies at one time, then I would get one record in orders and 2 records in orders_products, correct? If so, I think I need a status field in orders_products, so that each copy is tracked separately?

The plot thickens...

No, I get one orders_products record, with a quantity count of 2. Unless I want to limit the number that can be ordered per session. That shouldn't be a big problem for my customers. Hhhmmm...

22 Jun 2014, 11:04 PM
#8
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: How to detect if an order has been paid?

chuckles_net:

Looking at this statement, "the order is paid via PayPal and PayPal automatically sets the order status to 'Processing'", I read that as (for CC/PP payments), the orders_status field is set to "2" after the payment has been processed, correct?

Correct - but you can set this in admin to another value

chuckles_net:

So from my point of view, I am using "Actiavte" where Zencart calls it "Delivered". I don't think there's any conflict there.

You can set this to whatever you like

chuckles_net:

I am re-using the value of "4" on the orders_status field, which originally meant "Update". Should I have done this? What does the generic "Update" status really mean to Zencart. Maybe I should have made this a "6"?

By default 'Pending' is '1' - Processing is '2' etc etc - you can change these to your liking in Admin > Localization > Orders Status. They then show up as options in the configuration pages of payment modules.

The generic "Update" status IMHO is really useless, I never use it. If I need to send an update email to the customer eg notify them of a delay in delivery then I still leave the orders status at '2' which is 'Processing'. You just need to set yourself some rules what an orders status should be set to when a certain scenario has occurred.

24 Jun 2014, 5:55 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How to detect if an order has been paid?

frank18:

The generic "Update" status IMHO is really useless, I never use it. If I need to send an update email to the customer eg notify them of a delay in delivery then I still leave the orders status at '2' which is 'Processing'. You just need to set yourself some rules what an orders status should be set to when a certain scenario has occurred.
The "Update" status is actually more specific than generic. Its primary purpose was to update the status of any expired downloadable files attached to the order. Using it for any other purpose is, as you say, relatively moot.

24 Jun 2014, 9:32 PM
#10
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: How to detect if an order has been paid?

DrByte:

....Its primary purpose was to update the status of any expired downloadable files attached to the order....

Thanks - wasn't aware of this. Learned something again!