Skip to content

Commit

Permalink
[#69454150] removing initial payment when changing the periodicity
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Scataglini committed May 6, 2014
1 parent fdccf4d commit 97f6c28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions features/independent_payment_strategy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ Feature: Independent Payment Strategy

Examples: changing the periodicity of product A from monthly to yearly
| desired state | action |
| A @ $99/yr, B @ $20/mo | cancel [A @ $30/mo] now, add (A @ $99/yr) on 04/01/13 with initial payment set to $99.00 |
| A @ $99/yr, B @ $20/mo | cancel [A @ $30/mo] now, add (A @ $99/yr) on 04/01/12 |

Examples:
Adding a new product D,
Re-adding a cancelled product C,
Changing the periodicity of A product,
Removing product B
| desired state | action |
| A @ $60/yr, C @ $50/yr, D @ $40/yr | cancel [A @ $30/mo] now, add (A @ $60/yr) on 04/01/13 with initial payment set to $60.00, cancel [B @ $20/mo] now, add (C @ $50/yr) on 04/25/12, add (D @ $40/yr) on 03/15/12 |
| A @ $60/yr, C @ $50/yr, D @ $40/yr | cancel [A @ $30/mo] now, add (A @ $60/yr) on 04/01/12, cancel [B @ $20/mo] now, add (C @ $50/yr) on 04/25/12, add (D @ $40/yr) on 03/15/12 |

# """
# cancel A @ $30 now,
Expand Down
4 changes: 2 additions & 2 deletions lib/billing_logic/strategies/base_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def group_by_date(new_products)
elsif (previous_product = changed_product_subscription?(product))
update_product_billing_cycle_and_payment!(product, previous_product)
date = next_payment_date_from_product(product, previous_product)
puts "date #{date.inspect}"
end
date = (date.nil? || date < today) ? today : date
group[date] ||= []
Expand Down Expand Up @@ -150,14 +151,13 @@ def next_payment_date_from_profile_with_product(product, opts = {:active => fals

def update_product_billing_cycle_and_payment!(product, previous_product)
if product.billing_cycle.periodicity > previous_product.billing_cycle.periodicity
product.initial_payment = product.price
product.billing_cycle.anniversary = previous_product.billing_cycle.anniversary
end
end

def next_payment_date_from_product(product, previous_product)
if product.billing_cycle.periodicity > previous_product.billing_cycle.periodicity
product.billing_cycle.next_payment_date
product.billing_cycle.anniversary
else
product.billing_cycle.anniversary = next_payment_date_from_profile_with_product(product, :active => true)
end
Expand Down

0 comments on commit 97f6c28

Please sign in to comment.