Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds ability to void transactions & removes refunds decline_all_cards context #30

Merged
merged 3 commits into from

2 participants

@robertjwhitney

Adds ability to void transactions, and removes branch for decline_all_cards on refunds. Neither of these methods should ever return a card declined error. Also, adds methods to Readme.

@gabebw gabebw commented on the diff
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
@gabebw Admin
gabebw added a note

Why did you remove this? Both methods POST to this URL, unless I'm missing something.

I don't believe Braintree:::CreditCard has this method, does it?

https://github.com/braintree/braintree_ruby/blob/master/lib/braintree/credit_card.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gabebw gabebw merged commit 7590d60 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
@gabebw Admin
gabebw added a note

Why did you remove this? Both methods POST to this URL, unless I'm missing something.

I don't believe Braintree:::CreditCard has this method, does it?

https://github.com/braintree/braintree_ruby/blob/master/lib/braintree/credit_card.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Something went wrong with that request. Please try again.