Skip to content

Instantly share code, notes, and snippets.

@haleeben
Last active August 27, 2018 04:21
Show Gist options
  • Save haleeben/1646ca3010734c1ad2f236306e169c31 to your computer and use it in GitHub Desktop.
Save haleeben/1646ca3010734c1ad2f236306e169c31 to your computer and use it in GitHub Desktop.
Gravity Forms Stripe Addon - Add filter to be able to set the plan_id before sending to Stripe
public function get_subscription_plan_id( $feed, $payment_amount, $trial_period_days, $currency = '' ) {
$safe_feed_name = preg_replace( '/[^a-z0-9_\-]/', '', strtolower( $feed['meta']['feedName'] ) );
$safe_billing_cycle = $feed['meta']['billingCycle_length'] . $feed['meta']['billingCycle_unit'];
$safe_trial_period = $trial_period_days ? 'trial' . $trial_period_days . 'days' : '';
$safe_payment_amount = $this->get_amount_export( $payment_amount, $currency );
/*
* Only include the currency code in the plan id when the entry currency does not match the plugin currency.
* Ensures the majority of plans created before this change will continue to be used.
* https://stripe.com/docs/subscriptions/plans#working-with-local-currencies
*/
if ( ! empty( $currency ) && $currency === GFCommon::get_currency() ) {
$currency = '';
}
$plan_id = implode( '_', array_filter( array( $safe_feed_name, $feed['id'], $safe_billing_cycle, $safe_trial_period, $safe_payment_amount, $currency ) ) );
$plan_id = apply_filters( 'gf_stripe_plan_id', $plan_id );
$this->log_debug( __METHOD__ . '(): ' . $plan_id );
return $plan_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment