Skip to content

Commit

Permalink
Add basic support for adding discounts to subscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
r00k committed Dec 14, 2011
1 parent 312cfac commit 757c0aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Currently in alpha (i.e. it does not support every Braintree call).

### Customer
* `Braintree::Customer.find`
* `Braintree::Customer.create`
* `Braintree::Customer.create` (including adding add-ons and discounts)
* `Braintree::Customer.update`
* `Braintree::Customer.delete`

Expand Down
10 changes: 9 additions & 1 deletion lib/fake_braintree/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def subscription_hash
subscription_hash["id"] ||= subscription_id
subscription_hash["transactions"] = []
subscription_hash["add_ons"] = added_add_ons
subscription_hash["discounts"] = []
subscription_hash["discounts"] = added_discounts
subscription_hash["plan_id"] = @subscription_hash["plan_id"]
subscription_hash["next_billing_date"] = braintree_formatted_date(1.month.from_now)
subscription_hash["payment_method_token"] = @subscription_hash["payment_method_token"]
Expand Down Expand Up @@ -60,5 +60,13 @@ def added_add_ons
[]
end
end

def added_discounts
if @subscription_hash["discounts"] && @subscription_hash["discounts"]["add"]
@subscription_hash["discounts"]["add"].map { |discount| { "id" => discount["inherited_from_id"] } }
else
[]
end
end
end
end
9 changes: 9 additions & 0 deletions spec/fake_braintree/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
add_ons.size.should == 1
add_ons.first.id.should == add_on_id
end

it "returns discounts added with the subscription" do
discount_id = "def456"
subscription_id = create_subscription(:discounts => { :add => [{ :inherited_from_id => discount_id, :amount => BigDecimal.new("15.00") }]}).subscription.id
subscription = Braintree::Subscription.find(subscription_id)
discounts = subscription.discounts
discounts.size.should == 1
discounts.first.id.should == discount_id
end
end

describe "Braintree::Subscription.update" do
Expand Down

0 comments on commit 757c0aa

Please sign in to comment.