Skip to content

Commit

Permalink
Introduce FakeBraintree::Subscription.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Nov 3, 2011
1 parent 2aaf85c commit e4e99f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/fake_braintree.rb
Expand Up @@ -4,6 +4,7 @@

require 'fake_braintree/helpers'
require 'fake_braintree/customer'
require 'fake_braintree/subscription'

require 'fake_braintree/sinatra_app'
require 'fake_braintree/valid_credit_cards'
Expand Down
14 changes: 4 additions & 10 deletions lib/fake_braintree/sinatra_app.rb
Expand Up @@ -66,16 +66,10 @@ def md5(content)

# Braintree::Subscription.create
post "/merchants/:merchant_id/subscriptions" do
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<subscription>\n <plan-id type=\"integer\">2</plan-id>\n <payment-method-token>b22x</payment-method-token>\n</subscription>\n"
subscription = Hash.from_xml(request.body).delete("subscription")
subscription["id"] ||= md5("#{subscription["payment_method_token"]}#{Time.now.to_f}")[0,6]
subscription["transactions"] = []
subscription["add_ons"] = []
subscription["discounts"] = []
subscription["next_billing_date"] = 1.month.from_now
subscription["status"] = Braintree::Subscription::Status::Active
FakeBraintree.subscriptions[subscription["id"]] = subscription
gzipped_response(201, subscription.to_xml(:root => 'subscription'))
response_hash = Subscription.new(request).response_hash

FakeBraintree.subscriptions[response_hash["id"]] = response_hash
gzipped_response(201, response_hash.to_xml(:root => 'subscription'))
end

# Braintree::Subscription.find
Expand Down
21 changes: 21 additions & 0 deletions lib/fake_braintree/subscription.rb
@@ -0,0 +1,21 @@
module FakeBraintree
class Subscription
include Helpers

def initialize(request)
@subscription_hash = Hash.from_xml(request.body).delete("subscription")
end

def response_hash
response_hash = {}
response_hash["id"] = md5("#{@subscription_hash["payment_method_token"]}#{Time.now.to_f}")[0,6]
response_hash["transactions"] = []
response_hash["add_ons"] = []
response_hash["discounts"] = []
response_hash["next_billing_date"] = 1.month.from_now
response_hash["status"] = Braintree::Subscription::Status::Active

response_hash
end
end
end

0 comments on commit e4e99f8

Please sign in to comment.