AI Verified

Name

Save Gravity Forms Stripe Payment Methods to Stripe Customers

About

<p>https://docs.gravityforms.com/gform_stripe_charge_pre_create/#h-2-attach-payment-method-to-the-customer</p> <p>https://docs.gravityforms.com/gform_stripe_payment_element_initial_payment_information/#h-1-allow-setup-future-usage-for-products-and-services</p> <p>https://docs.gravityforms.com/gform_stripe_customer_after_create/#h-2-save-the-customer-id</p> <p>https://docs.gravityforms.com/gform_stripe_customer_id/#h-1-id-from-user-meta</p>

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

Abundant-Designs

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.abundantdesigns.com

History

Last modified:

19/10/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Save Gravity Forms Stripe Payment Methods to Stripe Customers

 
                    
1// This sets setup_future_usage parameter to off_session to save the payment method on the backend
2add_filter( 'gform_stripe_charge_pre_create', function( $charge_meta, $feed, $submission_data, $form, $entry ) {
3 gf_stripe()->log_debug( __METHOD__ . '(): Adding setup_future_usage for feed ' . rgars( $feed, 'meta/feedName' ) );
4 $charge_meta['setup_future_usage'] = 'off_session';
5 
6 return $charge_meta;
7}, 10, 5 );
8 
9// This sets setup_future_usage paramater to off_session to save the payment method on the frontend
10add_filter( 'gform_stripe_payment_element_initial_payment_information', function ( $intent_information, $feed, $form ) {
11 $intent_information['setup_future_usage'] = 'off_session';
12 
13 return $intent_information;
14}, 10, 3 );
15 
16// If the user is logged in, save their Stripe Customer ID to their WordPress user account
17add_action( 'gform_stripe_customer_after_create', function ( $customer ) {
18 if ( is_user_logged_in() ) {
19 $user_id = get_current_user_id();
20 update_user_meta( $user_id, '_stripe_customer_id', $customer->id );
21 gf_stripe()->log_debug( __METHOD__ . "(): Added Stripe Customer ID {$customer->id} to WP user ID {$user_id}" );
22 }
23});
24 
25// If the user is logged in, retrieve their Stripe Customer ID from their WordPress user account
26add_filter( 'gform_stripe_customer_id', function ( $customer_id ) {
27 if ( is_user_logged_in() ) {
28 $user_id = get_current_user_id();
29 $customer_id = get_user_meta( $user_id, '_stripe_customer_id', true );
30 gf_stripe()->log_debug( __METHOD__ . "(): Retrieved Stripe Customer ID {$customer_id} from WP user ID {$user_id}" );
31 }
32 
33 return $customer_id;
34});

0

Related Snippets

Please see some snippets below related to this snippet..

General

Unverified

0

mediaPlayer

Added: 2 months ago

Last Updated: 2 months ago

Chippi Chippi SDP Interlude Softcore

General

AI Verified

2

Make upload filenames lowercase

Added: 1 year ago

Last Updated: 3 days ago

Ensures that the filenames of all uploaded files are converted to lowercase, for consistency.

General

AI Verified

1

Delete WP Automatically Generated Images (not tested and audited yet)

Added: 7 months ago

Last Updated: 1 day ago

Delete from the database the images that WP automatically generated from uploaded images

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

WooCommerce

Unverified

General

AI Verified

0

Don't Set Rank Math OpenGraph Thumbnail from Content

Added: 7 months ago

Last Updated: 7 months ago

<p>https://wordpress.org/support/topic/posts-pages-without-opengraph-thumbnail-defined-grab-random-images-from-the-page/#post-17182639</p>