Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add basic support for adding discounts to subscriptions.

  • Loading branch information...
commit 757c0aad2998cab4475552410c60b949fc1bcf92 1 parent 312cfac
Ben Orenstein r00k authored
2  README.md
View
@@ -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`
10 lib/fake_braintree/subscription.rb
View
@@ -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"]
@@ -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 spec/fake_braintree/subscription_spec.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.