[checkout] auto delete discount codes

picdude

Joined: 2006-06-13
Posts: 176
Posted: Thu, 2009-05-07 16:14

Hello,

I offer gift certificates as prizes at the competitions which I cover. I like that these can be implimented into the Checkout module. However, they are one time use coupons. Is there a way to have the Discount Codes deleted automatically once they are used?

Thanks,
Andrew

Gallery version = 2.3 core 1.3.0
API = Core 7.54, Module 3.9, Theme 2.6, Embed 1.5
PHP version = 4.4.7 cgi
Webserver = Apache
Database = mysqlt 5.0.45-log, lock.system=flock
Toolkits = ArchiveUpload, Exif, Getid3, LinkItemToolkit, NetPBM, Thumbnail, SquareThumb, Gd
Acceleration = partial/3600, partial/3600
Operating system = Linux cgi0702.int.bizland.net 2.6.24.7 #1 SMP Wed May 14 19:55:18 PDT 2008 i686
Default theme = carbon
gettext = enabled
Locale = en_US
Browser = Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-05-07 20:14

No way unless you rewrite the code, no.

Actually there's an obvious difficulty with what you want to do (which is part of the reason it's not been implemented yet) which is that it's not entirely clear *when* a discount code has been "used". There is always the possibility of gaming the system by using two browsers to place two orders nearly simultaneously.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Thu, 2009-05-07 21:59

Thanks for the reply, Alec.

I don't really understand why it's not clear when a discount code is used. Each coupon that I donate as prizes has a unique code. That code is entered when the recipient places an order. When that coupon is applied to a CONFIRMED order, it can be deleted from the discount code database. No one else would have the code for that particular coupon, so there's no way it could be used by two different people simultaneously. If the recipient tried to pull a fast one and give the code to their friends, then it would be applied to the first order that used it, possibly cheating themselves out of the discount.

Although I don't understand it, I'll take it at your word. Guess I'll just have to be very dilligent about deleting the coupons manually as soon as they're used.

Thanks again for the feedback.
Andrew

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-05-07 22:20
Quote:
When that coupon is applied to a CONFIRMED order

It's tricky because the stage at which the coupon is *applied* is (in processing terms) a long time before the order is *confirmed*. And some orders never actually get to the confirmed stage at all - even though they're placed correctly.

The way checkout works (always has, long before I took it over) is that orders are placed in the database as soon as you get to the second (confirm) page - even if you go no further towards payment. It's not unusual to visit that page maybe five or six times before you pay for an order, each time a new order is written into the db. That's not a problem, because they get aged out eventually. But each of those five or six times includes the discount being applied. And strictly speaking, each one of those orders could go on to be paid for - there's no way for checkout to know that there isn't a browser window sitting somewhere with that particular order open, just waiting for someone to choose a payment method. Looking at it another way, Gallery doesn't get any notification if you close a browser window or navigate directly to another site, so it can't cancel that putative order record.

Taking the checkoutpaypal payment method, for example - the confirmed status is set when the customer returns to your website after paying at the paypal website. If they don't return to your website but close the browser instead then the order never makes it to 'confirmed'. That's not a disaster, because you still get the payment notification - but it means that relying on 'cofirmed' for anything significant is unreliable.

I'm not saying that you *can't* mark an discount as used, or delete it. If you're competent with writing G2 modules you could create a new module to do that in about 25 minutes, and I'll help you with the checkout-specific stuff you need to know. My judgement, however, was that there was no way to be 100% reliable about it - and therefore it was better not to saddle site owners with irate emails from customers saying that their one-time discounts had screwed up and couldn't be used, or support queries on this forum wanting to know why someone had figured out how to order 16 different orders with their supposedly-one time discounts.

ps. You'll notice that most ecommerce sites that use Paypal use a different paypal system where you firstly reserve funds on the paypal website, then you *must* return to the original site to confirm the order, at which point the site makes a callback to paypal to request the reserved funds. Because of the difficulties outlined above I actually started writing a checkoutpaypalplus module that would use this more sophisticated method, but half-way through I asked myself exactly what difficulties I was trying to solve for all the extra effort involved when in actual fact the current system had proved its reliablity and utility over many many months.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-05-07 22:29

Actually, thinking about it again, there's one glitch with deleting the discount on "confirmed" status - there's no record within the db of which discount was applied, only the description and the amount, not the internal unique reference for the discount. You could kludge something together I guess, by parsing the description field, but it wouldn't be elegant.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Fri, 2009-05-08 13:37

Hey Alec,

Thanks for that explanation. I am by no means a code writer, but I managed to understand *most* of what you were saying. Kudos to you for being able to explain it in terms that make sense even to me.

After reading this, I think the best course of action may be to have PayPal apply the discount on it's end. I haven't looked at PayPal's coupon handling system, but I know they have one. It's just a question of whether or not the codes can be set to automatically delete.

I noticed the absence of the coupon code in the admin order page and notification. It's easy enough for me to create unique descriptions, so kludging something together won't be necessary. As I mentioned, I am far, FAR, from a code writer. As such, I have a great appreciation for what you do.

Regards,
Andrew

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-05-08 16:07
Quote:
I think the best course of action may be to have PayPal apply the discount on it's end.

