VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: seyi on December 15, 2013, 17:25:25 PM

Title: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on December 15, 2013, 17:25:25 PM
Hello,

I have noticed a bug that I first saw with Paypal Pro and now also exists with Authorize.net.

To test
- create a coupon code of type "Gift"
- select either Paypal pro or authorize.net in the front end
- in confirming your order be sure your transaction gets declined the first time

What happens:
The coupon is removed from the cart, deleted from the backend, and cannot be used again

Why does it happen:
It seems the extensions on decline are throwing away the original generated order id and creating a new one for each decline.  The coupon has already been marked as used for the initial order id and cannot be then re-added to the new order id.

Is there a reason for creating new order id's and not just using the original order id
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 15, 2013, 23:07:59 PM
Hi Seyi

I already cried like a thousand times since the days of VM1 about coupons getting deleted independently of the order status result.

Even in your forum https://awodev.com/forum/awocoupon/help-section/coupon-valid-again-when-order-cancelled

Maybe the code provided by Stan from Rupostel in this post helps you but the logic is to delete the coupon in a selected status (confirmed in our case) avoiding VM from deleting it by default.

http://forum.virtuemart.net/index.php?topic=120205.0

BTW this happens with all payments, VM just deletes the coupon ignoring the result of the transaction. Once is added gets deleted, Happens the same with credit card systems or even the standard payment methods.

Even if the transaction remains pending the coupon is lost.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on December 16, 2013, 15:42:57 PM
Thanks for the post, I will probably have to implement something like that, but that seems like a work around instead of a solution to the problem.

I do fully agree with this statement from Milbo:
Quote
When I go in a shop and use a coupont, the coupon is gone,.. when I do refund, I may get another coupon. From my point of view it is absolutly correct that a coupon is gone in the moment you have it in the cart and press "confirm checkout".

But the problem is the behavior of the payment methods deleting the order with the coupon code and creating new ones because the customer accidentally entered the wrong payment information.  I do not think they should loose the coupon code at that point, that makes no sense, to them it is the same order.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 16, 2013, 18:24:41 PM
Quote from: seyi on December 16, 2013, 15:42:57 PM
Thanks for the post, I will probably have to implement something like that, but that seems like a work around instead of a solution to the problem.

I do fully agree with this statement from Milbo:
Quote
When I go in a shop and use a coupont, the coupon is gone,.. when I do refund, I may get another coupon. From my point of view it is absolutly correct that a coupon is gone in the moment you have it in the cart and press "confirm checkout".

But the problem is the behavior of the payment methods deleting the order with the coupon code and creating new ones because the customer accidentally entered the wrong payment information.  I do not think they should loose the coupon code at that point, that makes no sense, to them it is the same order.

Well Seyi but why is that different from a customer loosing his coupon due to a slow connection or cause he accidentaly closed the window or from credit card payments.

And what for a pending order which remains in that status and never gets processed? Coupon is lost too.

I agree with you in the payment issues, makes no sense there, but for me those are just 2 examples of many other possible cases which end up showing that a coupon can't just be deleted by adding it to the cart so I can't agree with Milbo or you there.

Stan's solution saved us from hundreds of calls from customers pissed for loosing their coupon without making use of them.


Regards

Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on December 16, 2013, 19:05:46 PM
The only way to absolutely make sure a coupon does not get used more than once is to mark it used on order creation.

Take for example using a gift certificate of $100, and you have bank transfer and credit card processing on your front end.  If you allow the code to be marked on the confirm stage, a customer could
- order 1: purchase using the gift certificate with the bank transfer option (which will put the order into pending)
- order 2: purchase again with the same gift certificate using a credit card, this time the gift certificate gets marked as used.
- the customer then pays the remaining amount on order 1 using  the bank transfer option. 

Now if the admin is not paying attention, they would mark the order confirmed and again the gift certificate gets marked.  But there is no control since the order has been created and coupon used.  In this case the customer got away with $200 discount instead of $100.

To be honest it does not even have to be that complicated, you could manipulate it with 2 different open sessions.

But I understand your point, to each his own, everyone should have the option to do as they wish.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 16, 2013, 20:31:46 PM
- order 2: purchase again with the same gift certificate using a credit card, this time the gift certificate gets marked as used.

Hi Seyi, is quite more simple that it seems. Ill tell you the process in our live site.

The user can't do that cause the bank transfer order (in our case) is automatically confirmed - Therefore: cupon erased.

Thats how we play with order status and this setting.

A standard payment as cash on delivery or bank transfer can never remain pending  (we leave that just for paypal, credit card process) so the result is either confirmed by shopper or confirmed and the coupon cant be used twice.

