gform_stripe_customer_id

gform_stripe_customer_id

DescriptionUsageParametersExamples1. ID from user meta2. Create new customerPlacementSinceSource Code

Description
The gform_stripe_customer_id filter can be used to specify an existing customer ID to be used when processing the submission.
Usage
The hook which would run for all Stripe feeds can be used like so:
add_filter( 'gform_stripe_customer_id', 'your_function_name', 10, 4 );

Parameters

$customer_id string
The Stripe customer id. Defaults to an empty string causing a new customer to be created when processing the subscription feed.

$feed Feed Object
The Feed which is currently being processed.

$entry Entry Object
The Entry which is currently being processed.

$form Form Object
The Form which is currently being processed.

Examples
1. ID from user meta
The following example shows how, if the user is logged in, you can retrieve the customer id from the user meta. See the gform_stripe_customer_after_create hook for an example showing how the customer id can be saved to the user meta.
add_filter( 'gform_stripe_customer_id', 'get_stripe_customer_id' );
function get_stripe_customer_id( $customer_id ) {
if ( is_user_logged_in () ) {
$customer_id = get_user_meta( get_current_user_id(), '_stripe_customer_id', true );
}

return $customer_id;
}

2. Create new customer
See the Stripe API documentation for creating a customer for the supported parameters.
add_filter( 'gform_stripe_customer_id', 'create_stripe_customer', 10, 4 );
function create_stripe_customer( $customer_id, $feed, $entry, $form ) {
if ( empty( $customer_id ) ) {
$customer_params = array();

if ( rgars( $feed, 'meta/transactionType' ) === 'subscription' ) {
$customer_params['email'] = gf_stripe()->get_field_value( $form, $entry, rgar( $feed['meta'], 'customerInformation_email' ) );
} else {
$email_field = rgars( $feed, 'meta/receipt_field' );
if ( ! empty( $email_field ) && strtolower( $email_field ) !== 'do not send receipt' ) {
$customer_params['email'] = gf_stripe()->get_field_value( $form, $entry, $email_field );
}
}

$customer = gf_stripe()->create_customer( $customer_params, $feed, $entry, $form );
$customer_id = $customer->id;
gf_stripe()->log_debug( 'gform_stripe_customer_id: Returning Customer ID: ' . $customer_id );
}

return $customer_id;
}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This hook was added in Stripe version 2.1.
Source Code
$customer_id = apply_filters( 'gform_stripe_customer_id', $customer_id, $feed, $entry, $form );

This hook is located in GFStripe::get_customer() in class-gf-stripe.php.

gform_stripe_customer_after_create

gform_stripe_customer_after_create

DescriptionUsageParametersExamples1. Create invoice item2. Save the customer id3. Update Stripe.com customer dataPlacementSinceSource Code

Description
The gform_stripe_customer_after_create hook can be used to perform custom actions between the customer being created and subscribed to the plan.
Usage
The hook which would run for all 『subscription』 type Stripe feeds can be used like so:
add_action( 'gform_stripe_customer_after_create', 'your_function_name', 10, 4 );

Parameters

$customer Stripe Customer Object
The Stripe Customer Object containing the customer properties.

$feed Feed Object
The Feed which is currently being processed.

$entry Entry Object
The Entry which is currently being processed.

$form Form Object
The Form which is currently being processed.

Examples
1. Create invoice item
The following example shows how you can add a charge to the customers upcoming invoice. See the Stripe API Reference for more details. Note: This can』t be done with Stripe Checkout as payment collection method.
add_action( 'gform_stripe_customer_after_create', 'add_invoice_item', 10, 4 );
function add_invoice_item( $customer, $feed, $entry, $form ) {

$feed_name = rgars( $feed, 'meta/feedName' );

if ( $feed_name != 'feed name goes here' ) { // Update this line to your feed name
return;
}

// get the currency code for this entry.
$currency = rgar( $entry, 'currency' );

// get the amount from a Number field set to currency with id 5 and convert it to the smallest unit required by Stripe for the currency being used.
$amount = gf_stripe()->get_amount_export( rgar( $entry, '5' ), $currency ); // Update 5 to your field id

$item = array(
'amount' => $amount,
'currency' => $currency,
'description' => 'Some fee', // Update this to put your description for the charge
);

gf_stripe()->log_debug( 'gform_stripe_customer_after_create: Invoice item to be added => ' . print_r( $item, 1 ) );

$result = $customer->addInvoiceItem( $item );

gf_stripe()->log_debug( 'gform_stripe_customer_after_create: Result => ' . print_r( $result, 1 ) );

}

