Stripe - Without capture payment - Metadata

Hi,

With the intent to generate a new customer and capture their card information in Stripe…
This article: https://docs.gravityforms.com/create-customer-stripe-without-payment/ and it’s code doesn’t also appear to capture the metadata that I defined in the Stripe feed settings. I probably have 10 Metadata that do not get submitted to Stripe, (note, capturing the email address and the credit card does appear to work OK).

How can I also include other Metadata that gets submitted.
For example, here’s a couple of arbitrary Metadata fields in the Stripe feed that I made which I’d like to get over to the customer information in Stripe upon creation:

  • FirstName
  • LastName
  • EmailAddress
  • PhoneNumber
  • etc.

Thanks for your feedback.

Hi All,

Any feedback or hints?

Thanks kindly,

Hi @chrishajer - Do you have any insights or hints about this?

Thanks,

I’m guessing you need to add the specific customer meta fields manually in the $customer_meta array in the function on that page, ie:

add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
    if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
        $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_meta['custom_meta_1'] = gf_stripe()->get_field_value( $form, $entry, 'custom_meta_1' );
        $customer_meta['custom_meta_2'] = gf_stripe()->get_field_value( $form, $entry, 'custom_meta_2' );
 
        $customer = gf_stripe()->create_customer( $customer_meta, $feed, $entry, $form );
 
        return $customer->id;
    }
 
    return $customer_id;
}, 10, 4 );

I’m not familiar with Stripe / the Stripe Add-On though and I haven’t tested the code above.

@hiranthi, thanks for your feedback, but I could not make that work. However, I have found a working solution in the meantime.

I found looking at class-gf-stripe.php, that we need to move the feed metadata into the $customer_meta array, at the index [‘metadata’], if it is not empty. Like this:

 $metadata = gf_stripe()->get_stripe_meta_data( $feed, $entry, $form );
        if ( ! empty( $metadata ) ) {
                     $customer_meta['metadata'] = $metadata;
        }

The $customer_meta is part of the create_customer function which gets called on about Line #15.
So, the completed code looks like this:

add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) {
    if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'feed name goes here' ) {
        $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 );

        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' ) {
        return true;
    }

    return $authorization_only;
}, 10, 2 );

Some side notes:

From: https://docs.gravityforms.com/create-customer-stripe-without-payment/,

  1. I found that the Stripe Receipt setting noted in Step #4, must be defined to the Email address (cannot use the do not send receipt) setting, or the email address does not get also sent to Stripe.

  2. The ‘feed name goes here’, must be exactly your Stripe feed name. Spaces are OK.

2 Likes

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. :v:

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.

1 Like

This is great information. Thank you for writing that up.

1 Like

For clarification, is this basically Payment Intent transaction?
After creating the customer in Stripe it then needs to be manually processed to capture monies?

Hi Michael,

Yes. It’s used to capture various information about the customer, including their card information without charging them anything.

Then within stripe dashboard or an application, charge the said customer’s card on file, on demand.

1 Like