You could say that ok, I dont want bank transfer orders to be automatically confimed, so simply use "confirmed by shopper" which I think is the default and tell the system that on "confirmed by shopper" and "confirmed" coupons get erased so theres no way they can do what you describe.

Regards
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on December 17, 2013, 03:38:09 AM
Ah I see, had not thought of that, so in effect, all orders with coupons are marked as used in the front end.

But that still does not cover a savvy user opening 2 separate cart sessions with the same coupon code, and using paypal, moves both orders to paypal (pending status) before paying for both of them.

Obviously if the admin is paying attention that can be caught, but some sites are too busy (or lazy) to notice such things.

I have no choice but to add the option to mark a coupon as used on specific order status(es) in AwoCoupon as this problem does not look like it is going anywhere.  Just feel a "gift" coupon becomes a "mostly gift" coupon.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on December 17, 2013, 12:21:09 PM
Hello
I am going to add an option for the coupon
- it will not be deleted, but just not usable again when the order is on a specific order status
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on December 17, 2013, 19:55:21 PM
Hello

So i though about that:

To set the coupon "in use" with the session id when the order is created (order status = pending)
If a second user uses the same coupon with a different session id , if the coupon is i"in use" with a different session id, while checking out, then an error message "coupon is not valid any longer" is displayed

but now about the checkout workflow, there is a problem:

case 1:
create order=> coupon in use
order status  changes: coupon is removed
OK

case 2:
create order=> coupon in use
cancel order => coupon not in use (in function function pluginUserPaymentCancel() )
OK

case 3:
create order=> coupon in use
client does not pay
order is pending the coupon stays in use
NOT OK

and this case 3 i do not really know how to solve it

Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 17, 2013, 23:52:20 PM
Hi Valérie

Thanks for looking at this.

I have just checked the problem commented by Seyi and you about the possibility that a customer uses the same coupon twice (the session ID you speak about)


I did the following:

FIREFOX: - Log in as a customer and add one gift coupon to the cart:

INTERNET EXPLORER: Log in as same customer and add the same coupon to the cart.

-----------------------------------

At this point the same coupon is applied in both orders (in theory)

FIREFOX I proceed to checkout and end up the order making use of the coupon - CORRECT (Confirmed Status: Coupon deleted)

INTERNET EXPLORER The same coupon here was added at the checkout but when I click to proceed I'm redirected to the homepage instead of completing the order.

When I go back to the cart the coupon is lost already and removed from the checkout.

-------------------

Resuming: I'm unable to checkout twice with the same coupon.


Did Stan view this possibility already in that code or is VM2 already prepared to avoid that, or just  my own configuration which prevents that.

The case is that theres no way that customers make use of the same coupon twice but you 2 are the experts, correct me if I'm wrong.

I just dont see how that is possible.


Regards
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on December 18, 2013, 03:16:21 AM
Hello lindapowers,

You confirmed the first order too quickly.  This is specifically for paypal.  You would have to put both orders in the "pending" stage, cant have one in a cart session.  With paypal, it is a matter of clicking the confirm button and being forwarded to paypal before paying for anything.  I produced it easily yesterday when testing.

But that hole will be plugged with Valérie's "in use" concept.  This might work well for Virtuemart's 1 time gift coupons since they are so simple, but would be a nightmare for AwoCoupon, way more complicated coupons.

Hi Valerie, for this:
Quote
case 3:
create order=> coupon in use
client does not pay
order is pending the coupon stays in use
NOT OK

Not really any thing you can do as there is no more human interaction triggers.  The only thing I can think of is to run a cron, and after a certain amount of time has passed, free up the coupon.

Any chance the core could be reworked to only use one order id through a full cart session not matter the errors?  Or this is just the reality?

Thanks for looking into it.

Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on December 18, 2013, 08:57:07 AM
Hello
I am doing it. Even if it not perfect, it will at least prevent somebody form using twice the coupon for 2 different orders, and will not removed the coupon when the order is created.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: Milbo on December 18, 2013, 16:03:55 PM
Seyi, please come skype to test the version, thank you.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on December 19, 2013, 11:22:31 AM
Hello
QuoteResuming: I'm unable to checkout twice with the same coupon.

QuoteYou confirmed the first order too quickly.  This is specifically for paypal.  You would have to put both orders in the "pending" stage, cant have one in a cart session.  With paypal, it is a matter of clicking the confirm button and being forwarded to paypal before paying for anything.  I produced it easily yesterday when testing.
yes exactly

