workarea-paypal 2.0.8
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/.eslintignore +2 -0
- data/.eslintrc +24 -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 +19 -0
- data/.rspec +2 -0
- data/.scss-lint.yml +188 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +314 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +6 -0
- data/LICENSE +52 -0
- data/README.md +47 -0
- data/Rakefile +54 -0
- data/app/assets/images/workarea/admin/payment_icons/paypal.svg +1 -0
- data/app/assets/images/workarea/storefront/payment_icons/paypal.svg +1 -0
- data/app/assets/javascripts/workarea/storefront/paypal/modules/update_checkout_submit_text.js +60 -0
- data/app/controllers/workarea/storefront/checkout/place_order_controller.decorator +13 -0
- data/app/controllers/workarea/storefront/paypal_controller.rb +51 -0
- data/app/models/workarea/payment.decorator +27 -0
- data/app/models/workarea/payment/authorize/paypal.rb +31 -0
- data/app/models/workarea/payment/capture/paypal.rb +35 -0
- data/app/models/workarea/payment/purchase/paypal.rb +31 -0
- data/app/models/workarea/payment/refund/paypal.rb +26 -0
- data/app/models/workarea/payment/tender/paypal.rb +11 -0
- data/app/models/workarea/search/order_text.decorator +8 -0
- data/app/services/workarea/paypal/setup.rb +114 -0
- data/app/services/workarea/paypal/update.rb +69 -0
- data/app/view_models/workarea/admin/paypal_view_model.rb +6 -0
- data/app/view_models/workarea/store_front/checkout/payment_view_model.decorator +18 -0
- data/app/view_models/workarea/store_front/credit_card_view_model.decorator +7 -0
- data/app/view_models/workarea/store_front/paypal_view_model.rb +6 -0
- data/app/views/workarea/admin/orders/tenders/_paypal.html.haml +2 -0
- data/app/views/workarea/api/orders/tenders/_paypal.json.jbuilder +3 -0
- data/app/views/workarea/storefront/carts/_paypal_checkout.html.haml +1 -0
- data/app/views/workarea/storefront/checkouts/_paypal_error.html.haml +6 -0
- data/app/views/workarea/storefront/checkouts/_paypal_payment.html.haml +12 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_paypal.html.haml +3 -0
- data/app/views/workarea/storefront/order_mailer/tenders/_paypal.text.haml +2 -0
- data/app/views/workarea/storefront/orders/tenders/_paypal.html.haml +2 -0
- data/bin/rails +17 -0
- data/config/initializers/append_points.rb +19 -0
- data/config/initializers/workarea.rb +7 -0
- data/config/locales/en.yml +19 -0
- data/config/routes.rb +4 -0
- data/lib/workarea/paypal.rb +34 -0
- data/lib/workarea/paypal/engine.rb +8 -0
- data/lib/workarea/paypal/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -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 +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +24 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -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 +21 -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 +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/workarea/storefront/paypal_integration_test.rb +345 -0
- data/test/integration/workarea/storefront/place_order_integration_test.decorator +11 -0
- data/test/models/workarea/payment/authorize/paypal_test.rb +94 -0
- data/test/models/workarea/payment/capture/paypal_test.rb +69 -0
- data/test/models/workarea/payment/purchase/paypal_test.rb +94 -0
- data/test/models/workarea/payment/refund/paypal_test.rb +69 -0
- data/test/models/workarea/payment_test.decorator +34 -0
- data/test/models/workarea/search/admin/order_test.decorator +32 -0
- data/test/services/workarea/paypal/setup_test.rb +120 -0
- data/test/services/workarea/paypal/update_test.rb +221 -0
- data/test/system/workarea/storefront/cart_system_test.decorator +14 -0
- data/test/system/workarea/storefront/logged_in_checkout_system_test.decorator +9 -0
- data/test/test_helper.rb +10 -0
- data/workarea-paypal.gemspec +21 -0
- metadata +170 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains migration options to ease your Rails 5.0 upgrade.
|
4
|
+
#
|
5
|
+
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
|
6
|
+
|
7
|
+
# Enable per-form CSRF tokens. Previous versions had false.
|
8
|
+
Rails.application.config.action_controller.per_form_csrf_tokens = true
|
9
|
+
|
10
|
+
# Enable origin-checking CSRF mitigation. Previous versions had false.
|
11
|
+
Rails.application.config.action_controller.forgery_protection_origin_check = true
|
12
|
+
|
13
|
+
# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
|
14
|
+
# Previous versions had false.
|
15
|
+
ActiveSupport.to_time_preserves_timezone = true
|
16
|
+
|
17
|
+
# Require `belongs_to` associations by default. Previous versions had false.
|
18
|
+
# Rails.application.config.active_record.belongs_to_required_by_default = true
|
19
|
+
|
20
|
+
# Configure SSL options to enable HSTS with subdomains. Previous versions had false.
|
21
|
+
Rails.application.config.ssl_options = { hsts: { subdomains: true } }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Puma can serve each request in a thread from an internal thread pool.
|
2
|
+
# The `threads` method setting takes two numbers a minimum and maximum.
|
3
|
+
# Any libraries that use thread pools should be configured to match
|
4
|
+
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
|
+
# and maximum, this matches the default thread size of Active Record.
|
6
|
+
#
|
7
|
+
threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i
|
8
|
+
threads threads_count, threads_count
|
9
|
+
|
10
|
+
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
|
11
|
+
#
|
12
|
+
port ENV.fetch('PORT') { 3000 }
|
13
|
+
|
14
|
+
# Specifies the `environment` that Puma will run in.
|
15
|
+
#
|
16
|
+
environment ENV.fetch('RAILS_ENV') { 'development' }
|
17
|
+
|
18
|
+
# Specifies the number of `workers` to boot in clustered mode.
|
19
|
+
# Workers are forked webserver processes. If using threads and workers together
|
20
|
+
# the concurrency of the application would be max `threads` * `workers`.
|
21
|
+
# Workers do not work on JRuby or Windows (both of which do not support
|
22
|
+
# processes).
|
23
|
+
#
|
24
|
+
# workers ENV.fetch('WEB_CONCURRENCY') { 2 }
|
25
|
+
|
26
|
+
# Use the `preload_app!` method when specifying a `workers` number.
|
27
|
+
# This directive tells Puma to first boot the application and load code
|
28
|
+
# before forking the application. This takes advantage of Copy On Write
|
29
|
+
# process behavior so workers use less memory. If you use this option
|
30
|
+
# you need to make sure to reconnect any threads in the `on_worker_boot`
|
31
|
+
# block.
|
32
|
+
#
|
33
|
+
# preload_app!
|
34
|
+
|
35
|
+
# The code in the `on_worker_boot` will be called if you are using
|
36
|
+
# clustered mode by specifying a number of `workers`. After each worker
|
37
|
+
# process is booted this block will be run, if you are using `preload_app!`
|
38
|
+
# option you will want to use this block to reconnect to any threads
|
39
|
+
# or connections that may have been created at application boot, Ruby
|
40
|
+
# cannot share connections between processes.
|
41
|
+
#
|
42
|
+
# on_worker_boot do
|
43
|
+
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
44
|
+
# end
|
45
|
+
|
46
|
+
# Allow puma to be restarted by `rails restart` command.
|
47
|
+
plugin :tmp_restart
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rails secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 02c581b9857245e8095f3858b8c5753467b49512cc7b0221dab82d105e95a7e7706a5880b17852093e5b4d390092f8c4b74c12745d10eef6a81baa7f6e4bf48c
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 2408da5677ca9c54a3f19a7202ce0f12a8b2c33d251846919617aeb97fcd2fe3e3f79c05aaa04d4536be5b85434c18462be9ce62e0ea422f087917086e7a4b95
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,345 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class PaypalIntengrationTest < Workarea::IntegrationTest
|
6
|
+
delegate :gateway, to: Workarea::Paypal
|
7
|
+
|
8
|
+
setup :stub_paypal_setup_redirect_url
|
9
|
+
|
10
|
+
def test_start_starts_checkout_when_guest
|
11
|
+
add_item_to_cart
|
12
|
+
Workarea::Checkout.any_instance.expects(:start_as).with(:guest)
|
13
|
+
get storefront.start_paypal_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_start_starts_checkout_when_logged_in
|
17
|
+
add_item_to_cart
|
18
|
+
user = User.new
|
19
|
+
|
20
|
+
Workarea::Storefront::PaypalController
|
21
|
+
.any_instance
|
22
|
+
.stubs(:current_user)
|
23
|
+
.returns(user)
|
24
|
+
|
25
|
+
Workarea::Checkout.any_instance.expects(:start_as).with(user)
|
26
|
+
get storefront.start_paypal_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_start_does_not_start_checkout_from_checkout
|
30
|
+
add_item_to_cart
|
31
|
+
Workarea::Checkout.any_instance.expects(:start_as).never
|
32
|
+
|
33
|
+
get storefront.start_paypal_path, params: { from_checkout: 'from_checkout' }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_start_prices_the_order
|
37
|
+
add_item_to_cart
|
38
|
+
Workarea::Pricing.expects(:perform)
|
39
|
+
|
40
|
+
get storefront.start_paypal_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_start_uses_setup_to_redirect
|
44
|
+
add_item_to_cart
|
45
|
+
get storefront.start_paypal_path
|
46
|
+
assert_redirected_to('http://paypal.com')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_start_redirects_to_cart_if_empty
|
50
|
+
get storefront.start_paypal_path
|
51
|
+
assert_redirected_to(storefront.cart_path)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_start_rdirects_to_cart_if_inventory_is_not_available
|
55
|
+
product = create_product(variants: [{ sku: 'SKU', regular: 5 }])
|
56
|
+
|
57
|
+
post storefront.cart_items_path, params: {
|
58
|
+
product_id: product.id,
|
59
|
+
sku: product.skus.first,
|
60
|
+
quantity: 1
|
61
|
+
}
|
62
|
+
|
63
|
+
create_inventory(
|
64
|
+
id: product.skus.first,
|
65
|
+
policy: 'standard',
|
66
|
+
available: 0
|
67
|
+
)
|
68
|
+
|
69
|
+
get storefront.start_paypal_path
|
70
|
+
assert_redirected_to(storefront.cart_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_complete_sets_the_current_order
|
74
|
+
add_item_to_cart
|
75
|
+
stub_paypal_update_apply
|
76
|
+
Workarea::Storefront::PaypalController
|
77
|
+
.any_instance
|
78
|
+
.expects(:current_order=)
|
79
|
+
get storefront.complete_paypal_path(order_id: order.id)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_complete_applies_a_paupal_update
|
83
|
+
add_item_to_cart
|
84
|
+
Workarea::Paypal::Update
|
85
|
+
.any_instance
|
86
|
+
.expects(:apply)
|
87
|
+
|
88
|
+
get storefront.complete_paypal_path(order_id: order.id)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_complete_redirects_to_checkout_path
|
92
|
+
add_item_to_cart
|
93
|
+
stub_paypal_update_apply
|
94
|
+
Workarea::Checkout
|
95
|
+
.any_instance
|
96
|
+
.stubs(:complete?)
|
97
|
+
.returns(true)
|
98
|
+
get storefront.complete_paypal_path(order_id: order.id)
|
99
|
+
assert_redirected_to(storefront.checkout_payment_path)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_complete_redirects_to_payment_as_purchasable
|
103
|
+
shipping_method = create_shipping_service
|
104
|
+
product = create_product(variants: [{ sku: 'SKU', regular: 49.to_m }])
|
105
|
+
|
106
|
+
post storefront.cart_items_path, params: {
|
107
|
+
product_id: product.id,
|
108
|
+
sku: product.skus.first,
|
109
|
+
quantity: 2
|
110
|
+
}
|
111
|
+
|
112
|
+
order = Workarea::Order.last
|
113
|
+
|
114
|
+
Workarea::Shipping.find_or_create_by(id: order.id)
|
115
|
+
Workarea::Payment.find_or_create_by(id: order.id)
|
116
|
+
|
117
|
+
checkout = Workarea::Checkout.new(order)
|
118
|
+
checkout.update(
|
119
|
+
shipping_address: {
|
120
|
+
first_name: 'Test',
|
121
|
+
last_name: 'User',
|
122
|
+
street: '1 Main St',
|
123
|
+
street_2: nil,
|
124
|
+
city: 'San Jose',
|
125
|
+
region: 'CA',
|
126
|
+
postal_code: '95131',
|
127
|
+
country: 'US'
|
128
|
+
},
|
129
|
+
billing_address: {
|
130
|
+
first_name: 'Test',
|
131
|
+
last_name: 'User',
|
132
|
+
street: '1 Main St',
|
133
|
+
street_2: nil,
|
134
|
+
city: 'San Jose',
|
135
|
+
region: 'CA',
|
136
|
+
postal_code: '95131',
|
137
|
+
country: 'US'
|
138
|
+
},
|
139
|
+
shipping_method_id: shipping_method.id,
|
140
|
+
payment: 'paypal'
|
141
|
+
)
|
142
|
+
|
143
|
+
gateway.expects(:details_for).returns(details)
|
144
|
+
|
145
|
+
get storefront.complete_paypal_path(order_id: order.id)
|
146
|
+
|
147
|
+
assert_redirected_to(storefront.checkout_payment_path)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_complete_redirects_to_address_if_paypal_address_invalid
|
151
|
+
details.params['PaymentDetails']['ShipToAddress'] = {
|
152
|
+
'Name' => 'Test User',
|
153
|
+
'Street1' => 'PO Box 123',
|
154
|
+
'Street2' => nil,
|
155
|
+
'CityName' => 'San Jose',
|
156
|
+
'StateOrProvince' => 'CA',
|
157
|
+
'Country' => 'US',
|
158
|
+
'CountryName' => 'United States',
|
159
|
+
'Phone' => '610-867-5309',
|
160
|
+
'PostalCode' => '95131',
|
161
|
+
'AddressID' => nil,
|
162
|
+
'AddressOwner' => 'PayPal',
|
163
|
+
'ExternalAddressID' => nil,
|
164
|
+
'AddressStatus' => 'Confirmed'
|
165
|
+
}
|
166
|
+
|
167
|
+
gateway.expects(:details_for).returns(details)
|
168
|
+
|
169
|
+
product = create_product(variants: [{ sku: 'SKU', regular: 5 }])
|
170
|
+
|
171
|
+
post storefront.cart_items_path, params: {
|
172
|
+
product_id: product.id,
|
173
|
+
sku: product.skus.first,
|
174
|
+
quantity: 1
|
175
|
+
}
|
176
|
+
|
177
|
+
order = Order.first
|
178
|
+
|
179
|
+
get storefront.complete_paypal_path(order_id: order.id)
|
180
|
+
assert_redirected_to(storefront.checkout_addresses_path)
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
def order
|
186
|
+
@order ||= create_order
|
187
|
+
end
|
188
|
+
|
189
|
+
def product
|
190
|
+
@product ||= create_product(
|
191
|
+
variants: [{ sku: 'SKU1', regular: 6.to_m, tax_code: '001' }]
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
def details
|
196
|
+
@details ||= stub(
|
197
|
+
email: 'bcrouse@workarea.com',
|
198
|
+
token: 'EC-3LX76108SH791964A',
|
199
|
+
payer_id: 'MDJZZYJ9SZJ52',
|
200
|
+
params: {
|
201
|
+
'timestamp' => '2012-02-16T15:22:17Z',
|
202
|
+
'ack' => 'Success',
|
203
|
+
'correlation_id' => 'e5e29daee048a',
|
204
|
+
'version' => '62.0',
|
205
|
+
'build' => '2571254',
|
206
|
+
'token' => 'EC-3LX76108SH791964A',
|
207
|
+
'payer' => 'bcrouse@workarea.com',
|
208
|
+
'payer_id' => 'MDJZZYJ9SZJ52',
|
209
|
+
'payer_status' => 'verified',
|
210
|
+
'salutation' => nil,
|
211
|
+
'first_name' => 'Test',
|
212
|
+
'middle_name' => nil,
|
213
|
+
'last_name' => 'User',
|
214
|
+
'suffix' => nil,
|
215
|
+
'payer_country' => 'US',
|
216
|
+
'payer_business' => nil,
|
217
|
+
'name' => 'Test Product 866',
|
218
|
+
'street1' => '1 Main St',
|
219
|
+
'street2' => nil,
|
220
|
+
'city_name' => 'San Jose',
|
221
|
+
'state_or_province' => 'CA',
|
222
|
+
'country' => 'US',
|
223
|
+
'country_name' => 'United States',
|
224
|
+
'postal_code' => '95131',
|
225
|
+
'address_owner' => 'PayPal',
|
226
|
+
'address_status' => 'Confirmed',
|
227
|
+
'order_total' => '98.00',
|
228
|
+
'order_total_currency_id' => 'USD',
|
229
|
+
'item_total' => '98.00',
|
230
|
+
'item_total_currency_id' => 'USD',
|
231
|
+
'shipping_total' => '0.00',
|
232
|
+
'shipping_total_currency_id' => 'USD',
|
233
|
+
'handling_total' => '0.00',
|
234
|
+
'handling_total_currency_id' => 'USD',
|
235
|
+
'tax_total' => '0.00',
|
236
|
+
'tax_total_currency_id' => 'USD',
|
237
|
+
'phone' => nil,
|
238
|
+
'address_id' => nil,
|
239
|
+
'external_address_id' => nil,
|
240
|
+
'quantity' => '2',
|
241
|
+
'tax' => '0.00',
|
242
|
+
'tax_currency_id' => 'USD',
|
243
|
+
'amount' => '49.00',
|
244
|
+
'amount_currency_id' => 'USD',
|
245
|
+
'ebay_item_payment_details_item' => nil,
|
246
|
+
'insurance_total' => '0.00',
|
247
|
+
'insurance_total_currency_id' => 'USD',
|
248
|
+
'shipping_discount' => '0.00',
|
249
|
+
'shipping_discount_currency_id' => 'USD',
|
250
|
+
'insurance_option_offered' => 'false',
|
251
|
+
'seller_details' => nil,
|
252
|
+
'payment_request_id' => nil,
|
253
|
+
'order_url' => nil,
|
254
|
+
'soft_descriptor' => nil,
|
255
|
+
'checkout_status' => 'PaymentActionNotInitiated',
|
256
|
+
'Token' => 'EC-3LX76108SH791964A',
|
257
|
+
'PayerInfo' => {
|
258
|
+
'Payer' => 'bcrouse@workarea.com',
|
259
|
+
'PayerID' => 'MDJZZYJ9SZJ52',
|
260
|
+
'PayerStatus' => 'verified',
|
261
|
+
'PayerName' => {
|
262
|
+
'Salutation' => nil,
|
263
|
+
'FirstName' => 'Test',
|
264
|
+
'MiddleName' => nil,
|
265
|
+
'LastName' => 'User',
|
266
|
+
'Suffix' => nil
|
267
|
+
},
|
268
|
+
'PayerCountry' => 'US',
|
269
|
+
'PayerBusiness' => nil,
|
270
|
+
'Address' => {
|
271
|
+
'Name' => 'Test User',
|
272
|
+
'Street1' => '1 Main St',
|
273
|
+
'Street2' => nil,
|
274
|
+
'CityName' => 'San Jose',
|
275
|
+
'StateOrProvince' => 'CA',
|
276
|
+
'Country' => 'US',
|
277
|
+
'CountryName' => 'United States',
|
278
|
+
'PostalCode' => '95131',
|
279
|
+
'AddressOwner' => 'PayPal',
|
280
|
+
'AddressStatus' => 'Confirmed'
|
281
|
+
}
|
282
|
+
},
|
283
|
+
'PaymentDetails' => {
|
284
|
+
'OrderTotal' => '98.00',
|
285
|
+
'ItemTotal' => '98.00',
|
286
|
+
'ShippingTotal' => '0.00',
|
287
|
+
'HandlingTotal' => '0.00',
|
288
|
+
'TaxTotal' => '0.00',
|
289
|
+
'ShipToAddress' => {
|
290
|
+
'Name' => 'Test User',
|
291
|
+
'Street1' => '1 Main St',
|
292
|
+
'Street2' => nil,
|
293
|
+
'CityName' => 'San Jose',
|
294
|
+
'StateOrProvince' => 'CA',
|
295
|
+
'Country' => 'US',
|
296
|
+
'CountryName' => 'United States',
|
297
|
+
'PostalCode' => '95131',
|
298
|
+
'AddressID' => nil,
|
299
|
+
'AddressOwner' => 'PayPal',
|
300
|
+
'ExternalAddressID' => nil,
|
301
|
+
'AddressStatus' => 'Confirmed'
|
302
|
+
},
|
303
|
+
'PaymentDetailsItem' => {
|
304
|
+
'Name' => 'Test Product 866',
|
305
|
+
'Quantity' => '2',
|
306
|
+
'Tax' => '0.00',
|
307
|
+
'Amount' => '49.00',
|
308
|
+
'EbayItemPaymentDetailsItem' => nil
|
309
|
+
},
|
310
|
+
'InsuranceTotal' => '0.00',
|
311
|
+
'ShippingDiscount' => '0.00',
|
312
|
+
'InsuranceOptionOffered' => 'false',
|
313
|
+
'SellerDetails' => nil,
|
314
|
+
'PaymentRequestID' => nil,
|
315
|
+
'OrderURL' => nil,
|
316
|
+
'SoftDescriptor' => nil
|
317
|
+
},
|
318
|
+
'CheckoutStatus' => 'PaymentActionNotInitiated'
|
319
|
+
}
|
320
|
+
)
|
321
|
+
end
|
322
|
+
|
323
|
+
def add_item_to_cart
|
324
|
+
post storefront.cart_items_path, params: {
|
325
|
+
product_id: product.id,
|
326
|
+
sku: product.skus.first,
|
327
|
+
quantity: 2
|
328
|
+
}
|
329
|
+
end
|
330
|
+
|
331
|
+
def stub_paypal_setup_redirect_url
|
332
|
+
Workarea::Paypal::Setup
|
333
|
+
.any_instance
|
334
|
+
.stubs(:redirect_url)
|
335
|
+
.returns('http://paypal.com')
|
336
|
+
end
|
337
|
+
|
338
|
+
def stub_paypal_update_apply
|
339
|
+
Workarea::Paypal::Update
|
340
|
+
.any_instance
|
341
|
+
.stubs(:apply)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|