vendidero / woocommerce-germanized

Adapt WooCommerce to the German Market with Germanized for WooCommerce
https://vendidero.de/woocommerce-germanized
Other
51 stars 42 forks source link

"Pay now" link added to order confirmation emails for paid orders #150

Closed strarsis closed 2 years ago

strarsis commented 2 years ago

I just noticed that a "Pay now" link is added to the order confirmation emails - even when the order status has already been set to paid (e.g. using PayPal ExpressCheckout).

The "Pay now" button surely is very useful and can help with completing incomplete payments, etc. However, when the payment was successful and the order status is already set to "paid", it would be better to omit this "Pay now" link as it can cause confusion.

What would happen the "Pay now" links is visited for an already paid order? Would a message be shown that the order is already completely paid?

The payment gateway is the free/open Angelleye PayPal for WooCommerce plugin (https://github.com/angelleye/paypal-woocommerce; https://www.angelleye.com/product/woocommerce-paypal-plugin/) with PayPal ExpressCheckout being the payment method.

dennisnissle commented 2 years ago

even when the order status has already been set to paid

No, I guess that's not the case (at least at the time the email is being sent). The link is only being placed if WC_Order::needs_payment() returns true. See https://github.com/vendidero/woocommerce-germanized/blob/master/includes/class-wc-gzd-checkout.php#L563

What would happen the "Pay now" links is visited for an already paid order?

The pay now link links to the "pay for order" endpoint (which is provided by the Woo core) - the user will see a message placed by Woo.

You could disable the pay now link altogether via Germanized settings > emails > display or disable the link for certain payment gateways only.

Cheers

strarsis commented 2 years ago

@vendidero: Hm, it may be that the Angeleye PayPal (ExpressCheckout) payment gateway (and probably other PayPal ExpressCheckout payment gateways) are asynchronous, creating the order as unpaid and very quickly afterwards setting the order state to "paid" as the payment confirmation from PayPal comes in (maybe this part https://github.com/angelleye/paypal-woocommerce/blob/5cc4aab391ffec6fa272f1928e01a58ff0c1ad90/angelleye-includes/express-checkout/class-wc-gateway-paypal-express-request-angelleye.php#L391).

I noticed a similar issue with PDF Vouchers that are send before the payment of an order is finished. When the payment of the order failed (irrecoverably), the PDF Voucher code is made invalid again - but the customer and the voucher recipient both receive a confirmation email with the voucher including the voucher code. The voucher code doesn't work anymore - but the voucher recipient doesn't really know about this and may try that voucher code - which is invalid then.

I noticed the woocommerce_gzd_show_order_pay_now_button filter. I can use it to exclude orders to be paid by PayPal ExpressCheckout - at least if the order was just created. Such a pay now link email should be send after e.g. 20 minutes or so, so a customer can continue an abandoned order payment.

dennisnissle commented 2 years ago

Yeah, the order is being added right away (not paid yet) and updated as soon as the response comes in. That is expected behaviour.

Yes, you might use the filter or just use the options available to exclude certain gateways from the Germanized > email > display settings.

strarsis commented 2 years ago

@vendidero: Out of curiosity: Is there a flag/field for a payment gateway in WooCommerce that indicates that it is asynchronous?

And what do you think about the proposal to add an option for adding the "Pay now" link after a duration, e.g. 10 minutes (when the order wasn't cancelled)? Then the customer will get reminded about the order and can finish it - in case the customer had to abort the payment process. This would also make sense.

dennisnissle commented 2 years ago

Every automatic payment gateway is essentially async as the order is being created and later marked as paid by updating the status on a payment confirmation request. As with german regulation it is required to send the order confirmation right after clicking the submit button. That is the actual issue here - it would be better to postpone this email.

And what do you think about the proposal to add an option for adding the "Pay now" link after a duration, e.g. 10 minutes (when the order wasn't cancelled)?

It's not that easy - that would implicate sending another email. You could implement such a "payment reminder" email yourself or use a plugin for that.

strarsis commented 2 years ago

@vendidero: I see! I added an exception for the PayPal gateway. A plugin for sending a reminder is surely a good idea, I will look into that.