workarea-stripe 1.0.0

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.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintrc +36 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  5. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  7. data/.gitignore +19 -0
  8. data/CHANGELOG.md +67 -0
  9. data/CODE_OF_CONDUCT.md +3 -0
  10. data/CONTRIBUTING.md +3 -0
  11. data/Gemfile +8 -0
  12. data/LICENSE +52 -0
  13. data/README.md +90 -0
  14. data/Rakefile +60 -0
  15. data/app/assets/javascripts/workarea/storefront/stripe/config.js.erb +29 -0
  16. data/app/assets/javascripts/workarea/storefront/stripe/modules/bogus_stripe_elements.js +55 -0
  17. data/app/assets/javascripts/workarea/storefront/stripe/modules/stripe_elements.js +113 -0
  18. data/app/assets/stylesheets/workarea/stripe/components/_checkout_payment_stripe.scss +19 -0
  19. data/app/controllers/workarea/storefront/users/credit_cards_controller.decorator +10 -0
  20. data/app/models/workarea/checkout/credit_card_params.decorator +30 -0
  21. data/app/models/workarea/checkout/steps/payment.decorator +16 -0
  22. data/app/models/workarea/payment.decorator +18 -0
  23. data/app/models/workarea/payment/authorize/credit_card.decorator +24 -0
  24. data/app/models/workarea/payment/credit_card.decorator +27 -0
  25. data/app/models/workarea/payment/purchase/credit_card.decorator +24 -0
  26. data/app/models/workarea/payment/store_credit_card.decorator +54 -0
  27. data/app/views/workarea/storefront/checkouts/_stripe_dialog.html.haml +2 -0
  28. data/app/views/workarea/storefront/checkouts/_stripe_form.html.haml +19 -0
  29. data/app/views/workarea/storefront/stripe/_stripe_js.html.haml +1 -0
  30. data/app/views/workarea/storefront/users/credit_cards/_stripe_form.html.haml +12 -0
  31. data/app/views/workarea/storefront/users/credit_cards/new.html.haml +42 -0
  32. data/bin/rails +20 -0
  33. data/config/initializers/appends.rb +33 -0
  34. data/config/initializers/workarea.rb +9 -0
  35. data/config/routes.rb +2 -0
  36. data/lib/active_merchant/billing/bogus_stripe_gateway.rb +29 -0
  37. data/lib/workarea/stripe.rb +46 -0
  38. data/lib/workarea/stripe/engine.rb +8 -0
  39. data/lib/workarea/stripe/version.rb +5 -0
  40. data/test/dummy/Rakefile +6 -0
  41. data/test/dummy/app/assets/config/manifest.js +4 -0
  42. data/test/dummy/app/assets/images/.keep +0 -0
  43. data/test/dummy/app/assets/javascripts/application.js +13 -0
  44. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  45. data/test/dummy/app/controllers/application_controller.rb +3 -0
  46. data/test/dummy/app/controllers/concerns/.keep +0 -0
  47. data/test/dummy/app/helpers/application_helper.rb +2 -0
  48. data/test/dummy/app/jobs/application_job.rb +2 -0
  49. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  50. data/test/dummy/app/models/concerns/.keep +0 -0
  51. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  52. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  53. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  54. data/test/dummy/bin/bundle +3 -0
  55. data/test/dummy/bin/rails +4 -0
  56. data/test/dummy/bin/rake +4 -0
  57. data/test/dummy/bin/setup +30 -0
  58. data/test/dummy/bin/update +26 -0
  59. data/test/dummy/bin/yarn +11 -0
  60. data/test/dummy/config.ru +5 -0
  61. data/test/dummy/config/application.rb +30 -0
  62. data/test/dummy/config/boot.rb +5 -0
  63. data/test/dummy/config/cable.yml +10 -0
  64. data/test/dummy/config/environment.rb +5 -0
  65. data/test/dummy/config/environments/development.rb +51 -0
  66. data/test/dummy/config/environments/production.rb +88 -0
  67. data/test/dummy/config/environments/test.rb +44 -0
  68. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  69. data/test/dummy/config/initializers/assets.rb +14 -0
  70. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  71. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  72. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  73. data/test/dummy/config/initializers/inflections.rb +16 -0
  74. data/test/dummy/config/initializers/mime_types.rb +4 -0
  75. data/test/dummy/config/initializers/workarea.rb +5 -0
  76. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  77. data/test/dummy/config/locales/en.yml +33 -0
  78. data/test/dummy/config/puma.rb +56 -0
  79. data/test/dummy/config/routes.rb +5 -0
  80. data/test/dummy/config/secrets.yml +32 -0
  81. data/test/dummy/config/spring.rb +6 -0
  82. data/test/dummy/db/seeds.rb +2 -0
  83. data/test/dummy/lib/assets/.keep +0 -0
  84. data/test/dummy/log/.keep +0 -0
  85. data/test/dummy/package.json +5 -0
  86. data/test/integration/workarea/storefront/place_order_integration_test.decorator +19 -0
  87. data/test/integration/workarea/storefront/users/credit_cards_integration_test.decorator +26 -0
  88. data/test/models/workarea/checkout/credit_card_params_test.rb +10 -0
  89. data/test/models/workarea/checkout/steps/payment_test.decorator +21 -0
  90. data/test/models/workarea/payment/authorize/credit_card_test.decorator +24 -0
  91. data/test/models/workarea/payment/capture_test.decorator +10 -0
  92. data/test/models/workarea/payment/credit_card_integration_test.decorator +26 -0
  93. data/test/models/workarea/payment/purchase/credit_card_test.decorator +25 -0
  94. data/test/models/workarea/payment/refund/credit_card_test.decorator +20 -0
  95. data/test/models/workarea/payment/refund_test.decorator +10 -0
  96. data/test/models/workarea/payment/store_credit_card_test.decorator +9 -0
  97. data/test/models/workarea/payment_test.decorator +20 -0
  98. data/test/support/stripe_public_key.rb +1 -0
  99. data/test/system/workarea/storefront/analytics_system_test.decorator +5 -0
  100. data/test/system/workarea/storefront/credit_cards_system_test.decorator +5 -0
  101. data/test/system/workarea/storefront/digital_products_system_test.decorator +67 -0
  102. data/test/system/workarea/storefront/guest_checkout_system_test.decorator +107 -0
  103. data/test/system/workarea/storefront/logged_in_checkout_system_test.decorator +5 -0
  104. data/test/system/workarea/storefront/no_js_system_test.decorator +5 -0
  105. data/test/system/workarea/storefront/stripe_payment_system_test.rb +97 -0
  106. data/test/teaspoon_env.rb +6 -0
  107. data/test/test_helper.rb +10 -0
  108. data/test/workers/workarea/send_refund_email_test.decorator +29 -0
  109. data/workarea-stripe.gemspec +21 -0
  110. metadata +171 -0
