Permalink
Browse files

adds ability to fake refunds

  • Loading branch information...
1 parent 63391a8 commit d2d038d0e7e64da3247aea323b32971b5f1bc1e8 Robert Whitney committed with mike-burns Sep 3, 2012
Showing with 33 additions and 0 deletions.
  1. +14 −0 lib/fake_braintree/sinatra_app.rb
  2. +18 −0 spec/fake_braintree/transaction_spec.rb
  3. +1 −0 spec/spec_helper.rb
@@ -129,6 +129,20 @@ def hash_from_request_body_with_key(request, key)
end
end
+ # Braintree::Transaction.refund
+ # Braintree::CreditCard.refund
+ post "/merchants/:merchant_id/transactions/:transaction_id/refund" do
+ if FakeBraintree.decline_all_cards?
+ gzipped_response(422, FakeBraintree.create_failure.to_xml(:root => 'api_error_response'))
+ else
+ transaction = hash_from_request_body_with_key(request, "transaction")
+ transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
+ transaction_response = {"id" => transaction_id, "amount" => transaction["amount"], "type" => "credit"}
+ FakeBraintree.registry.transactions[transaction_id] = transaction_response
+ gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
+ end
+ end
+
# Braintree::TransparentRedirect.url
post "/merchants/:merchant_id/transparent_redirect_requests" do
if params[:tr_data]
@@ -19,6 +19,24 @@
end
describe FakeBraintree::SinatraApp do
+ context "Braintree::Transaction.refund" do
+ it "successfully refunds a transaction" do
+ result = Braintree::Transaction.refund(create_id('foobar'), '1')
+ result.should be_success
+ end
+
+ context "when all cards are declined" do
+ before { FakeBraintree.decline_all_cards! }
+
+ it "fails" do
+ result = Braintree::Transaction.refund(create_id('foobar'), '1')
+ result.should_not be_success
+ end
+ end
+ end
+end
+
+describe FakeBraintree::SinatraApp do
context "Braintree::Transaction.find" do
it "can find a created sale" do
id = create_transaction.id
View
@@ -23,6 +23,7 @@ def clear_braintree_log
config.include BraintreeHelpers
config.include CustomerHelpers
config.include SubscriptionHelpers
+ config.include FakeBraintree::Helpers
config.before do
FakeBraintree.clear!

0 comments on commit d2d038d

Please sign in to comment.