Skip to content

Instantly share code, notes, and snippets.

@kro12
Last active August 29, 2015 14:13
Show Gist options
  • Save kro12/dcf4925db25175a34644 to your computer and use it in GitHub Desktop.
Save kro12/dcf4925db25175a34644 to your computer and use it in GitHub Desktop.
def set_current_plan(subscription, products)
plans = subscription[:ratePlans]
if plans.length == 1 # if only one plan then it's the active plan
current_plan = plans[0]
current_product_name = current_plan[:productName].downcase
else
current_plan = plans.select{|plan| plan[:lastChangeType].downcase == "add" } # select the plan which was added rather than removed
current_product_name = current_plan[0][:productName].downcase
end
subscription_period = plans[0][:ratePlanName].downcase
current_product = products[current_product_name.to_sym]
@current_rate_plan = current_product[:productRatePlans][subscription_period.to_sym]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment