Skip to content

Instantly share code, notes, and snippets.

@fearoffish
Created December 14, 2012 15:38
Show Gist options
  • Save fearoffish/4286319 to your computer and use it in GitHub Desktop.
Save fearoffish/4286319 to your computer and use it in GitHub Desktop.
The flow:
POST a form to braintree with customer details (our payment forms do this)
Braintree redirects to a URL we provided in the form
On this URL we ask braintree to confirm the result they give us
We create a customer
We set up the charges (different per payment plan)
The problem:
We POST the form to braintree, and a local sinatra app picks that up (from fake_braintree which has a sinatra app that emulates the braintree service)
Fake braintree redirects to the the right url
We start the confirm request...and it hangs
I modified the fake_braintree sinatra app to do some logging, to ensure requests were hitting it:
# Braintree::TransparentRedirect.url
post "/merchants/:merchant_id/transparent_redirect_requests" do
Braintree::Configuration.logger.debug "REDIRECT REQUEST: #{params}"
The log shows:
REDIRECT REQUEST: {"utf8"=>"✓", "tr_data"=>"742a2d545019733686164b83dd925e486bae12b8|api_version=3&customer%5Bemail%5D=email0%40email.com&customer%5Bid%5D=1&kind=create_customer&public_key=xxx&redirect_url=http%3A%2F%2F127.0.0.1%3A54281%2Fre%2Fusers%2Fpay&time=20121214151439", "customer"=>{"first_name"=>"Scarlett", "last_name"=>"Pimpernell", "credit_card"=>{"billing_address"=>{"street_address"=>"1 Here", "extended_address"=>"There", "locality"=>"San Francisco", "region"=>"California", "postal_code"=>"11111"}, "number"=>"4111111111111111", "expiration_date"=>"12/15", "cvv"=>"111"}}, "commit"=>"Pay", "splat"=>[], "captures"=>["xxx"], "merchant_id"=>"xxx"}
So this hits the app fine, and clearly redirects correctly because our rails app is hit on the correct url. Log:
Started GET "/re/users/pay?http_status=200&id=a92dea503ed7b2e94e80e7a5745d1472&kind=create_customer&hash=18881831a344369481e26970dcc0d9ec0fcae76a" for 127.0.0.1 at 2012-12-14 15:27:11 +0000
Processing by Restaurant::RegistrationsController#payment as HTML
Parameters: {"http_status"=>"200", "id"=>"a92dea503ed7b2e94e80e7a5745d1472", "kind"=>"create_customer", "hash"=>"18881831a344369481e26970dcc0d9ec0fcae76a"}
Starting the confirm http_status=200&id=a92dea503ed7b2e94e80e7a5745d1472&kind=create_customer&hash=18881831a344369481e26970dcc0d9ec0fcae76a
At this stage it hangs, and times out.
The sinatra app was modified to look like so:
# Braintree::TransparentRedirect.confirm
post "/merchants/:merchant_id/transparent_redirect_requests/:id/confirm" do
Braintree::Configuration.logger.debug "CONFIRMING #{params}"
It never gets to this part while the test is running, but as soon as it times out. Low and behold! the sinatra log shows:
CONFIRMING {"splat"=>[], "captures"=>["xxx", "a92dea503ed7b2e94e80e7a5745d1472"], "merchant_id"=>"xxx", "id"=>"a92dea503ed7b2e94e80e7a5745d1472"}
However my tests shows:
Timeout::Error (Timeout::Error):
app/controllers/registrations_controller.rb:38:in `payment'
No idea why, the app is running and acccepting requests (I used HTTP Client to test it was).
W.T.F.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment