Create a Customer in Stripe without Capturing Payment

Create a Customer in Stripe without Capturing Payment

You can create a customer in your Stripe.com dashboard, including their payment details, without actually charging the customer. The method you use to do this will depend on which version of the Stripe add-on you are using:

IMPORTANT: The following requires our Stripe Add-On version 3.4 or newer.
Payment method must be set to Stripe Credit Card Field.

Go to Form Settings > Stripe > Add New.Give the new feed a name and for the transaction type select Product and Services.The payment amount can be set to either the form total or a product field, it doesn』t matter which as long as the amount is greater than zero and conforms to Stripe.com minimum amount requirements, the customer won』t actually be charged.Map the Stripe Receipt setting to the form field which contains the customers email address.Add the following code snippets as usual, replacing feed name goes here with the actual name of your feed.

add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
gf_stripe()->log_debug( __METHOD__ . '(): running customer creation snippet.' );
if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
gf_stripe()->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 );
gf_stripe()->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' ) {
gf_stripe()->log_debug( __METHOD__ . '(): Authorization only 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' ) {
gf_stripe()->log_debug( __METHOD__ . '(): Adding setup_future_usage for feed ' . rgars( $feed, 'meta/feedName' ) );
$charge_meta['setup_future_usage'] = 'off_session';
}

return $charge_meta;
}, 10, 5 );

When the form is submitted and passes validation the customer will be created in your Stripe account. A charge will also be created based on how the feed is configured but it will not be captured when the entry is saved.

Please note that Stripe will automatically expire the authorized charges if not captured within seven days.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注