workarea-afterpay 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +22 -0
- data/CHANGELOG.md +161 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +17 -0
- data/LICENSE +52 -0
- data/README.md +131 -0
- data/Rakefile +60 -0
- data/app/assets/fonts/workarea/storefront/raleway/raleway_800.woff +0 -0
- data/app/assets/fonts/workarea/storefront/raleway/raleway_800.woff2 +0 -0
- data/app/assets/fonts/workarea/storefront/raleway/raleway_regular.woff +0 -0
- data/app/assets/fonts/workarea/storefront/raleway/raleway_regular.woff2 +0 -0
- data/app/assets/images/workarea/storefront/afterpay/afterpay_logo.png +0 -0
- data/app/assets/images/workarea/storefront/afterpay/aus/dialog_header_image.png +0 -0
- data/app/assets/images/workarea/storefront/afterpay/aus/step_1.png +0 -0
- data/app/assets/images/workarea/storefront/afterpay/aus/step_2.png +0 -0
- data/app/assets/images/workarea/storefront/afterpay/aus/step_3.png +0 -0
- data/app/assets/images/workarea/storefront/afterpay/us/complete_checkout.svg +1 -0
- data/app/assets/images/workarea/storefront/afterpay/us/four_equal_payments.svg +1 -0
- data/app/assets/images/workarea/storefront/afterpay/us/select_installments.svg +1 -0
- data/app/assets/javascripts/workarea/storefront/afterpay/config.js.erb +17 -0
- data/app/assets/javascripts/workarea/storefront/afterpay/modules/afterpay_redirect.js +30 -0
- data/app/assets/stylesheets/workarea/storefront/components/_afterpay_dialog.scss +158 -0
- data/app/controllers/workarea/admin/afterpay/configurations_controller.rb +33 -0
- data/app/controllers/workarea/storefront/afterpay_controller.rb +124 -0
- data/app/controllers/workarea/storefront/afterpay_dialog_controller.rb +7 -0
- data/app/controllers/workarea/storefront/checkout/place_order_controller.decorator +11 -0
- data/app/helpers/workarea/storefront/afterpay_helper.rb +16 -0
- data/app/models/workarea/afterpay/configuration.rb +16 -0
- data/app/models/workarea/order.decorator +17 -0
- data/app/models/workarea/payment/afterpay_payment_gateway.rb +16 -0
- data/app/models/workarea/payment/authorize/afterpay.rb +7 -0
- data/app/models/workarea/payment/capture/afterpay.rb +35 -0
- data/app/models/workarea/payment/purchase/afterpay.rb +7 -0
- data/app/models/workarea/payment/refund/afterpay.rb +52 -0
- data/app/models/workarea/payment/tender/afterpay.rb +18 -0
- data/app/models/workarea/payment.decorator +42 -0
- data/app/services/workarea/afterpay/order_builder.rb +107 -0
- data/app/view_models/workarea/admin/afterpay_configuration_view_model.rb +36 -0
- data/app/view_models/workarea/storefront/afterpay_configuration.rb +25 -0
- data/app/view_models/workarea/storefront/afterpay_view_model.rb +89 -0
- data/app/view_models/workarea/storefront/cart_view_model.decorator +12 -0
- data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +32 -0
- data/app/view_models/workarea/storefront/product_view_model.decorator +50 -0
- data/app/views/workarea/admin/afterpay/configurations/edit.html.haml +59 -0
- data/app/views/workarea/admin/orders/tenders/_afterpay.html.haml +2 -0
- data/app/views/workarea/admin/shared/_afterpay_configuration_link.html.haml +1 -0
- data/app/views/workarea/storefront/afterpay_dialog/show.html.haml +40 -0
- data/app/views/workarea/storefront/afterpay_dialog/show_aus.html.haml +40 -0
- data/app/views/workarea/storefront/carts/_afterpay.html.haml +9 -0
- data/app/views/workarea/storefront/checkouts/_afterpay_payment.html.haml +17 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_afterpay.html.haml +4 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_afterpay.text.erb +1 -0
- data/app/views/workarea/storefront/orders/tenders/_afterpay.html.haml +5 -0
- data/app/views/workarea/storefront/products/_afterpay_pricing.html.haml +3 -0
- data/app/views/workarea/storefront/style_guides/components/_afterpay_dialog.html.haml +92 -0
- data/bin/rails +19 -0
- data/bin/test +5 -0
- data/config/initializers/appends.rb +34 -0
- data/config/initializers/workarea.rb +17 -0
- data/config/locales/en.yml +107 -0
- data/config/routes.rb +15 -0
- data/four_equal_paymnets.svg +1 -0
- data/lib/workarea/afterpay/bogus_gateway.rb +211 -0
- data/lib/workarea/afterpay/engine.rb +14 -0
- data/lib/workarea/afterpay/gateway.rb +121 -0
- data/lib/workarea/afterpay/response.rb +17 -0
- data/lib/workarea/afterpay/version.rb +5 -0
- data/lib/workarea/afterpay.rb +59 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/bin/update +26 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config/application.rb +30 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +51 -0
- data/test/dummy/config/environments/production.rb +88 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +18 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/integration/workarea/storefront/afterpay_integration_test.rb +242 -0
- data/test/models/workarea/afterpay_order_test.rb +10 -0
- data/test/models/workarea/payment/afterpay_payment_integration_test.rb +67 -0
- data/test/services/workarea/afterpay/order_builder_test.rb +88 -0
- data/test/system/workarea/storefront/afterpay_product_test.rb +51 -0
- data/test/system/workarea/storefront/cart_system_test.decorator +83 -0
- data/test/system/workarea/storefront/logged_in_checkout_system_test.decorator +10 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/test/view_models/workarea/storefront/afterpay_view_model_test.rb +100 -0
- data/test/view_models/workarea/storefront/product_view_model_afterpay_test.rb +78 -0
- data/workarea-afterpay.gemspec +23 -0
- metadata +189 -0
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class AfterpayIntengrationTest < Workarea::IntegrationTest
|
6
|
+
setup do
|
7
|
+
create_tax_category(
|
8
|
+
name: 'Sales Tax',
|
9
|
+
code: '001',
|
10
|
+
rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
|
11
|
+
)
|
12
|
+
|
13
|
+
product = create_product(
|
14
|
+
variants: [{ sku: 'SKU1', regular: 6.to_m, tax_code: '001' }]
|
15
|
+
)
|
16
|
+
|
17
|
+
create_shipping_service(
|
18
|
+
carrier: 'UPS',
|
19
|
+
name: 'Ground',
|
20
|
+
service_code: '03',
|
21
|
+
tax_code: '001',
|
22
|
+
rates: [{ price: 7.to_m }]
|
23
|
+
)
|
24
|
+
|
25
|
+
post storefront.cart_items_path,
|
26
|
+
params: {
|
27
|
+
product_id: product.id,
|
28
|
+
sku: product.skus.first,
|
29
|
+
quantity: 2
|
30
|
+
}
|
31
|
+
|
32
|
+
patch storefront.checkout_addresses_path,
|
33
|
+
params: {
|
34
|
+
email: 'bcrouse@workarea.com',
|
35
|
+
billing_address: {
|
36
|
+
first_name: 'Ben',
|
37
|
+
last_name: 'Crouse',
|
38
|
+
street: '12 N. 3rd St.',
|
39
|
+
city: 'Philadelphia',
|
40
|
+
region: 'PA',
|
41
|
+
postal_code: '19106',
|
42
|
+
country: 'US',
|
43
|
+
phone_number: '2159251800'
|
44
|
+
},
|
45
|
+
shipping_address: {
|
46
|
+
first_name: 'Ben',
|
47
|
+
last_name: 'Crouse',
|
48
|
+
street: '22 S. 3rd St.',
|
49
|
+
city: 'Philadelphia',
|
50
|
+
region: 'PA',
|
51
|
+
postal_code: '19106',
|
52
|
+
country: 'US',
|
53
|
+
phone_number: '2159251800'
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
patch storefront.checkout_shipping_path
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_start_adds_a_token_to_payment
|
61
|
+
get storefront.start_afterpay_path
|
62
|
+
|
63
|
+
payment = Payment.find(order.id)
|
64
|
+
payment.reload
|
65
|
+
|
66
|
+
assert(payment.afterpay.present?)
|
67
|
+
|
68
|
+
order.reload
|
69
|
+
|
70
|
+
assert(order.afterpay_token.present?)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_start_clears_credit_card
|
74
|
+
payment = Payment.find(order.id)
|
75
|
+
payment.set_credit_card({
|
76
|
+
month: "01",
|
77
|
+
year: Time.now.year + 1,
|
78
|
+
number: 1,
|
79
|
+
cvv: "123"
|
80
|
+
})
|
81
|
+
|
82
|
+
payment.reload
|
83
|
+
|
84
|
+
get storefront.start_afterpay_path
|
85
|
+
|
86
|
+
payment.reload
|
87
|
+
order.reload
|
88
|
+
|
89
|
+
refute(payment.credit_card.present?)
|
90
|
+
assert(payment.afterpay.present?)
|
91
|
+
assert(order.afterpay_token.present?)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_cancel_removes_afterpay
|
95
|
+
payment = Payment.find(order.id)
|
96
|
+
|
97
|
+
payment.set_afterpay(token: '1234')
|
98
|
+
|
99
|
+
assert(payment.afterpay?)
|
100
|
+
|
101
|
+
get storefront.cancel_afterpay_path(token: '1234')
|
102
|
+
payment.reload
|
103
|
+
|
104
|
+
refute(payment.afterpay?)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_handling_afterpay_payment_error
|
108
|
+
payment = Payment.find(order.id)
|
109
|
+
|
110
|
+
payment.set_afterpay(token: '1234')
|
111
|
+
|
112
|
+
params = { token: '1234', status: 'ERROR' }
|
113
|
+
get storefront.complete_afterpay_path(params)
|
114
|
+
|
115
|
+
payment.reload
|
116
|
+
refute(payment.afterpay?)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_placing_order_from_afterpay
|
120
|
+
Workarea::Afterpay::BogusGateway.any_instance.stubs(:get_order).returns(get_order_response(order.total_price.to_s))
|
121
|
+
|
122
|
+
payment = Payment.find(order.id)
|
123
|
+
|
124
|
+
payment.set_afterpay(token: '1234')
|
125
|
+
|
126
|
+
params = { token: '1234', status: 'SUCCESS' }
|
127
|
+
|
128
|
+
get storefront.complete_afterpay_path(params)
|
129
|
+
|
130
|
+
payment.reload
|
131
|
+
order.reload
|
132
|
+
|
133
|
+
assert(order.placed?)
|
134
|
+
|
135
|
+
transactions = payment.tenders.first.transactions
|
136
|
+
assert_equal(1, transactions.size)
|
137
|
+
assert(transactions.first.success?)
|
138
|
+
assert_equal('purchase', transactions.first.action)
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def test_placing_order_from_afterpay_with_invalid_order_total
|
143
|
+
Workarea::Afterpay::BogusGateway.any_instance.stubs(:get_order).returns(get_order_response("5.00"))
|
144
|
+
|
145
|
+
payment = Payment.find(order.id)
|
146
|
+
|
147
|
+
payment.set_afterpay(token: '1234')
|
148
|
+
|
149
|
+
params = { token: '1234', status: 'SUCCESS' }
|
150
|
+
|
151
|
+
get storefront.complete_afterpay_path(params)
|
152
|
+
|
153
|
+
payment.reload
|
154
|
+
order.reload
|
155
|
+
|
156
|
+
refute(order.placed?)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_placing_order_with_dual_payment
|
160
|
+
payment = Payment.find(order.id)
|
161
|
+
payment.profile = create_payment_profile(email: order.email)
|
162
|
+
|
163
|
+
payment.profile.update_attributes!(store_credit: 1.00)
|
164
|
+
payment.set_store_credit
|
165
|
+
payment.tenders.first.amount = 1.to_m
|
166
|
+
payment.save!
|
167
|
+
|
168
|
+
payment.set_afterpay(token: '1234')
|
169
|
+
|
170
|
+
params = { token: '1234', status: 'SUCCESS' }
|
171
|
+
|
172
|
+
ap_balance = order.total_price - 1.to_m
|
173
|
+
Workarea::Afterpay::BogusGateway.any_instance.stubs(:get_order).returns(get_order_response(ap_balance.to_s))
|
174
|
+
|
175
|
+
get storefront.complete_afterpay_path(params)
|
176
|
+
|
177
|
+
payment.reload
|
178
|
+
order.reload
|
179
|
+
|
180
|
+
assert(order.placed?)
|
181
|
+
transactions = payment.transactions
|
182
|
+
assert_equal(2, transactions.size)
|
183
|
+
|
184
|
+
ap_tender = payment.tenders.detect { |t| t.slug == :afterpay }
|
185
|
+
assert(ap_tender.transactions.first.success?)
|
186
|
+
assert_equal('purchase', ap_tender.transactions.first.action)
|
187
|
+
|
188
|
+
sc_tender = payment.tenders.detect { |t| t.slug == :store_credit }
|
189
|
+
assert(sc_tender.transactions.first.success?)
|
190
|
+
|
191
|
+
# Workarea v3.0.53, v3.1.40, v3.2.29, v3.3.21 and greater sets store credit to purchase by default.
|
192
|
+
assert_equal('purchase', sc_tender.transactions.first.action)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_failed_afterpay_capture
|
196
|
+
payment = Payment.find(order.id)
|
197
|
+
|
198
|
+
payment.set_afterpay(token: 'error_token')
|
199
|
+
|
200
|
+
params = { token: 'error_token', status: 'SUCCESS' }
|
201
|
+
|
202
|
+
get storefront.complete_afterpay_path(params)
|
203
|
+
|
204
|
+
payment.reload
|
205
|
+
order.reload
|
206
|
+
|
207
|
+
refute(order.placed?)
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
def order
|
213
|
+
@order ||= Order.first
|
214
|
+
end
|
215
|
+
|
216
|
+
def product
|
217
|
+
@product ||= create_product(
|
218
|
+
variants: [{ sku: 'SKU1', regular: 6.to_m, tax_code: '001' }]
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_order_response(amount)
|
223
|
+
b = {
|
224
|
+
"totalAmount": {
|
225
|
+
"amount": "#{amount}",
|
226
|
+
"currency": "USD"
|
227
|
+
}
|
228
|
+
}
|
229
|
+
Workarea::Afterpay::Response.new(response(b))
|
230
|
+
end
|
231
|
+
|
232
|
+
def response(body, status = 200)
|
233
|
+
response = Faraday.new do |builder|
|
234
|
+
builder.adapter :test do |stub|
|
235
|
+
stub.get("/v1/bogus") { |env| [ status, {}, body.to_json ] }
|
236
|
+
end
|
237
|
+
end
|
238
|
+
response.get("/v1/bogus")
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class AfterpayPaymentIntegrationTest < Workarea::TestCase
|
5
|
+
|
6
|
+
def test_capture
|
7
|
+
tender.amount = 5.to_m
|
8
|
+
transaction = tender.build_transaction(action: 'capture')
|
9
|
+
transaction.save!
|
10
|
+
|
11
|
+
operation = Payment::Capture::Afterpay.new(tender, transaction)
|
12
|
+
operation.complete!
|
13
|
+
|
14
|
+
assert(transaction.success?, 'expected transaction to be successful')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_auth
|
18
|
+
transaction = tender.build_transaction(action: 'authorize')
|
19
|
+
Payment::Authorize::Afterpay.new(tender, transaction).complete!
|
20
|
+
assert(transaction.success?, 'expected transaction to be successful')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_purchase
|
24
|
+
transaction = tender.build_transaction(action: 'purchase')
|
25
|
+
Payment::Purchase::Afterpay.new(tender, transaction).complete!
|
26
|
+
assert(transaction.success?)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def gateway
|
32
|
+
Workarea.Afterpay.gateay
|
33
|
+
end
|
34
|
+
|
35
|
+
def payment
|
36
|
+
@payment ||=
|
37
|
+
begin
|
38
|
+
profile = create_payment_profile
|
39
|
+
create_payment(
|
40
|
+
profile_id: profile.id,
|
41
|
+
address: {
|
42
|
+
first_name: 'Ben',
|
43
|
+
last_name: 'Crouse',
|
44
|
+
street: '22 s. 3rd st.',
|
45
|
+
city: 'Philadelphia',
|
46
|
+
region: 'PA',
|
47
|
+
postal_code: '19106',
|
48
|
+
country: Country['US']
|
49
|
+
}
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def tender
|
55
|
+
@tender ||=
|
56
|
+
begin
|
57
|
+
payment.set_address(first_name: 'Ben', last_name: 'Crouse')
|
58
|
+
|
59
|
+
payment.build_afterpay(
|
60
|
+
token: '12345'
|
61
|
+
)
|
62
|
+
|
63
|
+
payment.afterpay
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Afterpay
|
5
|
+
class OrderBuilderTest < Workarea::TestCase
|
6
|
+
|
7
|
+
def test_build
|
8
|
+
create_order_total_discount
|
9
|
+
order = create_order
|
10
|
+
|
11
|
+
# apply store credit
|
12
|
+
payment = Workarea::Payment.find(order.id)
|
13
|
+
payment.profile.update_attributes!(store_credit: 1.00)
|
14
|
+
payment.set_store_credit
|
15
|
+
payment.tenders.first.amount = 1.to_m
|
16
|
+
payment.save
|
17
|
+
|
18
|
+
order.reload
|
19
|
+
payment.reload
|
20
|
+
order_hash = Workarea::Afterpay::OrderBuilder.new(order).build
|
21
|
+
|
22
|
+
assert_equal(9.00, order_hash[:totalAmount][:amount].to_f)
|
23
|
+
assert_equal(1.00, order_hash[:shippingAmount][:amount].to_f)
|
24
|
+
assert_equal(0.00, order_hash[:taxAmount][:amount].to_f)
|
25
|
+
assert_equal(order.id, order_hash[:merchantReference])
|
26
|
+
|
27
|
+
assert_equal("bcrouse-new@workarea.com", order_hash[:consumer][:email])
|
28
|
+
assert_equal("Ben", order_hash[:consumer][:givenNames])
|
29
|
+
assert_equal("Crouse", order_hash[:consumer][:surname])
|
30
|
+
|
31
|
+
assert_equal(1, order_hash[:discounts].size)
|
32
|
+
assert_equal("Order Total Discount", order_hash[:discounts].first[:displayName])
|
33
|
+
|
34
|
+
assert_equal("Philadelphia", order_hash[:shipping][:suburb])
|
35
|
+
assert_equal("Wilmington", order_hash[:billing][:suburb])
|
36
|
+
|
37
|
+
assert_equal(1, order_hash[:items].size)
|
38
|
+
assert_equal("SKU", order_hash[:items].first[:sku])
|
39
|
+
assert_equal(2, order_hash[:items].first[:quantity])
|
40
|
+
assert_equal(5, order_hash[:items].first[:price][:amount].to_f)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def create_order(overrides = {})
|
46
|
+
attributes = {
|
47
|
+
id: '1234',
|
48
|
+
email: 'bcrouse-new@workarea.com',
|
49
|
+
placed_at: Time.current
|
50
|
+
}.merge(overrides)
|
51
|
+
|
52
|
+
shipping_service = create_shipping_service
|
53
|
+
product = create_product(variants: [{ sku: 'SKU', regular: 5.to_m }])
|
54
|
+
|
55
|
+
order = Workarea::Order.new(attributes)
|
56
|
+
order.add_item(product_id: product.id, sku: 'SKU', quantity: 2)
|
57
|
+
|
58
|
+
checkout = Checkout.new(order)
|
59
|
+
checkout.update(
|
60
|
+
shipping_address: {
|
61
|
+
first_name: 'Ben',
|
62
|
+
last_name: 'Crouse',
|
63
|
+
street: '22 S. 3rd St.',
|
64
|
+
street_2: 'Second Floor',
|
65
|
+
city: 'Philadelphia',
|
66
|
+
region: 'PA',
|
67
|
+
postal_code: '19106',
|
68
|
+
country: 'US'
|
69
|
+
},
|
70
|
+
billing_address: {
|
71
|
+
first_name: 'Bob',
|
72
|
+
last_name: 'Clams',
|
73
|
+
street: '12 N. 3rd St.',
|
74
|
+
street_2: 'Second Floor',
|
75
|
+
city: 'Wilmington',
|
76
|
+
region: 'DE',
|
77
|
+
postal_code: '18083',
|
78
|
+
country: 'US'
|
79
|
+
},
|
80
|
+
shipping_service: shipping_service.name,
|
81
|
+
)
|
82
|
+
|
83
|
+
|
84
|
+
order
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class AfterpayProductText < Workarea::SystemTest
|
6
|
+
include Storefront::SystemTest
|
7
|
+
|
8
|
+
def test_showing_a_products_afterpay_price
|
9
|
+
@product = create_product(
|
10
|
+
name: 'Integration Product',
|
11
|
+
variants: [{ sku: 'SKU1', regular: 100.to_m }]
|
12
|
+
)
|
13
|
+
|
14
|
+
visit storefront.product_path(@product)
|
15
|
+
assert(page.has_content?(t('workarea.storefront.products.afterpay', installment_price: '$25.00', installment_count: Workarea.config.afterpay[:installment_count])))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_eneligble_product_total
|
19
|
+
@product = create_product(
|
20
|
+
name: 'Integration Product',
|
21
|
+
variants: [{ sku: 'SKU1', regular: 1.to_m }]
|
22
|
+
)
|
23
|
+
|
24
|
+
visit storefront.product_path(@product)
|
25
|
+
refute(page.has_content?(t('workarea.storefront.products.afterpay', installment_price: '$0.25', installment_count: Workarea.config.afterpay[:installment_count])))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_global_display_settings
|
29
|
+
Workarea::Afterpay::Configuration.create(enabled: false)
|
30
|
+
@product = create_product(
|
31
|
+
name: 'Integration Product',
|
32
|
+
variants: [{ sku: 'SKU1', regular: 100.to_m }]
|
33
|
+
)
|
34
|
+
|
35
|
+
visit storefront.product_path(@product)
|
36
|
+
refute(page.has_content?(t('workarea.storefront.products.afterpay', installment_price: '$25.00', installment_count: Workarea.config.afterpay[:installment_count])))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_pdp_display_settings
|
40
|
+
Workarea::Afterpay::Configuration.create(display_on_pdp: false)
|
41
|
+
@product = create_product(
|
42
|
+
name: 'Integration Product',
|
43
|
+
variants: [{ sku: 'SKU1', regular: 100.to_m }]
|
44
|
+
)
|
45
|
+
|
46
|
+
visit storefront.product_path(@product)
|
47
|
+
refute(page.has_content?(t('workarea.storefront.products.afterpay', installment_price: '$25.00', installment_count: Workarea.config.afterpay[:installment_count])))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
decorate Storefront::CartSystemTest, with: :afterpay do
|
5
|
+
def test_afterpay_content
|
6
|
+
visit storefront.product_path(@product)
|
7
|
+
select @product.skus.first, from: 'sku'
|
8
|
+
click_button t('workarea.storefront.products.add_to_cart')
|
9
|
+
click_link t('workarea.storefront.carts.view_cart')
|
10
|
+
|
11
|
+
assert(page.has_content?(t('workarea.storefront.carts.afterpay', installment_price: '$1.25', installment_count: Workarea.config.afterpay[:installment_count])))
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_afterpay_price_ineligibility
|
15
|
+
product = create_product(
|
16
|
+
name: 'Integration Product 2',
|
17
|
+
variants: [
|
18
|
+
{ name: 'SKU3', sku: 'SKU3', regular: 1.to_m },
|
19
|
+
{ name: 'SKU4', sku: 'SKU4', regular: 2.to_m }
|
20
|
+
]
|
21
|
+
)
|
22
|
+
|
23
|
+
visit storefront.product_path(product)
|
24
|
+
select product.skus.first, from: 'sku'
|
25
|
+
click_button t('workarea.storefront.products.add_to_cart')
|
26
|
+
click_link t('workarea.storefront.carts.view_cart')
|
27
|
+
|
28
|
+
assert(page.has_content?(t('workarea.storefront.afterpay.ineligible_order_total', min: '$5.00', max: '$500.00')))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_afterpay_country_ineligibility
|
32
|
+
Workarea.with_config do |config|
|
33
|
+
config.afterpay.api_timeout = 5
|
34
|
+
config.afterpay.open_timeout = 2
|
35
|
+
config.afterpay.currency_country_map = {
|
36
|
+
"GBP": "GB"
|
37
|
+
}
|
38
|
+
|
39
|
+
config.afterpay.test = true
|
40
|
+
config.afterpay.enabled = {
|
41
|
+
au: true,
|
42
|
+
us: true
|
43
|
+
}
|
44
|
+
|
45
|
+
product = create_product(
|
46
|
+
name: 'Integration Product 2',
|
47
|
+
variants: [
|
48
|
+
{ name: 'SKU3', sku: 'SKU3', regular: 1.to_m },
|
49
|
+
{ name: 'SKU4', sku: 'SKU4', regular: 2.to_m }
|
50
|
+
]
|
51
|
+
)
|
52
|
+
|
53
|
+
visit storefront.product_path(product)
|
54
|
+
select product.skus.first, from: 'sku'
|
55
|
+
click_button t('workarea.storefront.products.add_to_cart')
|
56
|
+
click_link t('workarea.storefront.carts.view_cart')
|
57
|
+
|
58
|
+
refute(page.has_content?(t('workarea.storefront.afterpay.ineligible_order_total', min: '$5.00', max: '$500.00')))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_global_display_settings
|
63
|
+
Workarea::Afterpay::Configuration.create(enabled: false)
|
64
|
+
visit storefront.product_path(@product)
|
65
|
+
select @product.skus.first, from: 'sku'
|
66
|
+
click_button t('workarea.storefront.products.add_to_cart')
|
67
|
+
click_link t('workarea.storefront.carts.view_cart')
|
68
|
+
|
69
|
+
refute(page.has_content?(t('workarea.storefront.carts.afterpay', installment_price: '$1.25', installment_count: Workarea.config.afterpay[:installment_count])))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_cart_display_settings
|
73
|
+
Workarea::Afterpay::Configuration.create(display_on_cart: false)
|
74
|
+
visit storefront.product_path(@product)
|
75
|
+
select @product.skus.first, from: 'sku'
|
76
|
+
click_button t('workarea.storefront.products.add_to_cart')
|
77
|
+
click_link t('workarea.storefront.carts.view_cart')
|
78
|
+
|
79
|
+
refute(page.has_content?(t('workarea.storefront.carts.afterpay', installment_price: '$1.25', installment_count: Workarea.config.afterpay[:installment_count])))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
decorate Storefront::LoggedInCheckoutSystemTest, with: :afterpay do
|
5
|
+
def test_afterpay_option_in_checkout
|
6
|
+
assert(page.has_content?(t('workarea.storefront.afterpay.on_continue')))
|
7
|
+
assert(page.has_content?(t('workarea.storefront.checkouts.afterpay', installment_price: '$3.21', installment_count: Workarea.config.afterpay[:installment_count])))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
|
+
|
4
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
5
|
+
require 'rails/test_help'
|
6
|
+
require 'workarea/test_help'
|
7
|
+
|
8
|
+
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
9
|
+
# to be shown.
|
10
|
+
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class AfterpayViewModelTest < TestCase
|
6
|
+
setup :set_checkout
|
7
|
+
|
8
|
+
def set_checkout
|
9
|
+
@order = Order.new(email: 'bcrouse@workarea.com')
|
10
|
+
@user = User.new(email: 'bcrouse@workarea.com')
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_order_total_in_range
|
14
|
+
@order.total_price = 25.00
|
15
|
+
|
16
|
+
checkout = Workarea::Checkout.new(@order, @user)
|
17
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
18
|
+
|
19
|
+
assert(view_model.order_total_in_range?)
|
20
|
+
|
21
|
+
@order.total_price = 15.00
|
22
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
23
|
+
refute(view_model.order_total_in_range?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_show?
|
27
|
+
settings = Workarea::Afterpay::Configuration.create!
|
28
|
+
|
29
|
+
@order.total_price = 25.00
|
30
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(nil, { afterpay_configuration: afterpay_options, order: @order })
|
31
|
+
assert(view_model.show?)
|
32
|
+
|
33
|
+
settings.enabled = false
|
34
|
+
settings.save!
|
35
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(nil, { afterpay_configuration: afterpay_options, order: @order })
|
36
|
+
refute(view_model.show?)
|
37
|
+
|
38
|
+
@order.total_price = 25.00.to_m("EUR")
|
39
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(nil, { afterpay_configuration: afterpay_options, order: @order })
|
40
|
+
refute(view_model.show?)
|
41
|
+
|
42
|
+
Workarea::Order.any_instance.stubs(:currency).returns("EUR")
|
43
|
+
@order.total_price = 25.00
|
44
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(nil, { afterpay_configuration: afterpay_options, order: @order })
|
45
|
+
refute(view_model.show?)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_afterpay_country
|
49
|
+
checkout = Workarea::Checkout.new(@order, @user)
|
50
|
+
|
51
|
+
@order.total_price = 25.00
|
52
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
53
|
+
assert_equal('US', view_model.afterpay_country)
|
54
|
+
|
55
|
+
@order.total_price = 25.00.to_m('AUD')
|
56
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
57
|
+
assert_equal('AU', view_model.afterpay_country)
|
58
|
+
|
59
|
+
@order.total_price = 25.00.to_m('EUR')
|
60
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
61
|
+
refute(view_model.afterpay_country.present?)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_display_options
|
65
|
+
@order.total_price = 25.00
|
66
|
+
|
67
|
+
checkout = Workarea::Checkout.new(@order, @user)
|
68
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(checkout, { afterpay_configuration: afterpay_options, order: @order })
|
69
|
+
|
70
|
+
assert_equal("PAY_BY_INSTALLMENT", view_model.display_option[:type])
|
71
|
+
assert_equal("Pay over time", view_model.display_option[:description])
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_installment_price
|
75
|
+
@order.total_price = 100.00
|
76
|
+
view_model = Workarea::Storefront::AfterpayViewModel.new(nil, { afterpay_configuration: afterpay_options, order: @order })
|
77
|
+
|
78
|
+
assert_equal(25.00, view_model.installment_price.amount)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def afterpay_options
|
83
|
+
[
|
84
|
+
{
|
85
|
+
"type": "PAY_BY_INSTALLMENT",
|
86
|
+
"description": "Pay over time",
|
87
|
+
"minimumAmount": {
|
88
|
+
"amount": "20.00",
|
89
|
+
"currency": "USD"
|
90
|
+
},
|
91
|
+
"maximumAmount": {
|
92
|
+
"amount": "30.00",
|
93
|
+
"currency": "USD"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|