defra_ruby_mocks 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -75
- data/app/controllers/defra_ruby_mocks/govpay_controller.rb +23 -0
- data/app/services/defra_ruby_mocks/govpay_refund_details_service.rb +43 -0
- data/app/services/defra_ruby_mocks/govpay_request_refund_service.rb +27 -0
- data/config/routes.rb +10 -10
- data/lib/defra_ruby_mocks/configuration.rb +1 -1
- data/lib/defra_ruby_mocks/engine.rb +0 -1
- data/lib/defra_ruby_mocks/version.rb +1 -1
- data/spec/dummy/log/test.log +1117 -2298
- data/spec/examples.txt +68 -130
- data/spec/requests/govpay_spec.rb +44 -1
- data/spec/services/govpay_refund_details_service_spec.rb +58 -0
- data/spec/services/govpay_request_refund_service_spec.rb +31 -0
- metadata +8 -48
- data/app/controllers/defra_ruby_mocks/worldpay_controller.rb +0 -57
- data/app/services/defra_ruby_mocks/worldpay_payment_service.rb +0 -47
- data/app/services/defra_ruby_mocks/worldpay_refund_service.rb +0 -37
- data/app/services/defra_ruby_mocks/worldpay_request_handler_service.rb +0 -40
- data/app/services/defra_ruby_mocks/worldpay_resource_service.rb +0 -55
- data/app/services/defra_ruby_mocks/worldpay_response_service.rb +0 -119
- data/app/views/defra_ruby_mocks/worldpay/payment_request.xml.erb +0 -4
- data/app/views/defra_ruby_mocks/worldpay/refund_request.xml.erb +0 -4
- data/app/views/defra_ruby_mocks/worldpay/stuck.html.erb +0 -37
- data/lib/defra_ruby_mocks/unrecognised_worldpay_request_error.rb +0 -5
- data/spec/fixtures/files/worldpay/payment_request_invalid.xml +0 -6
- data/spec/fixtures/files/worldpay/payment_request_valid.xml +0 -30
- data/spec/fixtures/files/worldpay/refund_request_invalid.xml +0 -6
- data/spec/fixtures/files/worldpay/refund_request_valid.xml +0 -11
- data/spec/fixtures/files/worldpay/unrecognised_request.xml +0 -6
- data/spec/requests/worldpay_spec.rb +0 -163
- data/spec/services/worldpay_payment_service_spec.rb +0 -95
- data/spec/services/worldpay_refund_service_spec.rb +0 -68
- data/spec/services/worldpay_request_handler_service_spec.rb +0 -79
- data/spec/services/worldpay_resource_service_spec.rb +0 -120
- data/spec/services/worldpay_response_service_spec.rb +0 -280
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyMocks
|
4
|
-
class WorldpayRequestHandlerService < BaseService
|
5
|
-
def run(xml)
|
6
|
-
arguments = {
|
7
|
-
merchant_code: extract_merchant_code(xml),
|
8
|
-
xml: xml
|
9
|
-
}
|
10
|
-
|
11
|
-
generate_response(arguments)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def extract_merchant_code(xml)
|
17
|
-
payment_service = xml.at_xpath("//paymentService")
|
18
|
-
payment_service.attribute("merchantCode").text
|
19
|
-
end
|
20
|
-
|
21
|
-
def generate_response(arguments)
|
22
|
-
return WorldpayPaymentService.run(arguments).merge(request_type: :payment) if payment_request?(arguments[:xml])
|
23
|
-
return WorldpayRefundService.run(arguments).merge(request_type: :refund) if refund_request?(arguments[:xml])
|
24
|
-
|
25
|
-
raise UnrecognisedWorldpayRequestError
|
26
|
-
end
|
27
|
-
|
28
|
-
def payment_request?(xml)
|
29
|
-
submit = xml.at_xpath("//submit")
|
30
|
-
|
31
|
-
!submit.nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
def refund_request?(xml)
|
35
|
-
modify = xml.at_xpath("//modify")
|
36
|
-
|
37
|
-
!modify.nil?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyMocks
|
4
|
-
class WorldpayResourceService < BaseService
|
5
|
-
|
6
|
-
def run(reference:)
|
7
|
-
@reference = reference
|
8
|
-
|
9
|
-
raise(MissingResourceError, @reference) if resource.nil?
|
10
|
-
|
11
|
-
WorldpayResource.new(resource, order, company_name)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
WorldpayResource = Struct.new(:resource, :order, :company_name)
|
17
|
-
|
18
|
-
def resource
|
19
|
-
@_resource ||= locate_transient_registration || locate_completed_registration
|
20
|
-
end
|
21
|
-
|
22
|
-
def locate_transient_registration
|
23
|
-
"WasteCarriersEngine::TransientRegistration"
|
24
|
-
.constantize
|
25
|
-
.where(token: @reference)
|
26
|
-
.first
|
27
|
-
end
|
28
|
-
|
29
|
-
def locate_completed_registration
|
30
|
-
"WasteCarriersEngine::Registration"
|
31
|
-
.constantize
|
32
|
-
.where(reg_uuid: @reference)
|
33
|
-
.first
|
34
|
-
end
|
35
|
-
|
36
|
-
def locate_original_registration(reg_identifier)
|
37
|
-
"WasteCarriersEngine::Registration"
|
38
|
-
.constantize
|
39
|
-
.where(reg_identifier: reg_identifier)
|
40
|
-
.first
|
41
|
-
end
|
42
|
-
|
43
|
-
def order
|
44
|
-
@_order ||= resource.finance_details&.orders&.order_by(dateCreated: :desc)&.first
|
45
|
-
end
|
46
|
-
|
47
|
-
def company_name
|
48
|
-
if resource.class.to_s == "WasteCarriersEngine::OrderCopyCardsRegistration"
|
49
|
-
locate_original_registration(resource.reg_identifier).company_name&.downcase
|
50
|
-
else
|
51
|
-
resource.company_name&.downcase
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyMocks
|
4
|
-
class WorldpayResponseService < BaseService
|
5
|
-
|
6
|
-
def run(success_url:, failure_url:, pending_url:, cancel_url:, error_url:)
|
7
|
-
urls = {
|
8
|
-
success: success_url,
|
9
|
-
failure: failure_url,
|
10
|
-
pending: pending_url,
|
11
|
-
cancel: cancel_url,
|
12
|
-
error: error_url
|
13
|
-
}
|
14
|
-
|
15
|
-
parse_reference(urls[:success])
|
16
|
-
@resource = WorldpayResourceService.run(reference: @reference)
|
17
|
-
|
18
|
-
generate_response(urls)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
WorldpayResponse = Struct.new(:supplied_url, :separator, :order_key, :mac, :value, :status, :reference) do
|
24
|
-
def url
|
25
|
-
[supplied_url, separator, params].join
|
26
|
-
end
|
27
|
-
|
28
|
-
def params
|
29
|
-
[
|
30
|
-
"orderKey=#{order_key}",
|
31
|
-
"paymentStatus=#{status}",
|
32
|
-
"paymentAmount=#{value}",
|
33
|
-
"paymentCurrency=GBP",
|
34
|
-
"mac=#{mac}",
|
35
|
-
"source=WP"
|
36
|
-
].join("&")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def parse_reference(url)
|
41
|
-
path = URI.parse(url).path
|
42
|
-
parts = path.split("/")
|
43
|
-
|
44
|
-
if parts[1].downcase == "your-registration"
|
45
|
-
# ["", "your-registration", "xP2zj9nqWYI0SAsMtGZn6w", "worldpay", "success", "1577812071", "NEWREG"]
|
46
|
-
@reference = parts[-5]
|
47
|
-
@url_format = :old
|
48
|
-
else
|
49
|
-
# ["", "fo", "jq6sTt2RQguAu4ZyKFfRg9zm", "worldpay", "success"]
|
50
|
-
@reference = parts[-3]
|
51
|
-
@url_format = :new
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def order_key
|
56
|
-
[
|
57
|
-
DefraRubyMocks.configuration.worldpay_admin_code,
|
58
|
-
DefraRubyMocks.configuration.worldpay_merchant_code,
|
59
|
-
@resource.order.order_code
|
60
|
-
].join("^")
|
61
|
-
end
|
62
|
-
|
63
|
-
def order_value
|
64
|
-
@resource.order.total_amount.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
def payment_status
|
68
|
-
return :AUTHORISED unless @resource.company_name
|
69
|
-
|
70
|
-
return :REFUSED if @resource.company_name.include?("reject")
|
71
|
-
return :STUCK if @resource.company_name.include?("stuck")
|
72
|
-
return :SENT_FOR_AUTHORISATION if @resource.company_name.include?("pending")
|
73
|
-
return :CANCELLED if @resource.company_name.include?("cancel")
|
74
|
-
return :ERROR if @resource.company_name.include?("error")
|
75
|
-
|
76
|
-
:AUTHORISED
|
77
|
-
end
|
78
|
-
|
79
|
-
def url(payment_status, urls)
|
80
|
-
return urls[:failure] if %i[REFUSED STUCK].include?(payment_status)
|
81
|
-
return urls[:pending] if payment_status == :SENT_FOR_AUTHORISATION
|
82
|
-
return urls[:cancel] if payment_status == :CANCELLED
|
83
|
-
return urls[:error] if payment_status == :ERROR
|
84
|
-
|
85
|
-
urls[:success]
|
86
|
-
end
|
87
|
-
|
88
|
-
# Generate a mac that matches what Worldpay would generate
|
89
|
-
#
|
90
|
-
# For whatever reason, if the payment is cancelled by the user Worldpay does
|
91
|
-
# not include the payment status in the mac it generates. Plus the order of
|
92
|
-
# things in the array is important.
|
93
|
-
def generate_mac(status)
|
94
|
-
data = [
|
95
|
-
order_key,
|
96
|
-
order_value,
|
97
|
-
"GBP"
|
98
|
-
]
|
99
|
-
data << status unless status == :CANCELLED
|
100
|
-
data << DefraRubyMocks.configuration.worldpay_mac_secret
|
101
|
-
|
102
|
-
Digest::MD5.hexdigest(data.join).to_s
|
103
|
-
end
|
104
|
-
|
105
|
-
def generate_response(urls)
|
106
|
-
status = payment_status
|
107
|
-
|
108
|
-
WorldpayResponse.new(
|
109
|
-
url(status, urls),
|
110
|
-
@url_format == :new ? "?" : "&",
|
111
|
-
order_key,
|
112
|
-
generate_mac(status),
|
113
|
-
order_value,
|
114
|
-
status,
|
115
|
-
@reference
|
116
|
-
)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
@@ -1,4 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE paymentService PUBLIC "-//WorldPay//DTD WorldPay PaymentService v1//EN"
|
3
|
-
"http://dtd.worldpay.com/paymentService_v1.dtd">
|
4
|
-
<paymentService version="1.4" merchantCode="<%= @values[:merchant_code] %>"><reply><orderStatus orderCode="<%= @values[:order_code] %>"><reference id="<%= @values[:id] %>"><%= @values[:url] %></reference></orderStatus></reply></paymentService>
|
@@ -1,4 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE paymentService PUBLIC "-//WorldPay//DTD WorldPay PaymentService v1//EN"
|
3
|
-
"http://dtd.worldpay.com/paymentService_v1.dtd">
|
4
|
-
<paymentService version="1.4" merchantCode="<%= @values[:merchant_code] %>"><reply><ok><refundReceived orderCode="<%= @values[:order_code] %>"><amount value="<%= @values[:refund_value] %>" currencyCode="<%= @values[:currency_code] %>" exponent="<%= @values[:exponent] %>" debitCreditIndicator="credit"/></refundReceived></ok></reply></paymentService>
|
@@ -1,37 +0,0 @@
|
|
1
|
-
<!doctype html>
|
2
|
-
|
3
|
-
<html lang="en">
|
4
|
-
<head>
|
5
|
-
<meta charset="utf-8">
|
6
|
-
|
7
|
-
<title>You is stuck</title>
|
8
|
-
<meta name="description" content="Thw Worldpay stuck page">
|
9
|
-
<meta name="author" content="Defra">
|
10
|
-
</head>
|
11
|
-
|
12
|
-
<body>
|
13
|
-
<main>
|
14
|
-
<div id="message">
|
15
|
-
<h1>Stuck!</h1>
|
16
|
-
<p>Looks like your registration has gotten stuck whilst paying for it using Worldpay.</p>
|
17
|
-
<p>We hope that's what you expected to happen.</p>
|
18
|
-
<p>Regards, the Ruby Services Team</p>
|
19
|
-
</div>
|
20
|
-
<% if @response %>
|
21
|
-
<div id="debug">
|
22
|
-
<h2>Debug</h2>
|
23
|
-
<ul>
|
24
|
-
<li><strong>Supplied URL</strong> <code><%= @response.supplied_url %></code></li>
|
25
|
-
<li><strong>Separator</strong> <code><%= @response.separator %></code></li>
|
26
|
-
<li><strong>Order key</strong> <code><%= @response.order_key %></code></li>
|
27
|
-
<li><strong>Mac</strong> <code><%= @response.mac %></code></li>
|
28
|
-
<li><strong>Value</strong> <code><%= @response.value %></code></li>
|
29
|
-
<li><strong>Status</strong> <code><%= @response.status %></code></li>
|
30
|
-
<li><strong>Reference</strong> <code><%= @response.reference %></code></li>
|
31
|
-
<li><strong>Url</strong> <code><%= @response.url %></code></li>
|
32
|
-
</ul>
|
33
|
-
</div>
|
34
|
-
<% end %>
|
35
|
-
</main>
|
36
|
-
</body>
|
37
|
-
</html>
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<!DOCTYPE paymentService PUBLIC "-//WorldPay/DTD WorldPay PaymentService v1/EN" "http://dtd.worldpay.com/paymentService_v1.dtd">
|
3
|
-
<paymentService version="1.4" merchantCode="MERCHME">
|
4
|
-
<submit>
|
5
|
-
<order orderCode="1577726052">
|
6
|
-
<description>Your Waste Carrier Registration CBDU2</description>
|
7
|
-
<amount currencyCode="GBP" value="10500" exponent="2"/>
|
8
|
-
<orderContent>Waste Carrier Registration renewal: CBDU2 for Booth Mcdaniel Associates</orderContent>
|
9
|
-
<paymentMethodMask>
|
10
|
-
<include code="VISA-SSL"/>
|
11
|
-
<include code="MAESTRO-SSL"/>
|
12
|
-
<include code="ECMC-SSL"/>
|
13
|
-
</paymentMethodMask>
|
14
|
-
<shopper>
|
15
|
-
<shopperEmailAddress>vucij@example.com</shopperEmailAddress>
|
16
|
-
</shopper>
|
17
|
-
<billingAddress>
|
18
|
-
<address>
|
19
|
-
<firstName>Bell</firstName>
|
20
|
-
<lastName>Cruz</lastName>
|
21
|
-
<address1>HARMSEN GROUP DEANERY ROAD</address1>
|
22
|
-
<address2/>
|
23
|
-
<postalCode>BS1 5AH</postalCode>
|
24
|
-
<city>BRISTOL</city>
|
25
|
-
<countryCode>GB</countryCode>
|
26
|
-
</address>
|
27
|
-
</billingAddress>
|
28
|
-
</order>
|
29
|
-
</submit>
|
30
|
-
</paymentService>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<!DOCTYPE paymentService PUBLIC '-//WorldPay/DTD WorldPay PaymentService v1/EN' 'http://dtd.worldpay.com/paymentService_v1.dtd'>
|
3
|
-
<paymentService version="1.4" merchantCode="MERCHME">
|
4
|
-
<modify>
|
5
|
-
<orderModification orderCode="1579644835">
|
6
|
-
<refund>
|
7
|
-
<amount value="2500" currencyCode="GBP" exponent="2"/>
|
8
|
-
</refund>
|
9
|
-
</orderModification>
|
10
|
-
</modify>
|
11
|
-
</paymentService>
|
@@ -1,163 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe "Worldpay", type: :request do
|
7
|
-
after(:all) { Helpers::Configuration.reset_for_tests }
|
8
|
-
|
9
|
-
context "when mocks are enabled" do
|
10
|
-
before(:each) do
|
11
|
-
Helpers::Configuration.prep_for_tests
|
12
|
-
DefraRubyMocks.configure do |config|
|
13
|
-
config.worldpay_admin_code = "admincode1"
|
14
|
-
config.worldpay_mac_secret = "macsecret1"
|
15
|
-
config.worldpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "#payments_service" do
|
20
|
-
let(:path) { "/defra_ruby_mocks/worldpay/payments-service" }
|
21
|
-
|
22
|
-
context "when a payment request is received" do
|
23
|
-
context "and the request is valid" do
|
24
|
-
let(:data) { File.read("spec/fixtures/files/worldpay/payment_request_valid.xml") }
|
25
|
-
|
26
|
-
it "returns an XML response with a 200 code" do
|
27
|
-
post path, headers: { "RAW_POST_DATA" => data }
|
28
|
-
|
29
|
-
expect(response.media_type).to eq("application/xml")
|
30
|
-
expect(response.code).to eq("200")
|
31
|
-
expect(response.body).to be_xml
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "and the request is invalid" do
|
36
|
-
let(:data) { File.read("spec/fixtures/files/worldpay/payment_request_invalid.xml") }
|
37
|
-
|
38
|
-
it "returns a response with a 500 code" do
|
39
|
-
post path, headers: { "RAW_POST_DATA" => data }
|
40
|
-
|
41
|
-
expect(response.code).to eq("500")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when a refund request is received" do
|
47
|
-
context "and the request is valid" do
|
48
|
-
let(:data) { File.read("spec/fixtures/files/worldpay/refund_request_valid.xml") }
|
49
|
-
|
50
|
-
it "returns an XML response with a 200 code" do
|
51
|
-
post path, headers: { "RAW_POST_DATA" => data }
|
52
|
-
|
53
|
-
expect(response.media_type).to eq("application/xml")
|
54
|
-
expect(response.code).to eq("200")
|
55
|
-
expect(response.body).to be_xml
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "#dispatcher" do
|
62
|
-
let(:success_url) { "http://example.com/fo/12345/worldpay/success" }
|
63
|
-
let(:failure_url) { "http://example.com/fo/12345/worldpay/failure" }
|
64
|
-
let(:pending_url) { "http://example.com/fo/12345/worldpay/pending" }
|
65
|
-
let(:cancel_url) { "http://example.com/fo/12345/worldpay/cancel" }
|
66
|
-
let(:error_url) { "http://example.com/fo/12345/worldpay/error" }
|
67
|
-
let(:response_url) { "#{success_url}?orderKey=admincode1^^987654&paymentStatus=#{status}&paymentAmount=10500&paymentCurrency=GBP&mac=0ba5271e1ed1b26f9bb428ef7fb536a4&source=WP" }
|
68
|
-
let(:path) do
|
69
|
-
root = "/defra_ruby_mocks/worldpay/dispatcher"
|
70
|
-
escaped_success = CGI.escape(success_url)
|
71
|
-
escaped_failure = CGI.escape(failure_url)
|
72
|
-
escaped_pending = CGI.escape(pending_url)
|
73
|
-
escaped_cancel = CGI.escape(cancel_url)
|
74
|
-
escaped_error = CGI.escape(error_url)
|
75
|
-
|
76
|
-
"#{root}?successURL=#{escaped_success}&failureURL=#{escaped_failure}&pendingURL=#{escaped_pending}&cancelURL=#{escaped_cancel}&errorURL=#{escaped_error}"
|
77
|
-
end
|
78
|
-
let(:service_response) do
|
79
|
-
double(
|
80
|
-
:response,
|
81
|
-
supplied_url: success_url,
|
82
|
-
url: response_url,
|
83
|
-
status: status,
|
84
|
-
separator: "?",
|
85
|
-
order_key: "admincode1",
|
86
|
-
mac: "e5bc7ce5dfe44d2000771ac2b157f0e9",
|
87
|
-
value: 154_00,
|
88
|
-
reference: "12345"
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
context "and the request is valid" do
|
93
|
-
before(:each) do
|
94
|
-
allow(WorldpayResponseService).to receive(:run)
|
95
|
-
.with(
|
96
|
-
success_url: success_url,
|
97
|
-
failure_url: failure_url,
|
98
|
-
pending_url: pending_url,
|
99
|
-
cancel_url: cancel_url,
|
100
|
-
error_url: error_url
|
101
|
-
) { service_response }
|
102
|
-
end
|
103
|
-
|
104
|
-
context "and a response is expected" do
|
105
|
-
let(:status) { "AUTHORISED" }
|
106
|
-
|
107
|
-
it "redirects the user with a 300 code" do
|
108
|
-
get path
|
109
|
-
|
110
|
-
expect(response).to redirect_to(response_url)
|
111
|
-
expect(response.code).to eq("302")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "and a response is not expected" do
|
116
|
-
let(:status) { :STUCK }
|
117
|
-
|
118
|
-
it "renders the Worldpay stuck page" do
|
119
|
-
get path
|
120
|
-
|
121
|
-
expect(response).to render_template(:stuck)
|
122
|
-
expect(response.code).to eq("200")
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "and the request is invalid" do
|
128
|
-
before(:each) { allow(WorldpayResponseService).to receive(:run).and_raise(MissingResourceError.new("foo")) }
|
129
|
-
|
130
|
-
context "because the success url is not in a recognised format" do
|
131
|
-
let(:success_url) { "http://example.com/forthewin" }
|
132
|
-
|
133
|
-
it "returns a response with a 500 code" do
|
134
|
-
get path
|
135
|
-
|
136
|
-
expect(response.code).to eq("500")
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context "when mocks are disabled" do
|
144
|
-
before(:each) { DefraRubyMocks.configuration.enable = false }
|
145
|
-
|
146
|
-
context "#payments_service" do
|
147
|
-
let(:path) { "/defra_ruby_mocks/worldpay/payments-service" }
|
148
|
-
|
149
|
-
it "cannot load the page" do
|
150
|
-
expect { get path }.to raise_error(ActionController::RoutingError)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "#dispatcher" do
|
155
|
-
let(:path) { "/defra_ruby_mocks/worldpay/dispatcher" }
|
156
|
-
|
157
|
-
it "cannot load the page" do
|
158
|
-
expect { get path }.to raise_error(ActionController::RoutingError)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe WorldpayPaymentService do
|
7
|
-
describe ".run" do
|
8
|
-
after(:each) { Helpers::Configuration.reset_for_tests }
|
9
|
-
|
10
|
-
let(:merchant_code) { "MERCHME" }
|
11
|
-
let(:args) { { merchant_code: merchant_code, xml: xml } }
|
12
|
-
|
13
|
-
context "when the mocks config is missing a worldpay domain" do
|
14
|
-
let(:xml) { nil }
|
15
|
-
|
16
|
-
it "raises a 'InvalidConfigError'" do
|
17
|
-
expect { described_class.run(args) }.to raise_error InvalidConfigError
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when the XML is valid" do
|
22
|
-
before(:each) do
|
23
|
-
DefraRubyMocks.configure do |config|
|
24
|
-
config.worldpay_domain = "http://localhost:3000/defra_ruby_mocks"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/files/worldpay/payment_request_valid.xml")) }
|
29
|
-
|
30
|
-
context "the result it returns" do
|
31
|
-
it "is a hash" do
|
32
|
-
expect(described_class.run(args)).to be_an_instance_of(Hash)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "contains 4 values" do
|
36
|
-
result = described_class.run(args).length
|
37
|
-
expect(result).to eq(4)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "has the merchant code passed in" do
|
41
|
-
result = described_class.run(args)[:merchant_code]
|
42
|
-
|
43
|
-
expect(result).to eq(merchant_code)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has an order code extracted from the XML" do
|
47
|
-
result = described_class.run(args)[:order_code]
|
48
|
-
|
49
|
-
expect(result).to eq("1577726052")
|
50
|
-
end
|
51
|
-
|
52
|
-
context "has a generated ID which is" do
|
53
|
-
it "10 characters long" do
|
54
|
-
result = described_class.run(args)[:id]
|
55
|
-
|
56
|
-
expect(result.length).to eq(10)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "only made up of the digits 0 to 9" do
|
60
|
-
result = described_class.run(args)[:id]
|
61
|
-
|
62
|
-
expect(result.scan(/\D/).empty?).to be_truthy
|
63
|
-
end
|
64
|
-
|
65
|
-
it "different each time" do
|
66
|
-
results = []
|
67
|
-
3.times do
|
68
|
-
results << described_class.run(args)[:id]
|
69
|
-
end
|
70
|
-
|
71
|
-
expect(results.uniq.length).to eq(results.length)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "has a url" do
|
76
|
-
it "based on the configured domain, and extracted merchant and order codes" do
|
77
|
-
result = described_class.run(args)[:url]
|
78
|
-
|
79
|
-
expect(result).to eq("http://localhost:3000/defra_ruby_mocks/worldpay/dispatcher?OrderKey=MERCHME%5E1577726052")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when the XML is invalid" do
|
87
|
-
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/files/worldpay/payment_request_invalid.xml")) }
|
88
|
-
|
89
|
-
it "raises an error" do
|
90
|
-
expect { described_class.run(args) }.to raise_error StandardError
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails_helper"
|
4
|
-
|
5
|
-
module DefraRubyMocks
|
6
|
-
RSpec.describe WorldpayRefundService do
|
7
|
-
describe ".run" do
|
8
|
-
|
9
|
-
let(:merchant_code) { "MERCHME" }
|
10
|
-
let(:args) { { merchant_code: merchant_code, xml: xml } }
|
11
|
-
|
12
|
-
context "when the XML is valid" do
|
13
|
-
|
14
|
-
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/files/worldpay/refund_request_valid.xml")) }
|
15
|
-
|
16
|
-
context "the result it returns" do
|
17
|
-
it "is a hash" do
|
18
|
-
expect(described_class.run(args)).to be_an_instance_of(Hash)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "contains 5 values" do
|
22
|
-
result = described_class.run(args).length
|
23
|
-
expect(result).to eq(5)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "has the merchant code passed in" do
|
27
|
-
result = described_class.run(args)[:merchant_code]
|
28
|
-
|
29
|
-
expect(result).to eq(merchant_code)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "has an order code extracted from the XML" do
|
33
|
-
result = described_class.run(args)[:order_code]
|
34
|
-
|
35
|
-
expect(result).to eq("1579644835")
|
36
|
-
end
|
37
|
-
|
38
|
-
it "has the refund value extracted from the XML" do
|
39
|
-
result = described_class.run(args)[:refund_value]
|
40
|
-
|
41
|
-
expect(result).to eq("2500")
|
42
|
-
end
|
43
|
-
|
44
|
-
it "has a currency code extracted from the XML" do
|
45
|
-
result = described_class.run(args)[:currency_code]
|
46
|
-
|
47
|
-
expect(result).to eq("GBP")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "has the exponent extracted from the XML" do
|
51
|
-
result = described_class.run(args)[:exponent]
|
52
|
-
|
53
|
-
expect(result).to eq("2")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when the XML is invalid" do
|
60
|
-
let(:xml) { Nokogiri::XML(File.read("spec/fixtures/files/worldpay/refund_request_invalid.xml")) }
|
61
|
-
|
62
|
-
it "raises an error" do
|
63
|
-
expect { described_class.run(args) }.to raise_error StandardError
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|