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

Always send account_email to WorldPay #325

Merged
merged 2 commits into from
Dec 7, 2018
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
17 changes: 6 additions & 11 deletions app/services/waste_carriers_engine/worldpay_xml_service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "countries"

module WasteCarriersEngine
Expand Down Expand Up @@ -62,7 +64,7 @@ def build_payment_methods(xml)
end

def build_shopper(xml)
email = get_email
email = @transient_registration.account_email

xml.shopper do
xml.shopperEmailAddress email
Expand All @@ -79,7 +81,7 @@ def build_address(xml)
address2 = address.address_line_2
postcode = address.postcode
city = address.town_city
country_code = get_country_code(address.country)
country_code = look_up_country_code(address.country)

xml.billingAddress do
xml.address do
Expand All @@ -94,19 +96,12 @@ def build_address(xml)
end
end

def get_country_code(country)
def look_up_country_code(country)
country = ISO3166::Country.find_country_by_name(country)
# If we didn't provide a country or no match was found, use GB as default
return "GB" if country.nil?
country.alpha2
end

def get_email
if @current_user.email == @transient_registration.account_email
@transient_registration.account_email
else
@transient_registration.contact_email
end
country.alpha2
end
end
end
30 changes: 0 additions & 30 deletions spec/fixtures/files/request_to_worldpay_ad.xml

This file was deleted.

27 changes: 6 additions & 21 deletions spec/services/waste_carriers_engine/worldpay_xml_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

module WasteCarriersEngine
Expand Down Expand Up @@ -26,27 +28,10 @@ module WasteCarriersEngine
allow_any_instance_of(Order).to receive(:total_amount).and_return(10_000)
end

describe "build_xml" do
context "when it's a digital registration" do
before do
current_user.email = transient_registration.account_email
end

it "returns correctly-formatted XML" do
xml = File.read("./spec/fixtures/files/request_to_worldpay.xml")
expect(worldpay_xml_service.build_xml).to eq(xml)
end
end

context "when it's an assisted digital registration" do
before do
current_user.email = "not-the-same-account@example.com"
end

it "returns correctly-formatted XML" do
xml = File.read("./spec/fixtures/files/request_to_worldpay_ad.xml")
expect(worldpay_xml_service.build_xml).to eq(xml)
end
describe "#build_xml" do
it "returns correctly-formatted XML" do
xml = File.read("./spec/fixtures/files/request_to_worldpay.xml")
expect(worldpay_xml_service.build_xml).to eq(xml)
end
end
end
Expand Down