Skip to content

Commit

Permalink
services/../worldpay_url_service_spec passing
Browse files Browse the repository at this point in the history
Key change is the WorldpayUrlService needs to be dealing with a transient registration token not a reg identifier, so we can accurately determine which one to assign a payment against.
  • Loading branch information
Cruikshanks committed Dec 9, 2019
1 parent 7b6066f commit 6a1d5b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/services/waste_carriers_engine/worldpay_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def prepare_for_payment
reference = parse_response(response)

if reference.present?
worldpay_url_service = WorldpayUrlService.new(@transient_registration.reg_identifier, reference[:link])
worldpay_url_service = WorldpayUrlService.new(@transient_registration.token, reference[:link])
url = worldpay_url_service.format_link

{
Expand Down
6 changes: 3 additions & 3 deletions app/services/waste_carriers_engine/worldpay_url_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module WasteCarriersEngine
# Builds the URL we use to redirect users to Worldpay.
# This should include URLs for our own service, which Worldpay will redirect users to after payment.
class WorldpayUrlService
def initialize(reg_identifier, base_url)
@reg_identifier = reg_identifier
def initialize(token, base_url)
@token = token
@base_url = base_url
end

Expand All @@ -29,7 +29,7 @@ def redirect_url_for(action)
def build_path_for(action)
path = "#{action}_worldpay_forms_path"
url = [Rails.configuration.host,
WasteCarriersEngine::Engine.routes.url_helpers.public_send(path, @reg_identifier)]
WasteCarriersEngine::Engine.routes.url_helpers.public_send(path, token: @token)]
CGI.escape(url.join)
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/services/waste_carriers_engine/worldpay_url_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module WasteCarriersEngine
create(:renewing_registration,
:has_required_data)
end
let(:reg_id) { transient_registration.reg_identifier }
let(:token) { transient_registration.token }
let(:link_base) { "https://secure-test.worldpay.com/wcc/dispatcher?OrderKey=" }
let(:worldpay_url_service) { WorldpayUrlService.new(reg_id, link_base) }
let(:worldpay_url_service) { WorldpayUrlService.new(token, link_base) }

describe "format_url" do
let(:url) { worldpay_url_service.format_link }
Expand All @@ -25,27 +25,27 @@ module WasteCarriersEngine
end

it "includes the success URL" do
success_url = "&successURL=" + CGI.escape("#{root}/worldpay/success/#{reg_id}")
success_url = "&successURL=" + CGI.escape("#{root}/#{token}/worldpay/success")
expect(url).to include(success_url)
end

it "includes the pending URL" do
pending_url = "&pendingURL=" + CGI.escape("#{root}/worldpay/pending/#{reg_id}")
pending_url = "&pendingURL=" + CGI.escape("#{root}/#{token}/worldpay/pending")
expect(url).to include(pending_url)
end

it "includes the failure URL" do
failure_url = "&failureURL=" + CGI.escape("#{root}/worldpay/failure/#{reg_id}")
failure_url = "&failureURL=" + CGI.escape("#{root}/#{token}/worldpay/failure")
expect(url).to include(failure_url)
end

it "includes the cancel URL" do
cancel_url = "&cancelURL=" + CGI.escape("#{root}/worldpay/cancel/#{reg_id}")
cancel_url = "&cancelURL=" + CGI.escape("#{root}/#{token}/worldpay/cancel")
expect(url).to include(cancel_url)
end

it "includes the error URL" do
error_url = "&errorURL=" + CGI.escape("#{root}/worldpay/error/#{reg_id}")
error_url = "&errorURL=" + CGI.escape("#{root}/#{token}/worldpay/error")
expect(url).to include(error_url)
end
end
Expand Down

0 comments on commit 6a1d5b3

Please sign in to comment.