Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #30 from robertjwhitney/voids_refunds

Adds ability to void transactions & removes refunds decline_all_cards context
  • Loading branch information...
commit 7590d601da96e132c035550b7f7766e517baa84f 2 parents 37ef41b + f3d3766
@gabebw gabebw authored
View
2  README.md
@@ -33,6 +33,8 @@ of them (yet).
### Transaction
* `Braintree::Transaction.sale`
+* `Braintree::Transaction.refund`
+* `Braintree::Transaction.void`
### TransparentRedirect
* `Braintree::TransparentRedirect.url`
View
23 lib/fake_braintree/sinatra_app.rb
@@ -130,17 +130,20 @@ def hash_from_request_body_with_key(request, key)
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
+ 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
+
+ # 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
+ gzipped_response(200, transaction_response.to_xml(:root => "transaction"))
end
# Braintree::TransparentRedirect.url
View
14 spec/fake_braintree/transaction_spec.rb
@@ -24,14 +24,14 @@
result = Braintree::Transaction.refund(create_id('foobar'), '1')
result.should be_success
end
+ end
+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
+describe FakeBraintree::SinatraApp do
+ context "Braintree::Transaction.void" do
+ it "successfully voids a transaction" do
+ result = Braintree::Transaction.void(create_id('foobar'))
+ result.should be_success
end
end
end

0 comments on commit 7590d60

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