So in the next version, the coupon is not deleted any longer when the order is created, but the coupon is in state "in use", and it is deleted on a specific order status (set in the config, and by default being Confirmed)
It is not any longer possible to use twice a gift coupon.
The only issue is that the checkout is "blocked" for the cart using the 2nd time the coupon, and no message is displayed. We know that issue, and we will fix it in the VM2.1. Anyway that only concerns people trying to use twice the coupon....


Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 19, 2013, 13:08:36 PM
Quote from: alatak on December 19, 2013, 11:22:31 AM
Hello
QuoteResuming: I'm unable to checkout twice with the same coupon.

QuoteYou confirmed the first order too quickly.  This is specifically for paypal.  You would have to put both orders in the "pending" stage, cant have one in a cart session.  With paypal, it is a matter of clicking the confirm button and being forwarded to paypal before paying for anything.  I produced it easily yesterday when testing.
yes exactly

So in the next version, the coupon is not deleted any longer when the order is created, but the coupon is in state "in use", and it is deleted on a specific order status (set in the config, and by default being Confirmed)
It is not any longer possible to use twice a gift coupon.
The only issue is that the checkout is "blocked" for the cart using the 2nd time the coupon, and no message is displayed. We know that issue, and we will fix it in the VM2.1. Anyway that only concerns people trying to use twice the coupon....




Blocking users trying to do that even sounds like a good thing ;)

Thanks for the work, this was really needed.

Regards
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on January 14, 2014, 23:21:57 PM
Hi Valerie,

I mentioned this on skype but it is still not addressed in the latest version.  The modifications you put in work for the most part but there is still a small problem.

In models/order.php, function _createorder, you comment out the old code and add the new coupon in session function:
   //CouponHelper::RemoveCoupon($_cart->couponCode);
  CouponHelper::setInUseCoupon($_cart->couponCode, true);

The problem is there is no trigger within function setInUseCoupon, so no way for 3rd party coupon module to run any processes on order create

I think you should add something like this at the top of function setInUseCoupon

<?php
JPluginHelper::importPlugin('vmcoupon');
$dispatcher JDispatcher::getInstance();
$returnValues $dispatcher->trigger('plgVmCouponInUse', array($code));
if(!empty($returnValues)){
foreach ($returnValues as $returnValue) {
if ($returnValue !== null  ) {
return $returnValue;
}
}
}
?>


Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on January 17, 2014, 14:04:38 PM
Hello Seyi,

I have added your code to the top of the function setInUseCoupon()
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on January 21, 2014, 18:26:56 PM
Thank you so very much.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on February 10, 2014, 14:43:43 PM
Hi Valerie,

I just looked in the latest version, 2.0.27, and I dont see the changes there.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on February 11, 2014, 10:53:34 AM
Hello Seyi,
Yes you are right. I have done only in one of our version (the one called trunk)
and the code was not in 2.0.27.
I have added it now :)
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: seyi on February 11, 2014, 17:14:36 PM
Ah great, thanks once again.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on March 24, 2014, 22:01:17 PM
seyi & alatak in 2.5.4 coupons only reapear when an order is "cancelled" so "pending" orders keep loosing coupons.

The logic that with "cancelled" status the coupon is avi again is good sadly many orders remain pending and those customers loose their coupon code.

Regards
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: alatak on April 01, 2014, 11:56:33 AM
Hello Manu

Quotecase 3:
create order=> coupon in use
client does not pay
order is pending the coupon stays in use
NOT OK

and this case 3 i do not really know how to solve it

QuoteThe logic that with "cancelled" status the coupon is avi again is good sadly many orders remain pending and those customers loose their coupon code.

We knew that the solution was not perfect.
But in that case, you can set the order manually to "cancelled" and the coupon should be released.
Title: Re: Coupon bug with Paypal Pro and Authorize.net
Post by: lindapowers on December 23, 2016, 04:46:32 AM
Hi

Several issues regarding VM coupons and 3rd party extensions.

1 - I wonder why when a gift coupon is created with a 3rd party software it doesnt appear listed in VM backend/coupons
I noticed this in a previous component we used and recently in Seyi's AwoRewards too, the coupons are default vm gift coupons, they should appear no?

The gift coupons are created correctly and they work but VM doesn't show them in the backend. Only if you manually create a coupon from that same VM page you will see it listed.

2 -We had a custom created order status where payed orders were marked as "accepted". This was set in all payments too as a replacement for "confirmed".
In VM/Shopfront "Order Status to Delete a Gift Coupon" was set to accepted.
The result was that coupons were not being deleted and could be used again and again.

After changing from our custom "accepted" to the default "confirmed" VM coupons get deleted correctly once used.

This is working fine for us now but is just to let you know.

using vm 3.0.18.6 and j 3.6.5