Skip to content
This repository
Browse code

Add basic support for adding discounts to subscriptions.

  • Loading branch information...
commit 757c0aad2998cab4475552410c60b949fc1bcf92 1 parent 312cfac
Ben Orenstein authored December 14, 2011
2  README.md
Source Rendered
@@ -12,7 +12,7 @@ Currently in alpha (i.e. it does not support every Braintree call).
12 12
 
13 13
 ### Customer
14 14
 * `Braintree::Customer.find`
15  
-* `Braintree::Customer.create`
  15
+* `Braintree::Customer.create` (including adding add-ons and discounts)
16 16
 * `Braintree::Customer.update`
17 17
 * `Braintree::Customer.delete`
18 18
 
10  lib/fake_braintree/subscription.rb
@@ -25,7 +25,7 @@ def subscription_hash
25 25
       subscription_hash["id"]                   ||= subscription_id
26 26
       subscription_hash["transactions"]         = []
27 27
       subscription_hash["add_ons"]              = added_add_ons
28  
-      subscription_hash["discounts"]            = []
  28
+      subscription_hash["discounts"]            = added_discounts
29 29
       subscription_hash["plan_id"]              = @subscription_hash["plan_id"]
30 30
       subscription_hash["next_billing_date"]    = braintree_formatted_date(1.month.from_now)
31 31
       subscription_hash["payment_method_token"] = @subscription_hash["payment_method_token"]
@@ -60,5 +60,13 @@ def added_add_ons
60 60
         []
61 61
       end
62 62
     end
  63
+
  64
+    def added_discounts
  65
+      if @subscription_hash["discounts"] && @subscription_hash["discounts"]["add"]
  66
+        @subscription_hash["discounts"]["add"].map { |discount| { "id" => discount["inherited_from_id"] } }
  67
+      else
  68
+        []
  69
+      end
  70
+    end
63 71
   end
64 72
 end
9  spec/fake_braintree/subscription_spec.rb
@@ -60,6 +60,15 @@
60 60
     add_ons.size.should == 1
61 61
     add_ons.first.id.should == add_on_id
62 62
   end
  63
+
  64
+  it "returns discounts added with the subscription" do
  65
+    discount_id = "def456"
  66
+    subscription_id = create_subscription(:discounts => { :add => [{ :inherited_from_id => discount_id, :amount => BigDecimal.new("15.00") }]}).subscription.id
  67
+    subscription = Braintree::Subscription.find(subscription_id)
  68
+    discounts = subscription.discounts
  69
+    discounts.size.should == 1
  70
+    discounts.first.id.should == discount_id
  71
+  end
63 72
 end
64 73
 
65 74
 describe "Braintree::Subscription.update" do

0 notes on commit 757c0aa

Please sign in to comment.
Something went wrong with that request. Please try again.