From 3bbd32d49068a4320c6ec460e9e41eb653181abd Mon Sep 17 00:00:00 2001 From: Janis Miezitis Date: Tue, 8 Jan 2013 18:21:26 +0200 Subject: [PATCH 1/3] Added transaction id as optional parameter --- lib/active_merchant/billing/first_data_gateway.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/active_merchant/billing/first_data_gateway.rb b/lib/active_merchant/billing/first_data_gateway.rb index b28a955..bb4f44e 100644 --- a/lib/active_merchant/billing/first_data_gateway.rb +++ b/lib/active_merchant/billing/first_data_gateway.rb @@ -280,8 +280,13 @@ def endpoint_url test? ? test_url : live_url end - def redirect_url - test? ? test_redirect_url : live_redirect_url + def redirect_url(trans_id = nil) + trans_id_param = "?trans_id=#{CGI.escape trans_id}" if trans_id + if test? + trans_id ? test_redirect_url + trans_id_param : test_redirect_url + else + trans_id ? live_redirect_url + trans_id_param : live_redirect_url + end end private From c02bf11a0ab81b8ab2afd9a6fbf28aa693358108 Mon Sep 17 00:00:00 2001 From: Janis Miezitis Date: Tue, 8 Jan 2013 18:28:36 +0200 Subject: [PATCH 2/3] Added tests for redirect_url --- spec/active_merchant/billing/first_data_gateway_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/active_merchant/billing/first_data_gateway_spec.rb b/spec/active_merchant/billing/first_data_gateway_spec.rb index 88121f4..d3964d3 100644 --- a/spec/active_merchant/billing/first_data_gateway_spec.rb +++ b/spec/active_merchant/billing/first_data_gateway_spec.rb @@ -685,6 +685,13 @@ end end + it "26) return correct redirect url with transaction id" do + @gateway.redirect_url.should == @gateway.test_redirect_url + end + + it "27) return correct redirect url without transaction id" do + @gateway.redirect_url("2SGip+TK/dVYe+XMSeQuECMs//S=").should == @gateway.test_redirect_url + "?trans_id=2SGip%2BTK%2FdVYe%2BXMSeQuECMs%2F%2FS%3D" + end end def submit_form(url, params, cassette_prefix) From 2c43815a3ad660bcd105c28110fcbc91749f9020 Mon Sep 17 00:00:00 2001 From: Janis Miezitis Date: Tue, 8 Jan 2013 18:49:19 +0200 Subject: [PATCH 3/3] Added redirect url with less complexity --- lib/active_merchant/billing/first_data_gateway.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/active_merchant/billing/first_data_gateway.rb b/lib/active_merchant/billing/first_data_gateway.rb index bb4f44e..70a9729 100644 --- a/lib/active_merchant/billing/first_data_gateway.rb +++ b/lib/active_merchant/billing/first_data_gateway.rb @@ -281,12 +281,9 @@ def endpoint_url end def redirect_url(trans_id = nil) - trans_id_param = "?trans_id=#{CGI.escape trans_id}" if trans_id - if test? - trans_id ? test_redirect_url + trans_id_param : test_redirect_url - else - trans_id ? live_redirect_url + trans_id_param : live_redirect_url - end + url = test? ? test_redirect_url : live_redirect_url + url += "?trans_id=#{CGI.escape trans_id}" if trans_id + url end private