Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 5, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ of them (yet).

### Transaction
* `Braintree::Transaction.sale`
* `Braintree::Transaction.refund`
* `Braintree::Transaction.void`

### TransparentRedirect
* `Braintree::TransparentRedirect.url`
Expand Down
23 changes: 13 additions & 10 deletions lib/fake_braintree/sinatra_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

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
Expand Down
14 changes: 7 additions & 7 deletions spec/fake_braintree/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down