pronamic / wp-pronamic-pay-gravityforms

Gravity Forms driver for the WordPress payment processing library.
http://www.wp-pay.org/extensions/gravityforms/
10 stars 4 forks source link

Add support for "GP Unique ID" (`gp-unique-id`) plugin (perk) #38

Open remcotolsma opened 10 months ago

remcotolsma commented 10 months ago

If I search for "GP Unique ID" within our support system, I get 21 results. Should we consider adding support for the "GP Unique ID" plugin (perk)? Now sometimes we throw the following gist over the fence: https://gist.github.com/rvdsteege/6b0afe10f81b1bc99d335ff484206fa9. According to the FAQ at https://gravitywiz.com/documentation/gravity-forms-unique-id/#can-unique-id-generation-be-delayed-until-after-payment-is-approved I would expect it to be already should work.

Can Unique ID generation be delayed until after payment is approved?

If your form uses a first-party payment add-on (or a third-party payment add-on compatible with the Gravity Forms Payment Add-On Framework) then the unique ID can be generated once payment has been captured. This delay is enabled via the gpui_wait_for_payment filter.

Based on this FAQ you get the impression that it should work automatically, or should a programmer still hook into the gpui_wait_for_payment filter with custom code? A user of the Pronamic Pay plugin may inquire with Gravity Wiz how this works, see following ticket:

Internal HelpScout ticket: https://secure.helpscout.net/conversation/2457184606/26664/

I did see that the "GP Unique ID" plugin is equipped with specific code for the Gravity Forms PayPal add-on: https://github.com/pronamic/gp-unique-id/blob/main/includes/class-gf-field-unique-id.php#L43-L45

The "GP Unique ID" plugin also doesn't seem to work with Gravity Forms feeds, but with a "Unique ID" field, which is probably why it doesn't work as I would expect.


localhost_8888_wp-admin_admin php_page=gf_edit_forms id=1


localhost_8888_wp-admin_admin-php_page-gf_edit_forms-view-settings-subview-pronamic_pay-id-1-fid-0

CC @rvdsteege

rvdsteege commented 10 months ago

Hmm, the faq seems a bit unclear indeed. Sounds like gpui_wait_for_payment always needs to be used to make GP Unique ID "wait for payment".

We've had contact with @spivurno in the past (2020) regarding compatibility between Pronamic Pay and GP Unique ID and have added the pronamic_pay_gravityforms_delay_actions filter back then. In response we received:

Amazing! I'll dig in this week. Thanks for the follow-up!

…but I'm not sure if this has ever been implemented within GP Unique ID. It's a pity that GP Unique ID cannot work with the delayed payment support:

https://github.com/pronamic/wp-pronamic-pay-gravityforms/blob/c4cf3034c429d5cbe8a825835ecde7e01d230048/src/Extension.php#L1496-L1518

Would be nice if we don't have to mention the Gist anymore in the future!

Internal Help Scout ticket: https://secure.helpscout.net/conversation/1149426959/19687

kjtolsma commented 10 months ago

Solution from Gravity Wiz:

add_action( 'gform_ideal_fulfillment', function( $entry ) {
    $form = GFAPI::get_form( $entry['form_id'] );

    foreach ( $form['fields'] as $field ) {
        if ( $field->get_input_type() != 'uid' ) {
            continue;
        }

        $value = gp_unique_id()->get_unique( $form['id'], $field, 5, array(), $entry, false ); // last param as false to trigger Unique ID generation even for spam entries

        $entry[ $field['id'] ] = $value;

        GFAPI::update_entry( $entry );
    }
}, 9 );

Internal Help Scout ticket: https://secure.helpscout.net/conversation/1149426959/19687