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

Delayed actions ignore conditional logic #9

Closed remcotolsma closed 1 year ago

remcotolsma commented 1 year ago

Message from a Pronamic Pay user:

Pronamic Pay houdt geen rekening met ingestelde voorwaardes bij Ninja Forms.We willen namelijk acties uitvoeren nadat betaling is uitgevoerd, alleen nu voert hij alle acties uit die actief zijn gemarkeerd bij de acties. Terwijl er conditionele logica actief is. Zie ook log dump.

This is related to the https://ninjaforms.com/extensions/conditional-logic/ extensions → https://github.com/pronamic/ninja-forms-conditionals.

Internal HelpScout ticket: https://secure.helpscout.net/conversation/2365232621/26169?folderId=1425710

remcotolsma commented 1 year ago

It appears that this is a problem/limitation within the "Ninja Forms - Conditional Logic" plugin. The submitted data is no longer available after a successful payment and therefore the conditional logic can no longer be tested. The "Ninja Forms - Conditional Logic" plugin hooks into the ninja_forms_submit_data filter to parse the fields data. These fields data will be used later to test the conditional logic. When a payment provider notifies that the payment has been successful, there is no form submission and the ninja_forms_submit_data filter is not executed.

    public function parse_actions( $actions, $form_data )
    {
        // If we don't have a fieldsCollection (such as if this is a resume) skip this filter.
        if ( ! empty( $this->fieldsCollection ) ) {
            array_walk( $actions, array( $this, 'parse_action' ), $this->fieldsCollection );
        }

        return $actions;
    }

PS I have added some Ninja Forms extensions to the .wp-env file:

https://github.com/pronamic/wp-pronamic-pay-ninjaforms/blob/50fa9b83b9a937ce04295edc15ef360549201de7/.wp-env.json#L6-L8

CC @rvdsteege

rvdsteege commented 1 year ago

It appears that this is a problem/limitation within the "Ninja Forms - Conditional Logic" plugin.

Therefore, I think we can close this issue or do you want to reach out to the developers of the Ninja Forms - Conditional Logic plugin?

remcotolsma commented 1 year ago

Yes, I have not received a response from the customer either, let's close for now.

rvdsteege commented 7 months ago

Received update from customer today, apparently the issue in the Ninja Forms - Conditional Logic plugin has not yet been resolved. My reply:

we would like to hear from you what is needed to get the Conditional Logic working so that you can validate the logic based on submitted data and a delayed action must or must not be carried out.

Ninja Forms has functionality which they call "resume" for submissions, which allows actions to be processed at a later time than directly at the time of submit. Within Pronamic Pay, we make sure that the checked 'delayed actions' are skipped when submitting the form. As soon as the payment is successful, we call the "resume" routine to process the delayed actions which are not yet processed. The problem is that the Conditional Logic add-on does not support the "resume" functionality (they hook into a filter ninja_forms_submit_data to to set up some temporary data, which they later use to determine which actions should (not) be performed, but this filter is only called when submitting the form and not during the "resume" routine). The conditional logic you have set in the actions is therefore only applied when the form is submitted.

As my colleague Remco pointed out earlier, we do indeed see it as a limitation of the Conditional Logic add-on that they do not support this. You can send them the code below to illustrate the issue, because I think this solves it (not the most beautiful way, but I think it is the only one that works with the possibilities available for developers; I have not tested it very extensively, but the logic seemed to be applied when processing the delayed actions after successful payment).

\add_filter( 'ninja_forms_submission_actions', function( $actions, $form_cache, $form_data ) {
  apply_filters( 'ninja_forms_submit_data', $form_data );

  return $actions;
}, 1, 3 );

Internal Help Scout ticket: https://secure.helpscout.net/conversation/2539759550/27013