2. Save the customer id
The following example shows how, if the user is logged in, you can save the customer id in the user meta.
add_action( 'gform_stripe_customer_after_create', 'save_stripe_customer_id' );
function save_stripe_customer_id( $customer ) {
if ( is_user_logged_in () ) {
update_user_meta( get_current_user_id(), '_stripe_customer_id', $customer->id );
}
}

3. Update Stripe.com customer data
The following example shows how to update the 『name』 in the Stripe.com customer data taking as source the values in a name field of your form. You can find additional parameters in the Stripe API Reference.
add_action( 'gform_stripe_customer_after_create', 'update_customer_data', 10, 4 );
function update_customer_data( $customer, $feed, $entry, $form ) {

// Run only for form id 3
if ( $form['id'] != 3 ) {
return;
}

gf_stripe()->log_debug( __METHOD__ . '(): Running' );

// First Name and Last Name from field id 1 joined into one string
$name = rgar( $entry, '1.3' ) . ' ' . rgar( $entry, '1.6' );

// Array containing the data you want to update
$customer_data = array(
'name' => $name,
'address' => array(
'line1' => gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_line1' ) ),
'line2' => gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_line2' ) ),
'city' => gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_city' ) ),
'state' => gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_state' ) ),
'postal_code' => gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_zip' ) ),
),
);

$country = gf_stripe()->get_field_value( $form, $entry, rgars( $feed, 'meta/billingInformation_address_country' ) );
if ( ! empty( $country ) ) {
$code = GF_Fields::get( 'address' )->get_country_code( $country );
if ( ! empty( $code ) ) {
$customer_data['address']['country'] = $code;
}
}

$result = $customer->update( $customer->id, $customer_data );

gf_stripe()->log_debug( __METHOD__ . '(): Result => ' . print_r( $result, 1 ) );

}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This hook was added in Stripe version 2.0.1.
Source Code
do_action( 'gform_stripe_customer_after_create', $customer, $feed, $entry, $form );

This hook is located in GFStripe::create_customer() in class-gf-stripe.php.

gform_stripe_connect_enabled

gform_stripe_connect_enabled

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Allows the disabling of Stripe Connect in order to use the legacy Stripe API key connection method.
Note: When the filter is set, users will need to disconnect from Stripe first in order to see the input fields.
Usage
add_filter( 'gform_stripe_connect_enabled', '__return_false' );

Parameters

$stripe_connect_enabled boolean
Set to True by default on new installations. When set to False, the legacy Stripe setting screen will be shown instead of the recommended Stripe Connect settings screen.

Example
add_filter( 'gform_stripe_connect_enabled', '__return_false' );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe version 2.8.
Source Code
This filter is located in gravityformsstripe/class-gf-stripe.php.

gform_stripe_checkout_options

gform_stripe_checkout_options

DescriptionUsageParametersExamplePlacementSinceSource Code

This filter was removed in version 3.0 of the Stripe add-on. For versions 3.0 or greater, you』ll want to use the gform_stripe_session_data filter.

Description
The 「gform_stripe_checkout_options」 JavaScript based filter in the Gravity Forms Stripe add-on allows for altering the checkout options just before the Stripe checkout modal is loaded. This filter can only be used if you』re using the Stripe Checkout payment method in your Stripe add-on settings.
Usage
The following would apply to all forms:
gform.addFilter( 'gform_stripe_checkout_options', function( options, formId ) {
return options;
} );

Parameters

$options object
The Stripe Checkout options to be filtered.

$formId int
The form id.

Example
The following would dynamically populate the email field in the Stripe Checkout modal with the value entered into an email field. In the snippet below change the number 8 in {:8} to be the field ID of an email field on your form.
gform.addFilter( 'gform_stripe_checkout_options', function( options, formId ) {
options.email = GFMergeTag.replaceMergeTags( formId, '{:8}' );
return options;
} );

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Since
This filter was added in Stripe 2.6 and removed in Stripe 3.0
Source Code
This filter is located in js/frontend.js

gform_stripe_charge_pre_create

gform_stripe_charge_pre_create

DescriptionUsageParametersExamples1. Add the statement_descriptor property2. Attach payment method to the customerPlacementSinceSource Code

Note: As of Stripe version 3.0 this filter is not available for use with the Stripe Checkout payment collection method. Use the gform_stripe_session_data filter instead if using Stripe Checkout.

Description

The gform_stripe_charge_pre_create filter allows the charge properties to be overridden before the charge is created by the Stripe API. This filter should not be used to override the $charge_meta[『metadata』] property.

Note: This filter is applicable only to Products and Services feeds.

Usage

The hook which would run for all Stripe product and service feeds can be used like so:

add_filter( 'gform_stripe_charge_pre_create', 'your_function_name', 10, 5 );

Parameters

$charge_meta arrayThe properties for the charge to be created.
$feed Feed Object
The feed object currently being processed.

$submission_data Submission Data
Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons.

$form Form Object
The Form which is currently being processed.

$entry Entry Object
The entry from which the subscription was created.

Examples

1. Add the statement_descriptor property

The following example shows how you can add the statement_descriptor property to the charge meta.

add_filter( 'gform_stripe_charge_pre_create', 'stripe_charge_pre_create', 10, 5 );
function stripe_charge_pre_create( $charge_meta, $feed, $submission_data, $form, $entry ) {
$charge_meta['statement_descriptor'] = 'STATEMENTDESC';

return $charge_meta;
}

2. Attach payment method to the customer

The following example shows how you can tell Stripe.com to attach the payment method to the customer for forms using the Stripe Card field.

add_filter( 'gform_stripe_charge_pre_create', 'stripe_save_card', 10, 5 );
function stripe_save_card( $charge_meta, $feed, $submission_data, $form, $entry ) {
$charge_meta['setup_future_usage'] = 'off_session';
return $charge_meta;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme.

Since

This hook was added in Stripe version 2.2.2.

Source Code

$charge_meta = apply_filters( 'gform_stripe_charge_pre_create', $charge_meta, $feed, $submission_data, $form, $entry );

This hook is located in GFStripe::authorize_product() in class-gf-stripe.php.

gform_stripe_charge_description

gform_stripe_charge_description

DescriptionUsageParametersExamples1. Remove the entry ID2. Include a field value3. Override the default description completelyPlacementSource Code

Description

This filter can be used to modify the charge description before it is sent to Stripe.

Usage

The filter which would run for all 『product and services』 type Stripe feeds can be used like so:

add_filter( 'gform_stripe_charge_description', 'your_function_name', 10, 5 );

Parameters

$description string
The description to be modified.
$description = 'Entry ID: 123, Products: Product A, Product B, Product C';

$strings array
Contains the Entry ID and Products. This is the array which was imploded to create the description string.
$strings = array(
'entry_id' => 'Entry ID: 123',
'products' => 'Products: Product A, Product B, Product C',
);

$entry Entry Object
The Entry which is currently being processed.

$submission_data Submission Data
Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons.

$feed Feed Object
The Feed which is currently being processed. Available from v1.7.

Examples

1. Remove the entry ID

The following example shows how you can remove the entry ID from the description.

add_filter( 'gform_stripe_charge_description', 'remove_entry_id', 10, 2 );
function remove_entry_id( $description, $strings ) {
unset( $strings['entry_id'] );

return implode( ', ', $strings );
}

2. Include a field value

The following example shows how you can append the value of a form field to the description.

add_filter( 'gform_stripe_charge_description', 'append_field_value', 10, 3 );
function append_field_value( $description, $strings, $entry ) {

return $description . ', Name: ' . rgar( $entry, '1.3' ) . ' ' . rgar( $entry, '1.6' );
}

3. Override the default description completely

The following example shows how you can replace the default description with a custom text and the value of a form field (id 21). The scope of this snippet is limited to a feed with the name 『Invoice Payment via Stripe』.

add_filter( 'gform_stripe_charge_description', 'gf_replace_charge_description', 10, 5 );
function gf_replace_charge_description( $description, $strings, $entry, $submission_data, $feed ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
$feed_name = rgars( $feed, 'meta/feedName' );

// Update the following line to use your feed name.
if ( 'Invoice Payment via Stripe' != $feed_name ){
return $description;
}

GFCommon::log_debug( __METHOD__ . '(): running for feed ' . $feed_name );

// Change 21 to your field id number.
$description = 'Invoice Payment for #' . rgar( $entry, '21' );

GFCommon::log_debug( __METHOD__ . '(): Custom Description: ' . $description );
return $description;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme.

Source Code

apply_filters( 'gform_stripe_charge_description', implode( ', ', $strings ), $strings, $entry, $submission_data, $feed )

This filter is located in GFStripe::get_payment_description() in class-gf-stripe.php.

gform_stripe_charge_authorization_only

gform_stripe_charge_authorization_only

DescriptionUsageParametersExamples1. Apply to all product and service feeds2. Apply to a specific feedPlacementSinceSource Code

Description

The gform_stripe_charge_authorization_only filter allows authorization only transactions by preventing the capture request from being made after the entry has been saved.

Usage

The hook which would run for all Stripe product and service feeds can be used like so:

add_filter( 'gform_stripe_charge_authorization_only', 'your_function_name', 10, 5 );

Parameters

$authorization_only bool
Defaults to false; return true to prevent payment being captured.

$feed Feed Object
The feed object currently being processed.

$submission_data Submission Data
Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons.

$form Form Object
The Form which is currently being processed.

$entry Entry Object
The entry from which the subscription was created.

Examples

1. Apply to all product and service feeds

add_filter( 'gform_stripe_charge_authorization_only', '__return_true' );

2. Apply to a specific feed

The following example shows how you can delay the subscription cancellation for a specific feed by checking the feed name.

add_filter( 'gform_stripe_charge_authorization_only', 'stripe_charge_authorization_only', 10, 2 );
function stripe_charge_authorization_only( $authorization_only, $feed ) {
$feed_name = rgars( $feed, 'meta/feedName' );
if ( $feed_name == 'your feed name here' ) {
return true;
}

return $authorization_only;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme.

Since

This hook was added in Stripe version 2.1.

Source Code

$authorization_only = apply_filters( 'gform_stripe_charge_authorization_only', false, $feed, $submission_data, $form, $entry );

This hook is located in GFStripe::capture() in class-gf-stripe.php.

gform_stripe_cancel_url

gform_stripe_cancel_url

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Filters Stripe session』s cancel URL, which is the URL that users will be sent to after canceling the payment on Stripe.
Usage
add_filter( 'gform_stripe_cancel_url', 'your_function_name', 10, 2 );

Parameters

$url string
The URL to be filtered.

$form_id int
The ID of the form being submitted.

Example
add_filter( 'gform_stripe_cancel_url', function ( $url, $form_id ) {
return 'https/your-domain.com/page';
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe 3.0.
Source Code
This filter is located in class-gf-stripe.php.

gform_stripe_api_mode

gform_stripe_api_mode

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
The 「gform_stripe_api_mode」 filter in the Gravity Forms Stripe Add-On allows the API mode to be set to 「live」 or 「test」.
Usage
add_filter( 'gform_stripe_api_mode', 'your_function_name', 10, 1 );

Parameters

$api_mode string
The API mode.

Examples
add_filter( 'gform_stripe_api_mode', function ( $api_mode ) {
return 'live';
} );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Stripe version 2.0.
Source Code
This filter is located in GFStripe::get_api_mode() in gravityformsstripe/class-gf-stripe.php.