When your website means business.

eCommerce, Forms, WP/CP | Type: PHPGravity Forms: Setting Payments Number before Termination of Subscription

Below is a variation from the code found at the reference link, to accommodate different numbers of payments for different feeds (provided by Richard Wawrzyniak, Gravity Forms Support Engineer). Putting either in WP functions is necessary because Stripe does not currently have a mechanism in their API to define number of subscription payments.

add_action( 'gform_post_add_subscription_payment', function ( $entry ) {
    if ( rgar( $entry, 'payment_status' ) == 'Active' ) {
        $feed       = gf_stripe()->get_payment_feed( $entry );
        $feed_name  = rgars( $feed, 'meta/feedName' );
        $feed_names = array( 'Mentorship Payment Plan' => 3 ); // update this line to add subscriptions and cancellation numbers ( , 'next feed name' => 12)
 
        if ( in_array( $feed_name, $feed_names ) ) {
            global $wpdb;
            $count = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$wpdb->prefix}gf_addon_payment_transaction WHERE lead_id=%d", $entry['id'] ) );
 
            if ( $count == $feed_names[ $feed_name ] ) {
                $result = gf_stripe()->cancel( $entry, $feed );
                gf_stripe()->log_debug( "gform_post_add_subscription_payment: Cancelling subscription (feed #{$feed['id']} - {$feed_name}) for entry #{$entry['id']}. Result: " . print_r( $result, 1 ) );
            }
        }
    }
} );

Reference Links

Menu
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Cookies Notice