This commit is contained in:
ct
2025-07-02 01:08:11 +08:00
parent 209c022f1d
commit 68a47ec916
19 changed files with 503 additions and 75 deletions

View File

@@ -37,6 +37,32 @@ public static function getPricingPageOneTime()
return $one_time;
}
public static function getSubscriptionPlanByStripePriceID($stripe_price_id)
{
$plans = self::getSubscriptions('subscription_plans', true, true);
foreach ($plans as $plan) {
if ($plan['id'] == 'free') {
continue;
}
$stripe_price_ids = self::getPlanSystemProperty($plan, 'stripe.stripe_price_ids');
if (is_array($stripe_price_ids)) {
if (isset($stripe_price_ids['month']) && in_array($stripe_price_id, $stripe_price_ids['month'])) {
return $plan;
}
if (isset($stripe_price_ids['year']) && in_array($stripe_price_id, $stripe_price_ids['year'])) {
return $plan;
}
}
}
return null;
}
public static function getPlanSystemProperty($plan, $property)
{
// Get the environment (test or prod)
@@ -50,10 +76,10 @@ public static function getPlanSystemProperty($plan, $property)
// Inject environment into the path
// stripe.product_id.month becomes system.stripe.product_id.{env}.month
array_splice($propertyParts, 2, 0, $environment);
$fullPath = 'system.'.implode('.', $propertyParts);
$fullPath = 'system.' . implode('.', $propertyParts);
} else {
// For non-stripe properties, just prepend 'system.'
$fullPath = 'system.'.$property;
$fullPath = 'system.' . $property;
}
return data_get($plan, $fullPath);