workarea-paypal 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,11 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
decorate Storefront::PlaceOrderIntegrationTest, with: :paypal do
|
|
5
|
+
def test_place_order_redirects_to_paypal
|
|
6
|
+
patch storefront.checkout_place_order_path, params: { payment: 'paypal' }
|
|
7
|
+
|
|
8
|
+
assert_redirected_to(storefront.start_paypal_path)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
class Payment
|
|
5
|
+
module Authorize
|
|
6
|
+
class PaypalTest < Workarea::TestCase
|
|
7
|
+
delegate :gateway, to: Workarea::Paypal
|
|
8
|
+
|
|
9
|
+
def payment
|
|
10
|
+
@payment ||= create_payment
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def authorization
|
|
14
|
+
@authorization ||= ActiveMerchant::Billing::BogusGateway::AUTHORIZATION
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def tender
|
|
18
|
+
@tender ||=
|
|
19
|
+
begin
|
|
20
|
+
payment.set_address(first_name: 'Ben', last_name: 'Crouse')
|
|
21
|
+
payment.build_paypal(token: '1234', payer_id: 'pid')
|
|
22
|
+
payment.paypal
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def transaction
|
|
27
|
+
@transaction ||= tender.transactions.build(
|
|
28
|
+
action: 'authorize',
|
|
29
|
+
amount: 5.to_m
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_complete_authorizes_on_the_paypal_gateway
|
|
34
|
+
operation = Paypal.new(tender, transaction)
|
|
35
|
+
|
|
36
|
+
gateway.expects(:authorize)
|
|
37
|
+
|
|
38
|
+
operation.complete!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_complete_sets_the_response_on_the_transaction
|
|
42
|
+
operation = Paypal.new(tender, transaction)
|
|
43
|
+
operation.complete!
|
|
44
|
+
|
|
45
|
+
assert_instance_of(
|
|
46
|
+
ActiveMerchant::Billing::Response,
|
|
47
|
+
transaction.response
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_cancel_does_nothing_if_the_transaction_was_a_failure
|
|
52
|
+
transaction.success = false
|
|
53
|
+
operation = Paypal.new(tender, transaction)
|
|
54
|
+
|
|
55
|
+
operation.gateway.expects(:void).never
|
|
56
|
+
operation.cancel!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_cancel_voids_with_the_authorization_from_the_transaction
|
|
60
|
+
transaction.response = ActiveMerchant::Billing::Response.new(
|
|
61
|
+
true,
|
|
62
|
+
'Message',
|
|
63
|
+
'transaction_id' => authorization
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
operation = Paypal.new(tender, transaction)
|
|
67
|
+
|
|
68
|
+
operation
|
|
69
|
+
.gateway
|
|
70
|
+
.expects(:void)
|
|
71
|
+
.with(authorization)
|
|
72
|
+
|
|
73
|
+
operation.cancel!
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_cancel_sets_cancellation_params_on_the_transaction
|
|
77
|
+
transaction.response = ActiveMerchant::Billing::Response.new(
|
|
78
|
+
true,
|
|
79
|
+
'Message',
|
|
80
|
+
'transaction_id' => authorization
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
operation = Paypal.new(tender, transaction)
|
|
84
|
+
operation.cancel!
|
|
85
|
+
|
|
86
|
+
assert_instance_of(
|
|
87
|
+
ActiveMerchant::Billing::Response,
|
|
88
|
+
transaction.cancellation
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
class Payment
|
|
5
|
+
class Capture
|
|
6
|
+
class PaypalTest < Workarea::TestCase
|
|
7
|
+
delegate :gateway, to: Workarea::Paypal
|
|
8
|
+
|
|
9
|
+
def authorization
|
|
10
|
+
@authorization ||= ActiveMerchant::Billing::BogusGateway::AUTHORIZATION
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def payment
|
|
14
|
+
@payment ||=
|
|
15
|
+
begin
|
|
16
|
+
result = create_payment
|
|
17
|
+
result.set_paypal(token: '1234', payer_id: 'pid')
|
|
18
|
+
result
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reference
|
|
23
|
+
@reference ||= Transaction.new(
|
|
24
|
+
amount: 5.to_m,
|
|
25
|
+
response: ActiveMerchant::Billing::Response.new(
|
|
26
|
+
true,
|
|
27
|
+
'Message',
|
|
28
|
+
'transaction_id' => authorization
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def transaction
|
|
34
|
+
@transaction ||= payment.paypal.transactions.build(
|
|
35
|
+
amount: 5.to_m,
|
|
36
|
+
reference: reference
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_complate_raises_if_the_reference_transaction_is_blank
|
|
41
|
+
transaction.reference = nil
|
|
42
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
43
|
+
|
|
44
|
+
assert_raises(Payment::MissingReference) { operation.complete! }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_complete_captures_on_the_credit_card_gateway
|
|
48
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
49
|
+
|
|
50
|
+
gateway
|
|
51
|
+
.expects(:capture)
|
|
52
|
+
.with(500, authorization, currency: 'USD')
|
|
53
|
+
|
|
54
|
+
operation.complete!
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_complete_sets_the_response_on_the_transaction
|
|
58
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
59
|
+
operation.complete!
|
|
60
|
+
|
|
61
|
+
assert_instance_of(
|
|
62
|
+
ActiveMerchant::Billing::Response,
|
|
63
|
+
transaction.response
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
class Payment
|
|
5
|
+
module Purchase
|
|
6
|
+
class PaypalTest < Workarea::TestCase
|
|
7
|
+
delegate :gateway, to: Workarea::Paypal
|
|
8
|
+
|
|
9
|
+
def payment
|
|
10
|
+
@payment ||= create_payment
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def authorization
|
|
14
|
+
@authorization ||= ActiveMerchant::Billing::BogusGateway::AUTHORIZATION
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def tender
|
|
18
|
+
@tender ||=
|
|
19
|
+
begin
|
|
20
|
+
payment.set_address(first_name: 'Ben', last_name: 'Crouse')
|
|
21
|
+
payment.build_paypal(token: '1234', payer_id: 'pid')
|
|
22
|
+
payment.paypal
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def transaction
|
|
27
|
+
@transaction ||= tender.transactions.build(
|
|
28
|
+
action: 'purchase',
|
|
29
|
+
amount: 5.to_m
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_complete_purchases_on_the_gateway
|
|
34
|
+
operation = Paypal.new(tender, transaction)
|
|
35
|
+
|
|
36
|
+
gateway.expects(:purchase)
|
|
37
|
+
|
|
38
|
+
operation.complete!
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_complete_sets_the_response_on_the_transaction
|
|
42
|
+
operation = Paypal.new(tender, transaction)
|
|
43
|
+
operation.complete!
|
|
44
|
+
|
|
45
|
+
assert_instance_of(
|
|
46
|
+
ActiveMerchant::Billing::Response,
|
|
47
|
+
transaction.response
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_cancel_does_nothing_if_the_transaction_was_a_failure
|
|
52
|
+
transaction.success = false
|
|
53
|
+
operation = Paypal.new(tender, transaction)
|
|
54
|
+
|
|
55
|
+
operation.gateway.expects(:void).never
|
|
56
|
+
operation.cancel!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_cancel_voids_with_the_authorization_from_the_transaction
|
|
60
|
+
transaction.response = ActiveMerchant::Billing::Response.new(
|
|
61
|
+
true,
|
|
62
|
+
'Message',
|
|
63
|
+
'transaction_id' => authorization
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
operation = Paypal.new(tender, transaction)
|
|
67
|
+
|
|
68
|
+
operation
|
|
69
|
+
.gateway
|
|
70
|
+
.expects(:void)
|
|
71
|
+
.with(authorization)
|
|
72
|
+
|
|
73
|
+
operation.cancel!
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_cancel_sets_cancellation_params_on_the_transaction
|
|
77
|
+
transaction.response = ActiveMerchant::Billing::Response.new(
|
|
78
|
+
true,
|
|
79
|
+
'Message',
|
|
80
|
+
'transaction_id' => authorization
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
operation = Paypal.new(tender, transaction)
|
|
84
|
+
operation.cancel!
|
|
85
|
+
|
|
86
|
+
assert_instance_of(
|
|
87
|
+
ActiveMerchant::Billing::Response,
|
|
88
|
+
transaction.cancellation
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
class Payment
|
|
5
|
+
class Refund
|
|
6
|
+
class PaypalTest < Workarea::TestCase
|
|
7
|
+
delegate :gateway, to: Workarea::Paypal
|
|
8
|
+
|
|
9
|
+
def authorization
|
|
10
|
+
@authorization ||= ActiveMerchant::Billing::BogusGateway::AUTHORIZATION
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def payment
|
|
14
|
+
@payment ||=
|
|
15
|
+
begin
|
|
16
|
+
result = create_payment
|
|
17
|
+
result.set_paypal(token: '1234', payer_id: 'pid')
|
|
18
|
+
result
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def reference
|
|
23
|
+
@reference ||= Transaction.new(
|
|
24
|
+
amount: 5.to_m,
|
|
25
|
+
response: ActiveMerchant::Billing::Response.new(
|
|
26
|
+
true,
|
|
27
|
+
'Message',
|
|
28
|
+
'transaction_id' => authorization
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def transaction
|
|
34
|
+
@transaction ||= payment.paypal.transactions.build(
|
|
35
|
+
amount: 5.to_m,
|
|
36
|
+
reference: reference
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_complete_raises_if_the_reference_transaction_is_blank
|
|
41
|
+
transaction.reference = nil
|
|
42
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
43
|
+
|
|
44
|
+
assert_raises(Payment::MissingReference) { operation.complete! }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_complete_refunds_on_the_credit_card_gateway
|
|
48
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
49
|
+
|
|
50
|
+
gateway
|
|
51
|
+
.expects(:refund)
|
|
52
|
+
.with(500, authorization, currency: 'USD')
|
|
53
|
+
|
|
54
|
+
operation.complete!
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_complete_sets_the_response_on_the_transaction
|
|
58
|
+
operation = Paypal.new(payment.paypal, transaction)
|
|
59
|
+
operation.complete!
|
|
60
|
+
|
|
61
|
+
assert_instance_of(
|
|
62
|
+
ActiveMerchant::Billing::Response,
|
|
63
|
+
transaction.response
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
decorate PaymentTest, with: :paypal do
|
|
5
|
+
def test_set_paypal_creates_paypal_tender
|
|
6
|
+
payment.set_paypal(
|
|
7
|
+
token: 'token',
|
|
8
|
+
payer_id: 'payer_id',
|
|
9
|
+
details: { 'foo' => 'bar' }
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
assert_equal('token', payment.paypal.token)
|
|
13
|
+
assert_equal('payer_id', payment.paypal.payer_id)
|
|
14
|
+
assert_equal({ 'foo' => 'bar' }, payment.paypal.details)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_set_credit_card_removes_paypal_tender
|
|
18
|
+
payment.set_paypal(
|
|
19
|
+
token: 'token',
|
|
20
|
+
payer_id: 'payer_id',
|
|
21
|
+
details: { 'foo' => 'bar' }
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
payment.set_credit_card({})
|
|
25
|
+
assert(payment.paypal.blank?)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def payment
|
|
31
|
+
@payment ||= Payment.create!
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
decorate Search::Admin::OrderTest, with: :paypal do
|
|
5
|
+
def test_search_text_includes_paypal
|
|
6
|
+
order = Workarea::Order.new(created_at: Time.now)
|
|
7
|
+
|
|
8
|
+
Payment.create!(
|
|
9
|
+
id: order.id,
|
|
10
|
+
address: {
|
|
11
|
+
first_name: 'Ben',
|
|
12
|
+
last_name: 'Crouse',
|
|
13
|
+
street: '22 S. 3rd St.',
|
|
14
|
+
city: 'Philadelphia',
|
|
15
|
+
region: 'PA',
|
|
16
|
+
postal_code: '19106',
|
|
17
|
+
country: 'US',
|
|
18
|
+
phone_number: '2159251800'
|
|
19
|
+
},
|
|
20
|
+
paypal: {
|
|
21
|
+
token: '1234',
|
|
22
|
+
payer_id: '1234',
|
|
23
|
+
details: {}
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
result = Search::Admin::Order.new(order).search_text
|
|
28
|
+
|
|
29
|
+
assert_includes(result, 'PayPal')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Workarea
|
|
4
|
+
class Paypal::SetupTest < Workarea::TestCase
|
|
5
|
+
delegate :gateway, to: Workarea::Paypal
|
|
6
|
+
|
|
7
|
+
def context
|
|
8
|
+
@context ||= stub_everything(request: stub_everything)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def user
|
|
12
|
+
@user ||= User.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def address
|
|
16
|
+
@address ||= Address.new(
|
|
17
|
+
first_name: 'Ben',
|
|
18
|
+
last_name: 'Crouse',
|
|
19
|
+
street: '22 S. 3rd St.',
|
|
20
|
+
city: 'Philadelphia',
|
|
21
|
+
region: 'PA',
|
|
22
|
+
country: 'US',
|
|
23
|
+
postal_code: '19106',
|
|
24
|
+
phone_number: '2159251800'
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def shipping
|
|
29
|
+
@shipping ||= Shipping.new(address: address)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def order
|
|
33
|
+
@order ||= create_order.tap do |order|
|
|
34
|
+
product = create_product(
|
|
35
|
+
variants: [{ sku: 'SKU1', regular: 5.to_m }]
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
create_order_total_discount(
|
|
39
|
+
name: 'Test Order Discount',
|
|
40
|
+
amount_type: :flat,
|
|
41
|
+
amount: 3
|
|
42
|
+
)
|
|
43
|
+
order.add_item(
|
|
44
|
+
product_id: product.id,
|
|
45
|
+
sku: product.skus.first,
|
|
46
|
+
quantity: 2
|
|
47
|
+
)
|
|
48
|
+
Pricing.perform(order)
|
|
49
|
+
order.save!
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def setup
|
|
54
|
+
@setup ||= Paypal::Setup.new(order, user, shipping, context)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_paypal_response_asks_the_paypal_gateway_to_setup_the_auth
|
|
58
|
+
response = mock
|
|
59
|
+
|
|
60
|
+
gateway
|
|
61
|
+
.expects(:setup_authorization)
|
|
62
|
+
.returns(response)
|
|
63
|
+
|
|
64
|
+
assert_equal(response, setup.paypal_response)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_items_includes_order_items_and_discounts
|
|
68
|
+
assert_equal([
|
|
69
|
+
{ name: nil, quantity: 2, amount: 650 },
|
|
70
|
+
{ name: 'Test Order Discount', quantity: 1, amount: -300 },
|
|
71
|
+
{ name: 'Test Order Discount', quantity: 1, amount: -300 }
|
|
72
|
+
], setup.items)
|
|
73
|
+
|
|
74
|
+
assert_equal(700, setup.subtotal)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_shpping_address_uses_order_shipping_address_when_order_has_shipping_address
|
|
78
|
+
assert_equal(
|
|
79
|
+
{
|
|
80
|
+
name: 'Ben Crouse',
|
|
81
|
+
address1: '22 S. 3rd St.',
|
|
82
|
+
address2: nil,
|
|
83
|
+
city: 'Philadelphia',
|
|
84
|
+
state: 'PA',
|
|
85
|
+
country: Country['US'],
|
|
86
|
+
zip: '19106',
|
|
87
|
+
phone: '2159251800'
|
|
88
|
+
},
|
|
89
|
+
setup.shipping_address
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_shipping_address_uses_the_users_default_shipping_address_when_no_shipping_address
|
|
94
|
+
shipping.update_attributes!(address: nil)
|
|
95
|
+
user.expects(:default_shipping_address).returns(address)
|
|
96
|
+
|
|
97
|
+
assert_equal(
|
|
98
|
+
{
|
|
99
|
+
name: 'Ben Crouse',
|
|
100
|
+
address1: '22 S. 3rd St.',
|
|
101
|
+
address2: nil,
|
|
102
|
+
city: 'Philadelphia',
|
|
103
|
+
state: 'PA',
|
|
104
|
+
country: Country['US'],
|
|
105
|
+
zip: '19106',
|
|
106
|
+
phone: '2159251800'
|
|
107
|
+
},
|
|
108
|
+
setup.shipping_address
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_redirect_url_asks_the_paypal_gateway_for_the_redirect_url
|
|
113
|
+
url = 'http://paypal.com'
|
|
114
|
+
setup.expects(:paypal_response).returns(mock(token: '1243'))
|
|
115
|
+
gateway.expects(:redirect_url_for).with('1243').returns(url)
|
|
116
|
+
|
|
117
|
+
assert_equal(url, setup.redirect_url)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|