@@ -0,0 +1,2 @@
1
+ require 'workarea/seeds'
2
+ Workarea::Seeds.run
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "dummy",
3
+ "private": true,
4
+ "dependencies": {}
5
+ }
@@ -0,0 +1,19 @@
1
+ module Workarea
2
+ decorate Storefront::PlaceOrderIntegrationTest, with: :stripe do
3
+ def test_payment_error_handling
4
+ patch storefront.checkout_place_order_path,
5
+ params: {
6
+ payment: 'new_card',
7
+ credit_card: {
8
+ number: '2',
9
+ month: 1,
10
+ year: 2020,
11
+ cvv: '999',
12
+ stripe_token: '2'
13
+ }
14
+ }
15
+ assert(response.ok?)
16
+ assert_match('Payment', response.body)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module Workarea
2
+ decorate Storefront::Users::CreditCardsIntegrationTest, with: :stripe do
3
+ def test_adds_credit_cards
4
+ cc_params = {
5
+ credit_card: {
6
+ first_name: 'Ben',
7
+ last_name: 'Crouse'
8
+ }
9
+ }.merge!("stripe_token" => 1)
10
+
11
+ post storefront.users_credit_cards_path,
12
+ params: cc_params
13
+
14
+ assert_redirected_to(storefront.users_account_path)
15
+
16
+ payment_profile = Payment::Profile.lookup(PaymentReference.new(@user))
17
+
18
+ credit_card = payment_profile.credit_cards.first
19
+ assert_equal('Ben', credit_card.first_name)
20
+ assert_equal('Crouse', credit_card.last_name)
21
+ assert_equal(1, credit_card.month)
22
+ assert_equal(2020, credit_card.year)
23
+ assert(credit_card.token.present?)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Checkout::CreditCardParamsTest < TestCase
5
+ def test_strip
6
+ cc_params = Workarea::Checkout::CreditCardParams.new("stripeToken" => '123')
7
+ assert(cc_params.stripe?)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ module Workarea
2
+ decorate Checkout::Steps::PaymentTest, with: :stripe do
3
+ def test_update
4
+ assert(
5
+ step.update(
6
+ "payment" => 'new_card',
7
+ "stripeToken" => '1'
8
+ )
9
+ )
10
+
11
+ assert(payment.credit_card.present?)
12
+ assert(payment.credit_card.amount)
13
+
14
+ step.update
15
+ assert(payment.credit_card.nil?)
16
+
17
+ payment.address = nil
18
+ refute(step.update)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ module Workarea
2
+ decorate Payment::Authorize::CreditCardTest, with: :stripe do
3
+ def payment
4
+ @payment ||=
5
+ begin
6
+ profile = create_payment_profile
7
+ order = create_order
8
+ create_payment(
9
+ id: order.id,
10
+ profile_id: profile.id,
11
+ address: {
12
+ first_name: 'Ben',
13
+ last_name: 'Crouse',
14
+ street: '22 s. 3rd st.',
15
+ city: 'Philadelphia',
16
+ region: 'PA',
17
+ postal_code: '19106',
18
+ country: Country['US']
19
+ }
20
+ )
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Payment::CaptureTest, with: :stripe do
3
+ def payment
4
+ @payment ||= begin
5
+ order = create_order
6
+ create_payment(id: order.id, profile: profile)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ if Workarea::VERSION::MAJOR >= 3 && Workarea::VERSION::MINOR >= 3
2
+ module Workarea
3
+ decorate Payment::CreditCardIntegrationTest, with: :stripe do
4
+ def payment
5
+ @payment ||=
6
+ begin
7
+ profile = create_payment_profile
8
+ order = create_order
9
+ create_payment(
10
+ id: order.id,
11
+ profile_id: profile.id,
12
+ address: {
13
+ first_name: 'Ben',
14
+ last_name: 'Crouse',
15
+ street: '22 s. 3rd st.',
16
+ city: 'Philadelphia',
17
+ region: 'PA',
18
+ postal_code: '19106',
19
+ country: Country['US']
20
+ }
21
+ )
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Workarea
2
+ decorate Payment::Purchase::CreditCardTest, with: :stripe do
3
+ def payment
4
+ @payment ||=
5
+ begin
6
+ profile = create_payment_profile
7
+ order = create_order
8
+ create_payment(
9
+ id: order.id,
10
+ profile_id: profile.id,
11
+ address: {
12
+ first_name: 'Ben',
13
+ last_name: 'Crouse',
14
+ street: '22 s. 3rd st.',
15
+ city: 'Philadelphia',
16
+ region: 'PA',
17
+ postal_code: '19106',
18
+ country: Country['US']
19
+ }
20
+ )
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate Payment::Refund::CreditCardTest, with: :stripe do
3
+ def payment
4
+ @payment ||=
5
+ begin
6
+ profile = create_payment_profile
7
+ order = create_order
8
+ result = create_payment(id: order.id, profile: profile)
9
+ result.set_credit_card(
10
+ number: 1,
11
+ month: 1,
12
+ year: Time.current.year + 1,
13
+ cvv: 999
14
+ )
15
+
16
+ result
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Payment::RefundTest, with: :stripe do
3
+ def payment
4
+ @payment ||= begin
5
+ order = create_order
6
+ create_payment(id: order.id, profile: profile)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ decorate Payment::StoreCreditCardTest, with: :stripe do
3
+ def test_perform_sets_the_gateway_id
4
+ credit_card.token = nil
5
+ Workarea::Payment::StoreCreditCard.new(credit_card).perform!
6
+ assert(credit_card.profile.gateway_id.present?, 'expected gateway ID to be present on profile')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate PaymentTest, with: :stripe do
3
+ def test_set_credit_card
4
+ payment = Payment.new
5
+ payment.set_credit_card(
6
+ number: '4111111111111111',
7
+ month: 1,
8
+ year: Time.current.year + 1,
9
+ cvv: '123',
10
+ amount: 1.to_m,
11
+ stripe_token: 'tok_123'
12
+ )
13
+
14
+ assert(payment.credit_card.present?)
15
+ assert(payment.credit_card.stripe_token.present?)
16
+ assert(payment.credit_card.errors.present?)
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1 @@
1
+ Workarea.config.stripe.public_key = 'pk_test_MN4pzRoNbCa2lMUVVAQwpoiJ'
@@ -0,0 +1,5 @@
1
+ decorate Workarea::Storefront::AnalyticsSystemTest, with: :stripe do
2
+ def test_announcing_validation_errors
3
+ skip 'The elements JS will always return a valid token'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ decorate Workarea::Storefront::CreditCardsSystemTest, with: :stripe do
2
+ def test_managing_credit_cards
3
+ skip 'Test is skipped pending a good way to edit via the saved form'
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ decorate Workarea::Storefront::DigitalProductsSystemTest, with: :stripe do
2
+ def fill_in_credit_card
3
+ page.driver.browser.switch_to.frame "stripe-payment-frame"
4
+
5
+ find('input[name="cardnumber"]').set('4111111111111111')
6
+ find('input[name="exp-date"]').set('12/21')
7
+ find('input[name="cvc"]').set('999')
8
+ find('input[name="postal"]').set('19143')
9
+
10
+ page.driver.browser.switch_to.default_content
11
+ end
12
+
13
+
14
+ def test_checking_out_with_a_digital_product
15
+ setup_checkout_specs
16
+
17
+ Workarea::Order.first.items.delete_all
18
+
19
+ product = create_product(
20
+ name: 'Digital Product',
21
+ digital: true,
22
+ variants: [
23
+ { sku: 'SKU1', regular: 10.to_m },
24
+ { sku: 'SKU2', regular: 15.to_m },
25
+ { sku: 'SKU3', regular: 25.to_m }
26
+ ]
27
+ )
28
+
29
+ visit storefront.product_path(product)
30
+
31
+ within '.product-details__add-to-cart-form' do
32
+ select product.skus.first, from: 'sku'
33
+ click_button t('workarea.storefront.products.add_to_cart')
34
+ end
35
+
36
+ assert(page.has_content?('Success'))
37
+
38
+ start_guest_checkout
39
+
40
+ assert_current_path(storefront.checkout_addresses_path)
41
+
42
+ fill_in_email
43
+ fill_in_billing_address
44
+ click_button t('workarea.storefront.checkouts.continue_to_payment')
45
+
46
+ assert_current_path(storefront.checkout_payment_path)
47
+ assert(page.has_content?('Success'))
48
+
49
+ fill_in_credit_card
50
+ click_button t('workarea.storefront.checkouts.place_order')
51
+
52
+ assert_current_path(storefront.checkout_confirmation_path)
53
+ assert(page.has_content?('Success'))
54
+ assert(page.has_content?(t('workarea.storefront.flash_messages.order_placed')))
55
+ assert(page.has_content?(Workarea::Order.first.id))
56
+
57
+ assert(page.has_content?('1019 S. 47th St.'))
58
+ assert(page.has_content?('Philadelphia'))
59
+ assert(page.has_content?('PA'))
60
+ assert(page.has_content?('19143'))
61
+
62
+ assert(page.has_content?('Visa'))
63
+
64
+ assert(page.has_content?('Digital Product'))
65
+ assert(page.has_content?('$10.00'))
66
+ end
67
+ end
@@ -0,0 +1,107 @@
1
+ require 'test_helper'
2
+
3
+ decorate Workarea::Storefront::GuestCheckoutSystemTest, with: :stripe do
4
+ def test_failed_payment_authorization
5
+ skip 'Stripe will always return a valid payment method'
6
+ end
7
+
8
+ def test_creating_an_account
9
+ assert_current_path(storefront.checkout_addresses_path)
10
+ fill_in_email
11
+ fill_in_shipping_address
12
+ uncheck 'same_as_shipping'
13
+ fill_in_billing_address
14
+ click_button t('workarea.storefront.checkouts.continue_to_shipping')
15
+
16
+ assert_current_path(storefront.checkout_shipping_path)
17
+ assert(page.has_content?('Success'))
18
+ click_button t('workarea.storefront.checkouts.continue_to_payment')
19
+
20
+ assert_current_path(storefront.checkout_payment_path)
21
+ assert(page.has_content?('Success'))
22
+ fill_in_credit_card
23
+ click_button t('workarea.storefront.checkouts.place_order')
24
+
25
+ assert_current_path(storefront.checkout_confirmation_path)
26
+ fill_in 'password', with: 'W3bl1nc!'
27
+ check 'email_signup'
28
+ click_button t('workarea.storefront.users.create_account')
29
+
30
+ assert_current_path(storefront.users_account_path)
31
+
32
+ assert(page.has_content?('Success'))
33
+ assert(page.has_content?('Ben'))
34
+ assert(page.has_content?('Crouse'))
35
+ assert(page.has_content?(Workarea::Order.first.id))
36
+ assert(page.has_content?('22 S. 3rd St.'))
37
+ assert(page.has_content?('1019 S. 47th St.'))
38
+ end
39
+
40
+ def test_successfully_checking_out
41
+ assert_current_path(storefront.checkout_addresses_path)
42
+ fill_in_email
43
+ fill_in_shipping_address
44
+ uncheck 'same_as_shipping'
45
+ fill_in_billing_address
46
+ click_button t('workarea.storefront.checkouts.continue_to_shipping')
47
+
48
+ assert_current_path(storefront.checkout_shipping_path)
49
+ assert(page.has_content?('Success'))
50
+
51
+ click_button t('workarea.storefront.checkouts.shipping_instructions_prompt')
52
+ instruction = 'Doorbeel broken, please knock'
53
+ fill_in :shipping_instructions, with: instruction
54
+
55
+ click_button t('workarea.storefront.checkouts.continue_to_payment')
56
+
57
+ assert_current_path(storefront.checkout_payment_path)
58
+ assert(page.has_content?('Success'))
59
+
60
+ assert(page.has_content?('22 S. 3rd St.'))
61
+ assert(page.has_content?('Philadelphia'))
62
+ assert(page.has_content?('PA'))
63
+ assert(page.has_content?('19106'))
64
+ assert(page.has_content?('Ground'))
65
+
66
+ assert(page.has_content?('Integration Product'))
67
+ assert(page.has_content?('SKU'))
68
+
69
+ assert(page.has_content?('$5.00')) # Subtotal
70
+ assert(page.has_content?('$7.00')) # Shipping
71
+ assert(page.has_content?('$0.84')) # Tax
72
+ assert(page.has_content?('$12.84')) # Total
73
+
74
+ assert(page.has_content?(instruction))
75
+
76
+ fill_in_credit_card
77
+ click_button t('workarea.storefront.checkouts.place_order')
78
+ assert_current_path(storefront.checkout_confirmation_path)
79
+
80
+ assert(page.has_content?('Success'))
81
+ assert(page.has_content?(t('workarea.storefront.flash_messages.order_placed')))
82
+ assert(page.has_content?(Workarea::Order.first.id))
83
+
84
+ assert(page.has_content?('22 S. 3rd St.'))
85
+ assert(page.has_content?('Philadelphia'))
86
+ assert(page.has_content?('PA'))
87
+ assert(page.has_content?('19106'))
88
+ assert(page.has_content?('Ground'))
89
+
90
+ assert(page.has_content?('1019 S. 47th St.'))
91
+ assert(page.has_content?('Philadelphia'))
92
+ assert(page.has_content?('PA'))
93
+ assert(page.has_content?('19143'))
94
+
95
+ assert(page.has_content?('Visa'))
96
+
97
+ assert(page.has_content?(instruction))
98
+
99
+ assert(page.has_content?('Integration Product'))
100
+ assert(page.has_content?('SKU'))
101
+
102
+ assert(page.has_content?('$5.00')) # Subtotal
103
+ assert(page.has_content?('$7.00')) # Shipping
104
+ assert(page.has_content?('$0.84')) # Tax
105
+ assert(page.has_content?('$12.84')) # Total
106
+ end
107
+ end