Last active
August 29, 2015 14:13
-
-
Save kro12/dcf4925db25175a34644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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