Using Gravity Forms ‘gform_stripe_post_include_api’ PHP action

The gform_stripe_post_include_api action in Gravity Forms allows you to perform additional actions after the Stripe API is initialized.

Usage

add_action('gform_stripe_post_include_api', 'your_function_name');

Parameters

There are no parameters for this action.

More information

See Gravity Forms Docs: gform_stripe_post_include_api

Examples

Log API Initialization

This example logs a message after the Stripe API is initialized.

function log_api_initialization() {
    GFLogging::log_message('gravityformsstripe', __METHOD__ . '(): Stripe API Initialized. Performing further actions.', 1);
}

add_action('gform_stripe_post_include_api', 'log_api_initialization');

Update Stripe API Key

This example updates the Stripe API key after the API is initialized.

function update_stripe_api_key() {
    \Stripe\Stripe::setApiKey('your_new_api_key');
}

add_action('gform_stripe_post_include_api', 'update_stripe_api_key');

Add Stripe Metadata

This example adds metadata to a Stripe customer object after the API is initialized.

function add_stripe_metadata($entry, $form) {
    $customer_id = gform_get_meta($entry['id'], 'stripe_customer_id');
    if ($customer_id) {
        $customer = \Stripe\Customer::retrieve($customer_id);
        $customer->metadata['custom_data'] = 'your_custom_data';
        $customer->save();
    }
}

add_action('gform_stripe_post_include_api', 'add_stripe_metadata', 10, 2);

Set Stripe API Version

This example sets the Stripe API version after the API is initialized.

function set_stripe_api_version() {
    \Stripe\Stripe::setApiVersion('your_desired_api_version');
}

add_action('gform_stripe_post_include_api', 'set_stripe_api_version');

Enable Stripe Logging

This example enables Stripe logging for debugging purposes after the API is initialized.

function enable_stripe_logging() {
    \Stripe\Stripe::setAppInfo(
        'Gravity Forms Stripe Add-On',
        GF_STRIPE_VERSION,
        'https://www.gravityforms.com',
        'gravityformsstripe'
    );
}

add_action('gform_stripe_post_include_api', 'enable_stripe_logging');