Skip to content
Browse files

refactors voids to update an existing transaction instead of creating…

… a new transaction.
  • Loading branch information...
1 parent 7590d60 commit 97ab77a81ff134475034c86244b41970db470e75 @robertjwhitney robertjwhitney committed
Showing with 10 additions and 4 deletions.
  1. +7 −3 lib/fake_braintree/sinatra_app.rb
  2. +3 −1 spec/fake_braintree/transaction_spec.rb
View
10 lib/fake_braintree/sinatra_app.rb
@@ -138,11 +138,15 @@ def hash_from_request_body_with_key(request, key)
gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
end
+
# Braintree::Transaction.void
put "/merchants/:merchant_id/transactions/:transaction_id/void" do
- transaction_id = md5("#{params[:merchant_id]}#{Time.now.to_f}")
- transaction_response = {"id" => transaction_id, "type" => "sale"}
- FakeBraintree.registry.transactions[transaction_id] = transaction_response
+ transaction = FakeBraintree.registry.transactions[params[:transaction_id]]
+ transaction_response = {"id" => transaction["id"],
+ "type" => transaction["sale"],
+ "amount" => transaction["amount"],
+ "status" => Braintree::Transaction::Status::Voided}
+ FakeBraintree.registry.transactions[transaction['id']] = transaction_response
gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
end
View
4 spec/fake_braintree/transaction_spec.rb
@@ -30,8 +30,10 @@
describe FakeBraintree::SinatraApp do
context "Braintree::Transaction.void" do
it "successfully voids a transaction" do
- result = Braintree::Transaction.void(create_id('foobar'))
+ sale = Braintree::Transaction.sale(:payment_method_token => cc_token, :amount => 10.00)
+ result = Braintree::Transaction.void(sale.transaction.id)
result.should be_success
+ result.transaction.status.should == Braintree::Transaction::Status::Voided
end
end
end

0 comments on commit 97ab77a

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