Create a Stripe customer without capturing a charge

Posted on

A small but important difference between the Gravity Forms +Stripe plugin from Gravity+ vs the “official” Stripe addon by Gravity forms, is that the latter does not automatically create a Stripe customer on Products/Services charges. This means you do not have access to customer payment info, for example if your form charges a deposit and you want to be able to charge them for the balance.

There is no way to do this on single product/services charges, but what you can do is create another feed which has a delay on a trial, and then use the code below to cancel the subscription immediately after creating. Now the customer will be created in Stripe but will not actually be charged.

Thanks to this post https://www.gravityhelp.com/documentation/article/create-a-customer-in-stripe-without-capturing-payment/

// cancel a Stripe subscription, leaving the customer payment details in Stripe so they can be charged later
add_action( 'gform_post_subscription_started', function ( $entry ) {
    $stripe    = gf_stripe();
    $feed      = $stripe->get_payment_feed( $entry );
    $feed_name = rgars( $feed, 'meta/feedName' );
    if ( $feed_name == 'feed name goes here' ) { // update this line only.
        $result = $stripe->cancel( $entry, $feed );
        $stripe->log_debug( "gform_post_subscription_started: Cancelling subscription (feed #{$feed['id']} - {$feed_name}) for entry #{$entry['id']}. Result: " . print_r( $result, 1 ) );
    }
} );
Posted in Wordpress Tips, Tricks and Reusable Bits of Code.