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

Send WorldPay emails to contact_email for AD renewals #278

Merged
merged 4 commits into from
Oct 8, 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
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 @@ -75,7 +75,7 @@ def prepare_params(params)
end

def send_request
xml_service = WorldpayXmlService.new(@transient_registration, @order)
xml_service = WorldpayXmlService.new(@transient_registration, @order, @current_user)
xml = xml_service.build_xml

Rails.logger.debug "Sending initial request to WorldPay"
Expand Down
13 changes: 11 additions & 2 deletions app/services/waste_carriers_engine/worldpay_xml_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

module WasteCarriersEngine
class WorldpayXmlService
def initialize(transient_registration, order)
def initialize(transient_registration, order, current_user)
@transient_registration = transient_registration
@order = order
@current_user = current_user
end

def build_xml
Expand Down Expand Up @@ -61,7 +62,7 @@ def build_payment_methods(xml)
end

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

xml.shopper do
xml.shopperEmailAddress email
Expand Down Expand Up @@ -99,5 +100,13 @@ def get_country_code(country)
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
end
end
end
4 changes: 4 additions & 0 deletions spec/factories/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
finance_details { build(:finance_details, balance: 0) }
end

trait :has_different_contact_email do
contact_email { "contact-foo@example.com" }
end

# Overseas registrations

trait :has_required_overseas_data do
Expand Down
30 changes: 30 additions & 0 deletions spec/fixtures/files/request_to_worldpay_ad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!DOCTYPE paymentService PUBLIC "-//WorldPay/DTD WorldPay PaymentService v1/EN" "http://dtd.worldpay.com/paymentService_v1.dtd">
<paymentService version="1.4" merchantCode="MERCHANTCODE">
<submit>
<order orderCode="1234567890">
<description>Your Waste Carrier Registration CBDU9999</description>
<amount currencyCode="GBP" value="10000" exponent="2"/>
<orderContent>Waste Carrier Registration renewal: CBDU9999 for Acme Waste</orderContent>
<paymentMethodMask>
<include code="VISA-SSL"/>
<include code="MAESTRO-SSL"/>
<include code="ECMC-SSL"/>
</paymentMethodMask>
<shopper>
<shopperEmailAddress>contact-foo@example.com</shopperEmailAddress>
</shopper>
<billingAddress>
<address>
<firstName>Jane</firstName>
<lastName>Doe</lastName>
<address1>42 Foo Gardens</address1>
<address2/>
<postalCode>FA1 1KE</postalCode>
<city>Baz City</city>
<countryCode>SK</countryCode>
</address>
</billingAddress>
</order>
</submit>
</paymentService>
27 changes: 23 additions & 4 deletions spec/services/waste_carriers_engine/worldpay_xml_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ module WasteCarriersEngine
let(:transient_registration) do
create(:transient_registration,
:has_required_data,
:has_different_contact_email,
:has_overseas_addresses,
:has_finance_details,
temp_cards: 0)
end
let(:order) { transient_registration.finance_details.orders.first }
let(:worldpay_xml_service) { WorldpayXmlService.new(transient_registration, order) }
let(:current_user) { build(:user) }
let(:worldpay_xml_service) { WorldpayXmlService.new(transient_registration, order, current_user) }

before do
# Set a specific reg_identifier so we can match our XML
Expand All @@ -25,9 +27,26 @@ module WasteCarriersEngine
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)
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
end
end
end
Expand Down