Gravity Forms has a Stripe add-on that connects to Stripe and allows for 1-time and recurring purchases. The functionality works great, except that for 1-time purchases, it does not create Customers in Stripe. (By comparison, it DOES create Stripe Customers for recurring purchases.).
https://docs.gravityforms.com/create-customer-stripe-without-payment/.
The issue with this bit of code is that it only allows you to create a customer. I need to both create a Customer AND charge the credit card. The code snippets are below:
add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
GFCommon::log_debug( __METHOD__ . '(): Working for feed ' . rgars( $feed, 'meta/feedName' ) );
$customer_meta = array();
$email_field = rgars( $feed, 'meta/receipt_field' );
if ( ! empty( $email_field ) && strtolower( $email_field ) !== 'do not send receipt' ) {
$customer_meta['email'] = gf_stripe()->get_field_value( $form, $entry, $email_field );
}
$customer = gf_stripe()->create_customer( $customer_meta, $feed, $entry, $form );
GFCommon::log_debug( __METHOD__ . '(): Returning Customer ID ' . $customer->id );
return $customer->id;
}
return $customer_id;
}, 10, 4 );
add_filter( 'gform_stripe_charge_authorization_only', function ( $authorization_only, $feed )
{
if ( rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
GFCommon::log_debug( __METHOD__ . '(): running for feed ' . rgars( $feed, 'meta/feedName' ) );
return true;
}
return $authorization_only;
}, 10, 2 );
add_filter( 'gform_stripe_charge_pre_create', function( $charge_meta, $feed, $submission_data, $form, $entry ) {
if ( rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
GFCommon::log_debug( __METHOD__ . '(): running for feed ' . rgars( $feed, 'meta/feedName' ) );
$charge_meta['setup_future_usage'] = 'off_session';
}
return $charge_meta;
}, 10, 5 );
You can always create the customer yourself and then provide it when creating a payment intent (or a charge). Whether Gravity supports passing in a customer I don't know. You'll have to reach our to them to ask if that is supported and how to do it.