Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Stripe recurring payment M and Y conversion #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/includes/classes/gateways/stripe/stripe-utilities.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,30 @@ public static function get_plan($shortcode_attrs, $metadata = array())
// This gets tricky with Jason's shift of first regular to a separate charge when there's an unused trial period.
$metadata['recurring_times'] = $shortcode_attrs['rr'] && $shortcode_attrs['rrt'] ? (integer)$shortcode_attrs['rrt'] : -1;
$trial_period_days = self::per_term_2_days($shortcode_attrs['tp'], $shortcode_attrs['tt']);
$interval_days = self::per_term_2_days($shortcode_attrs['rp'], $shortcode_attrs['rt']);
$interval_term = "";
switch (strtoupper($shortcode_attrs['rt']))
{
case 'D':
$interval_term = "day";
break;
case 'W':
$interval_term = "week";
break;
case 'M':
$interval_term = "month";
break;
case 'Y':
$interval_term = "year";
break;
}
$interval_period = is_numeric($shortcode_attrs['rp'])? (integer)$shortcode_attrs['rp'] : 0;

// The access is more correct for the product's name, and will avoid duplicate products,
// but the shortcode's description is probably better in this case...
// $product_name = trim('level'$shortcode_attrs['level'].':'.$shortcode_attrs['ccaps']);
$product = self::get_product($name);

$plan_id = 's2_plan_'.md5($amount.$currency.$name.$trial_period_days.$interval_days.serialize($metadata).$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_stripe_api_statement_description']);
$plan_id = 's2_plan_'.md5($amount.$currency.$name.$trial_period_days.$interval_period.$interval_term.serialize($metadata).$GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_stripe_api_statement_description']);

try // Attempt to get an existing plan; else create a new one.
{
Expand All @@ -412,8 +428,8 @@ public static function get_plan($shortcode_attrs, $metadata = array())
'metadata' => $metadata,
'amount' => self::dollar_amount_to_cents($amount, $currency),
'currency' => $currency,
'interval' => 'day',
'interval_count' => $interval_days,
'interval' => $interval_term,
'interval_count' => $interval_period,
// This condition in the argument below moves the first regular period out of the subscription when there's an unused trial period.
// Basically, if there's an unused trial, it'll use it, it will always set a trial, even when the site owner didn't mean it.
// This trial will be "free" in the subscription (trialing...). The period is still charged, but separately.
Expand Down