Skip to content

Commit

Permalink
Preserve redirect_url query parameters for transparent redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-beacher authored and Gabe Berke-Williams committed Mar 22, 2013
1 parent cebe680 commit 33f0a96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -3,6 +3,8 @@
* Braintree::Transaction.void updates the existing sale transaction instead of
creating a new transaction of type Braintree::Transaction::Status::Voided

* Preserve `redirect_url` query parameters for transparent redirect (#36)

# 0.2.1
* Fake refunds via `Braintree::Transaction.refund` and
`Braintree::CreditCard.refund`.
Expand Down
5 changes: 4 additions & 1 deletion lib/fake_braintree/redirect.rb
Expand Up @@ -32,7 +32,10 @@ def confirm
private

def uri
URI.parse(@transparent_data['redirect_url']).merge("?#{base_query}&hash=#{hash(base_query)}")
uri = URI.parse(@transparent_data['redirect_url'])
merged_query = [uri.query, base_query].compact.join('&')
uri.query = "#{merged_query}&hash=#{hash(merged_query)}"
uri
end

def base_query
Expand Down
13 changes: 13 additions & 0 deletions spec/fake_braintree/transparent_redirect_spec.rb
Expand Up @@ -15,6 +15,19 @@
params[:kind].should_not be_nil
end

it "preserves redirect_url query parameters" do
redirect_url = 'http://example.com/redirect_path?preserve=me'

response = post_transparent_redirect(
:create_customer_data,
:redirect_url => redirect_url,
:customer => build_customer_hash
)

params = parse_redirect(response)
params[:preserve].should == 'me'
end

it 'rejects submissions without transparent redirect data' do
response = post_transparent_redirect_without_data
response.code.should == '422'
Expand Down

0 comments on commit 33f0a96

Please sign in to comment.