pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
34 stars 14 forks source link

Gravity Forms `add_subscription_payment` payment action only for follow-up payments? #239

Closed remcotolsma closed 2 years ago

remcotolsma commented 2 years ago

Currently we only execute the add_subscription_payment payment action for subscription follow-up payments (not the first payment).

https://github.com/wp-premium/gravityforms/search?q=add_subscription_payment

Is this behaviour correct or is a first subscription payment also a subscription payment and should we also execute the add_subscription_payment action?

https://github.com/wp-premium/gravityforms/blob/a9c8f2de051e016e096069210ecd5fb8f5a19801/includes/addon/class-gf-payment-addon.php#L2052-L2123

remcotolsma commented 2 years ago

The Gravity Forms PayPal Add-On triggers the add_subscription_payment action when it receives an subscr_payment transaction type IPN request.

https://github.com/wp-premium/gravityformspaypal/blob/71a188b80505d7205e50e7b276b224213851b5da/class-gf-paypal.php#L1302-L1318

I don't know if PayPal sends a subscr_payment transaction type IPN request for the first payment that triggered the creation of the PayPal subscription.

In the Gravity Forms Stripe Add-On i think they check on the first payment:

                // If it's the first invoice and payment_status is active, it means the subscription has just started
                // when checkout session completed. So don't set action to prevent duplicate notes.
                $number = explode( '-', rgars( $event, 'data/object/number' ) );
                if ( $this->is_stripe_checkout_enabled() && rgar( $entry, 'payment_status' ) === 'Active' && $number[1] === '0001' ) {
                    $action['abort_callback'] = true;
                } else {
                    $payment_intent           = rgars( $event, 'data/object/payment_intent' );
                    $action['transaction_id'] = empty( $payment_intent ) ? rgars( $event, 'data/object/charge' ) : $payment_intent;
                    $action['entry_id']       = $entry_id;
                    $action['type']           = 'add_subscription_payment';
                    $action['amount']         = $this->get_amount_import( rgars( $event, 'data/object/amount_due' ), $entry['currency'] );

                    $action['note'] = '';
rvdsteege commented 2 years ago

My main concern always is about sending a different welcome notification for the first payment, but the create_subscription event can already be used for this notification.

I don't think it is strange to call the add_subscription_payment event for the first payment. However, it might be a surprising change for some users, as the first payment will not result in a notifications anymore if only the complete_payment event has been set.

remcotolsma commented 2 years ago

Updated in https://github.com/wp-pay-extensions/gravityforms/commit/cc65bdcb9506fdafebc7d111929808f304d206b4.