Created
October 21, 2020 11:26
-
-
Save zainaali/98deb748bf4f0c4a21d142e01ba10658 to your computer and use it in GitHub Desktop.
Create a Stripe Customer with Gravity Forms Stripe Product Feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'gform_stripe_customer_id', function ( $customer_id, $feed, $entry, $form ) { | |
if ( rgars( $feed, 'meta/transactionType' ) == 'product' && rgars( $feed, 'meta/feedName' ) == 'Create Customer and Payment' ) { | |
$customer_meta = array(); | |
$metadata_field = rgars( $feed, 'meta/metaData' ); | |
foreach ($metadata_field as $metadata) { | |
if ($metadata['custom_key'] == 'Email') { | |
$email_field = $metadata['value']; | |
} | |
} | |
if ( ! empty( $email_field ) ) { | |
$customer_meta['email'] = gf_stripe()->get_field_value( $form, $entry, $email_field ); | |
} | |
$customer = gf_stripe()->create_customer( $customer_meta, $feed, $entry, $form ); | |
return $customer->id; | |
} | |
return $customer_id; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment