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.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注