Hello,
I wanted to follow up on this thread, since version 3.4+, in regards to the code
referenced here: https://docs.gravityforms.com/create-customer-stripe-without-payment/ . The code example there does not push optional Metadata fields to Stripe.
As discussed in this forum thread previously, we need to include a snippet to push the metadata gathered on your website (if you define metadata fields in the Stripe feed), to Stripe.
You’ll need to include this snippet:
$metadata = gf_stripe()->get_stripe_meta_data( $feed, $entry, $form );
if ( ! empty( $metadata ) ) {
$customer_meta['metadata'] = $metadata;
}
And, below is the whole thing, incorporating the above snippet:
//Gravity Forms - Capture card without charging => GF version 3.4
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 );
}
$metadata = gf_stripe()->get_stripe_meta_data( $feed, $entry, $form );
if ( ! empty( $metadata ) ) {
$customer_meta['metadata'] = $metadata;
}
$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['save_payment_method'] = true;
}
return $charge_meta;
}, 10, 5 );
I tested this today and it looks like it works just fine. Hopefully this helps someone.
Side note: I stopped using the old style “Credit Card” field that Gravity Forms deprecated and started using the Stripe Credit Card Field (Elements, SCA-ready), it’s simplier and less redundant for the client/person doing data entry. Works fine with this setup.
Side note #2 - important: As referenced in the above Gravity forms link regarding capturing, you will need to replace “feed name goes here” in the code, with the exact feed name of your Stripe feed. For example, my feed name is: “Credit Card Authorization”. So just copy paste your feed name in the right places, looks like there’s 3 total places to do that.