pronamic / wp-pronamic-pay-ninjaforms

Ninja Forms driver for the WordPress payment processing library.
http://www.wp-pay.org/extensions/ninjaforms/
2 stars 1 forks source link

Ninja Forms notification unintentionally delayed #4

Closed remcotolsma closed 2 years ago

remcotolsma commented 2 years ago

I use Pronamic Pay (7.0.2) together with Ninja Forms (3.6.7) for payment forms. When i started using this solution, the administrator emails where send even if the payment failed. But some time ago this stopped working and e-mails where only send when the payment succeeded.

After some research i’m suspecting that an update of Pronamic Pay (6.7.0) with support for delayed actions caused this change in behavior. Now there’s a toggle in Ninja Forms to choose if you want to delay this notification e-mail to be send after the payment, or not.

Great functionality! But i would like to receive an e-mail immediately after the form has submitted, even if the payment failed, so i’ve set this toggle to OFF to disable this delay.

Unfortunately e-mails are only send when the payment succeeds.

Is it possible there’s a bug in this functionality? Or maybe i’m misunderstanding how this is supposed to work?

Thanks!

Source: https://wordpress.org/support/topic/receive-ninja-form-email-even-when-the-payment-failed/

@rvdsteege

I was able to reproduce your issue and can confirm there is indeed something going wrong. The e-mail should not be delayed in your case.

I’ve found the culprit and will let you know once this has been resolved.

Source: https://wordpress.org/support/topic/receive-ninja-form-email-even-when-the-payment-failed/#post-15124596

According to @rvdsteege caused by:

https://github.com/pronamic/wp-pronamic-pay-ninjaforms/blob/1b18369f1dbdb5734483f246c1d394089acaed8e/src/PaymentGateway.php#L156

remcotolsma commented 2 years ago

I searched the Ninja Forms codebase for halt and found the following:

I could not find any information about halt on https://developer.ninjaforms.com/.

Did found the open internal Basecamp to-do "Ninja Forms » Uitgestelde notificaties", the feature was requested by a few customers.

@rvdsteege do you remember (or find out) if we copied the https://github.com/pronamic/wp-pronamic-pay-ninjaforms/commit/2e299dd4fd27913722ff2dd32b8b01ce48c64a20 implementation from something?

rvdsteege commented 2 years ago

do you remember (or find out) if we copied the 2e299dd implementation from something?

The Ninja Forms PayPal Express plugin uses the halt mechanism.

remcotolsma commented 2 years ago

do you remember (or find out) if we copied the 2e299dd implementation from something?

The Ninja Forms PayPal Express plugin uses the halt mechanism.

👍 https://github.com/pronamic/ninja-forms-paypal-express/blob/a5079486c59d925fcb9dedf23781cdac18857c7d/includes/PaymentGateway.php#L181

https://github.com/pronamic/wp-pronamic-pay-ninjaforms/blob/1b18369f1dbdb5734483f246c1d394089acaed8e/src/PaymentGateway.php#L136-L153

I don't quite understand the cookie and session code yet, they don't seem to use that in https://github.com/pronamic/ninja-forms-paypal-express/.

rvdsteege commented 2 years ago

The PayPal Express add-on also uses the halt/resume mechanism:

However, the mechanism provided by Ninja Forms to resume processing of form actions uses the current session (managed by Ninja Forms). That would mean 'order fulfilment' will only work if the user returns immediately after payment, within the current session. From experience, we know that that is not always the case and it could also be initiated by a webhook request. The PayPal Express add-on does not support PayPal IPN, so they didn't have to cope with the issue of resuming a specific session.

Therefore, we're storing the Ninja Forms session cookie to be able to restore that specific session and then resume processing of form actions:

https://github.com/pronamic/wp-pronamic-pay-ninjaforms/blob/fd562004a6d959abb4331b8b36234bc53d7bfad1/src/Extension.php#L148-L245

I agree that e.g. getting the cookie from the headers is quite ugly, but I don't think there is (or at least was) any other way to get to the same end result.