Loading...
X

Create customer in Stripe selling not subscription

0 0

The only way to create a customer in your Stripe dashboard along with their payment details would be to use the Subscription transaction type. You can then use gform_stripe_webhook hook to cancel the subscription as soon as the first payment is made, you would then be able to manually create a payment for that customer via the Stripe dashboard.

To cancel the subscription you would use the following code snippet:

// Cancel the subscription once the payment is successful
add_filter( 'gform_stripe_webhook', 'cancel_successful_stripe_subscription', 10, 2 );
function cancel_successful_stripe_subscription( $action, $event ) {

GFCommon::log_debug( __METHOD__ . '(): Running.' );

	if ( $action['type'] == 'add_subscription_payment' ) {
		GFCommon::log_debug( __METHOD__ . '(): Action type is: ' . $action['type'] );
		$entry = GFAPI::get_entry( $action['entry_id'] );
		GFCommon::log_debug( __METHOD__ . '(): Cancelling subscription for entry #' . $entry );
		$GFstripe = new GFStripe;
		$result = $GFstripe->cancel( $entry, '' );
	}

	return $action;
}

If you have many Stripe feeds and want to use it only in one of them:

// Cancel the subscription once the payment is successful
add_filter( 'gform_stripe_webhook', 'cancel_successful_stripe_subscription', 10, 2 );
function cancel_successful_stripe_subscription( $action, $event ) {

	GFCommon::log_debug( __METHOD__ . '(): Running.' );

    if ( $action['type'] == 'add_subscription_payment' ) {
		GFCommon::log_debug( __METHOD__ . '(): Action type is: ' . $action['type'] );
		$entry    = GFAPI::get_entry( $action['entry_id'] );
		$GFStripe = gf_stripe();
		$feed     = $GFStripe->get_payment_feed( $entry );
        
        if ( rgars( $feed, 'meta/feedName' ) == 'subscription' ) {
			GFCommon::log_debug( "gform_stripe_webhook(): Feed name is a match so lets cancel the subscription." );
			GFCommon::log_debug( __METHOD__ . '(): Cancelling subscription for entry #' . $entry );
			$result = $GFStripe->cancel( $entry, null );
		}
	}

    return $action;
}

If what you’re looking for is to create a customer in your Stripe.com dashboard without charging any payment, then use the following approach instead.

2 observations on “Create customer in Stripe selling not subscription
  1. Philippe

    Hi Samuel,

    I try the code in test mode but the subscription is still active.

    Is it because there are some modifications in the code of Gravity Forms or Stripe so they can’t handle this request anymore?

    Thanks for your help!

     
    Reply

Leave Your Observation

Your email address will not be published. Required fields are marked *

Do NOT follow this link or you will be banned from the site!