Unfortunately, that won't work. Checkout will reject any payment that doesn't match the amount recorded for the order, so you can't add tax or use discounts in Paypal. It's to stop people fiddling the amount paid.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Fri, 2009-05-08 21:38

Uh-oh...

If checkout won't calculate taxes and I can't add taxes in PayPal, how do you suggest I add the taxes to the orders?

This is a much more serious complication than the discount codes...

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-05-08 21:42

You have to include taxes in the up-front price. Checkout doesn't support taxes at the moment.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Fri, 2009-05-08 22:32

Hmmm.....

Unfortunately, that's not an option for me. Here in Canada we have both provincial and federal sales taxes. Orders from within my province are charged both, but orders from other parts of Canada are only charged federal. Orders from outside of Canada are not taxed at all.

I've set up my PayPal account accordingly, but is there a way to get checkout to ignore the difference in the total it receives back from PayPal and just confirm that payment has been made?

Other than that, I'm open to suggestions.

Thanks,
Andrew

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Fri, 2009-05-08 22:41
Quote:
Here in Canada we have both provincial and federal sales taxes. Orders from within my province are charged both, but orders from other parts of Canada are only charged federal. Orders from outside of Canada are not taxed at all.

... and that's just for Canada. Now try writing code to handle taxes from any one of maybe 2 dozen different jurisdictions. Did you know that in the UK there are something like 4 different rates of Value Added Tax which can be specified for any product, and which may or may not apply according to the country the order's placed from? Not to mention the reporting requirements on invoices etc. Luckily the threshold for VAT is quite high, so it doesn't apply to me!

I'll have a think about disabling the checks. I can't really recommend it though.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Fri, 2009-05-08 23:28

I can certainly appreciate the difficulties with writing code to comply with virtually global tax structures. Especially when your work is volunteered. Thank you for that! I have enough trouble wrapping my head around my own taxes.

So, how much would it cost to have you modify my checkout module to meet my needs (ie. adding my tax structure to the calculations)? I don't expect you to volunteer your services to me personally.

Also, what is the risk (why is it not recommended) with disabling the check? You mentioned that it is in place to prevent people from meddling with the amount paid, but if all they are doing in PayPal is entering a credit card number or loging in to their account, how could the tamper with it?

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2009-05-09 09:19

That security check has been there as long as checkoutpaypal has existed (I didn't write that bit) but I do remember it's actually included in Paypal's supplied sample code, so they must have included it for a reason.

If you want to (on your own head) override the check then you could edit IPN.inc line 131 to read

	    if ( true && abs((float) .......

Like I say, overriding security checks I think is always a bad idea, especially when they were put in by the paypal API designers.

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Sat, 2009-05-09 13:46

I'll have to give it some thought before disabling that check, then. I'll see if the PayPal people may have another option too.

Just to drop a note into your suggestion box, how about writing tax structure specific versions of Checkout and offering them for sale? I'm thinking $30 per considering how many people would be interested in them... I imagine the base code would remain the same and the tax calculations would be like a module within the module. Maybe it doesn't quite work that way, but if there's a reasonable way of doing it, I think it would be to your benefit.

Thanks again for all the insight and your help.
Andrew

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sat, 2009-05-09 14:02
Quote:
just to drop a note into your suggestion box, how about writing tax structure specific versions of Checkout and offering them for sale?

Interesting idea, but, it wouldn't be feasible or ethical under the GPL to "sell" checkout addons; you can do bespoke development, for a fee, of course, but you can't ask anyone who receives the code not to redistribute it for free. And I think you vastly overestimate the number of people using checkout. I think a lot of people try it and expect to get rich selling pictures but most drop out very quickly, I suspect. (Wouldn't be surprised if it was just you and me, and a couple of others, actually.)

 
picdude

Joined: 2006-06-13
Posts: 176
Posted: Sat, 2009-05-09 14:36

Really??? You're right. I would be surprised if there were so few people using it. I know that there are a lot of "amature" photographers using Gallery, but I thought there would be a lot of pros too. Especially considering that G2 is virtually limitless in the number of photos it can handle. Personally, I have about 30,000 in G2 and that's only from August 2008. Previous coverage is still in my G1 which has about 50,000. Unfortunatley, the last time I tried the "Migrate" feature, it didn't like my G1 very much and kept timing out (probably a result of the restrictions my host imposes on the server resourses... but that's another issue).

So, as I mentioned before, can you give me an estimate on how much you would charge to customize my Checkout to handle taxes? Ours is much simpler than the UK VAT you had mentioned. There are two tax levels which are location dependant. There would also be a Provincial Tax Exemption option for certain customers, but that is not too important as I only have a handful of those and I could easily refund their taxes separately.

 
sharoncollinsr

Joined: 2009-10-17
Posts: 1
Posted: Sat, 2009-10-17 03:21
alecmyers wrote:
Quote:
I think the best course of action may be to have PayPal apply the discount on it's end.

Unfortunately, that won't work. Checkout will reject any payment that doesn't match the amount recorded for the order, so you can't add tax or use discounts in Paypal. It's to stop people fiddling the amount paid.

I used this module on my website but found no such problem, could you give more details?