solidus_stripe 4.4.1 → 5.0.0.alpha.1

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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +92 -52
  3. data/.gitignore +3 -0
  4. data/.rubocop.yml +94 -4
  5. data/.yardopts +1 -0
  6. data/Gemfile +10 -30
  7. data/LICENSE +2 -2
  8. data/Procfile.dev +3 -0
  9. data/README.md +145 -215
  10. data/Rakefile +5 -44
  11. data/app/assets/javascripts/spree/backend/solidus_stripe.js +2 -0
  12. data/app/assets/stylesheets/spree/backend/solidus_stripe.css +4 -0
  13. data/app/controllers/solidus_stripe/intents_controller.rb +36 -52
  14. data/app/controllers/solidus_stripe/webhooks_controller.rb +28 -0
  15. data/app/models/concerns/solidus_stripe/log_entries.rb +31 -0
  16. data/app/models/solidus_stripe/customer.rb +21 -0
  17. data/app/models/solidus_stripe/gateway.rb +231 -0
  18. data/app/models/solidus_stripe/payment_intent.rb +111 -0
  19. data/app/models/solidus_stripe/payment_method.rb +106 -0
  20. data/app/models/solidus_stripe/payment_source.rb +31 -0
  21. data/app/models/solidus_stripe/slug_entry.rb +20 -0
  22. data/app/models/solidus_stripe.rb +7 -0
  23. data/app/subscribers/solidus_stripe/webhook/charge_subscriber.rb +28 -0
  24. data/app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb +112 -0
  25. data/app/views/spree/admin/payments/source_forms/_stripe.html.erb +29 -0
  26. data/app/views/spree/admin/payments/source_forms/existing_payment/_stripe.html.erb +14 -0
  27. data/app/views/spree/admin/payments/source_forms/existing_payment/stripe/_card.html.erb +8 -0
  28. data/app/views/spree/admin/payments/source_forms/existing_payment/stripe/_default.html.erb +7 -0
  29. data/app/views/spree/admin/payments/source_views/_stripe.html.erb +15 -0
  30. data/app/views/spree/api/payments/source_views/_stripe.json.jbuilder +8 -0
  31. data/bin/dev +13 -0
  32. data/bin/dummy-app +29 -0
  33. data/bin/rails +38 -3
  34. data/bin/rails-dummy-app +3 -0
  35. data/bin/rails-engine +1 -11
  36. data/bin/rails-new +55 -0
  37. data/bin/rails-sandbox +1 -14
  38. data/bin/rspec +10 -0
  39. data/bin/sandbox +12 -74
  40. data/bin/setup +1 -0
  41. data/bin/update-migrations +56 -0
  42. data/codecov.yml +12 -0
  43. data/config/locales/en.yml +16 -1
  44. data/config/routes.rb +5 -11
  45. data/coverage.rb +42 -0
  46. data/db/migrate/20230109183332_create_solidus_stripe_payment_sources.rb +10 -0
  47. data/db/migrate/20230303154931_create_solidus_stripe_setup_intent.rb +10 -0
  48. data/db/migrate/20230306105520_create_solidus_stripe_payment_intents.rb +10 -0
  49. data/db/migrate/20230308122414_create_solidus_stripe_webhook_endpoints.rb +10 -0
  50. data/db/migrate/20230310152615_add_payment_method_reference_to_stripe_intents.rb +6 -0
  51. data/db/migrate/20230310171444_normalize_stripe_intent_id_attributes.rb +6 -0
  52. data/db/migrate/20230313150008_create_solidus_stripe_customers.rb +16 -0
  53. data/db/migrate/20230323154931_drop_solidus_stripe_setup_intent.rb +13 -0
  54. data/db/migrate/20230403094916_rename_webhook_endpoint_to_payment_method_slug_entries.rb +5 -0
  55. data/db/seeds.rb +6 -24
  56. data/lib/generators/solidus_stripe/install/install_generator.rb +121 -14
  57. data/lib/generators/solidus_stripe/install/templates/app/assets/stylesheets/spree/frontend/solidus_stripe.css +13 -0
  58. data/lib/generators/solidus_stripe/install/templates/app/javascript/controllers/solidus_stripe_confirm_controller.js +39 -0
  59. data/lib/generators/solidus_stripe/install/templates/app/javascript/controllers/solidus_stripe_payment_controller.js +89 -0
  60. data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/_stripe.html.erb +16 -0
  61. data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/stripe/_card.html.erb +8 -0
  62. data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/stripe/_default.html.erb +7 -0
  63. data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/payment/_stripe.html.erb +39 -0
  64. data/lib/generators/solidus_stripe/install/templates/app/views/orders/payment_info/_stripe.html.erb +20 -0
  65. data/lib/generators/solidus_stripe/install/templates/config/initializers/solidus_stripe.rb +31 -0
  66. data/lib/solidus_stripe/configuration.rb +24 -3
  67. data/lib/solidus_stripe/engine.rb +19 -6
  68. data/lib/solidus_stripe/money_to_stripe_amount_converter.rb +109 -0
  69. data/lib/solidus_stripe/refunds_synchronizer.rb +96 -0
  70. data/lib/solidus_stripe/seeds.rb +19 -0
  71. data/lib/solidus_stripe/testing_support/factories.rb +153 -0
  72. data/lib/solidus_stripe/version.rb +1 -1
  73. data/lib/solidus_stripe/webhook/event.rb +90 -0
  74. data/lib/solidus_stripe.rb +0 -2
  75. data/solidus_stripe.gemspec +29 -6
  76. data/spec/lib/solidus_stripe/configuration_spec.rb +21 -0
  77. data/spec/lib/solidus_stripe/money_to_stripe_amount_converter_spec.rb +133 -0
  78. data/spec/lib/solidus_stripe/refunds_synchronizer_spec.rb +238 -0
  79. data/spec/lib/solidus_stripe/seeds_spec.rb +43 -0
  80. data/spec/lib/solidus_stripe/webhook/event_spec.rb +134 -0
  81. data/spec/models/concerns/solidus_stripe/log_entries_spec.rb +54 -0
  82. data/spec/models/solidus_stripe/customer_spec.rb +47 -0
  83. data/spec/models/solidus_stripe/gateway_spec.rb +283 -0
  84. data/spec/models/solidus_stripe/payment_intent_spec.rb +17 -0
  85. data/spec/models/solidus_stripe/payment_method_spec.rb +137 -0
  86. data/spec/models/solidus_stripe/payment_source_spec.rb +25 -0
  87. data/spec/requests/solidus_stripe/intents_controller_spec.rb +29 -0
  88. data/spec/requests/solidus_stripe/webhooks_controller/charge/refunded_spec.rb +31 -0
  89. data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/canceled_spec.rb +23 -0
  90. data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/payment_failed_spec.rb +23 -0
  91. data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/succeeded_spec.rb +29 -0
  92. data/spec/requests/solidus_stripe/webhooks_controller_spec.rb +52 -0
  93. data/spec/solidus_stripe_spec_helper.rb +10 -0
  94. data/spec/subscribers/solidus_stripe/webhook/charge_subscriber_spec.rb +33 -0
  95. data/spec/subscribers/solidus_stripe/webhook/payment_intent_subscriber_spec.rb +297 -0
  96. data/spec/support/solidus_stripe/backend_test_helper.rb +210 -0
  97. data/spec/support/solidus_stripe/checkout_test_helper.rb +339 -0
  98. data/spec/support/solidus_stripe/factories.rb +5 -0
  99. data/spec/support/solidus_stripe/webhook/data_fixtures.rb +106 -0
  100. data/spec/support/solidus_stripe/webhook/event_with_context_factory.rb +82 -0
  101. data/spec/support/solidus_stripe/webhook/request_helper.rb +32 -0
  102. data/spec/system/backend/solidus_stripe/orders/payments_spec.rb +119 -0
  103. data/spec/system/frontend/.keep +0 -0
  104. data/spec/system/frontend/solidus_stripe/checkout_spec.rb +187 -0
  105. data/tmp/.keep +0 -0
  106. metadata +202 -78
  107. data/.rubocop_todo.yml +0 -298
  108. data/.travis.yml +0 -28
  109. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +0 -122
  110. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-elements.js +0 -148
  111. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-init.js +0 -20
  112. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js +0 -84
  113. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +0 -160
  114. data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment.js +0 -16
  115. data/app/assets/javascripts/spree/frontend/solidus_stripe.js +0 -6
  116. data/app/controllers/solidus_stripe/payment_request_controller.rb +0 -52
  117. data/app/controllers/spree/stripe_controller.rb +0 -13
  118. data/app/decorators/models/spree/order_update_attributes_decorator.rb +0 -39
  119. data/app/decorators/models/spree/payment_decorator.rb +0 -11
  120. data/app/decorators/models/spree/refund_decorator.rb +0 -9
  121. data/app/models/solidus_stripe/address_from_params_service.rb +0 -72
  122. data/app/models/solidus_stripe/create_intents_payment_service.rb +0 -114
  123. data/app/models/solidus_stripe/prepare_order_for_payment_service.rb +0 -46
  124. data/app/models/solidus_stripe/shipping_rates_service.rb +0 -46
  125. data/app/models/spree/payment_method/stripe_credit_card.rb +0 -230
  126. data/bin/r +0 -13
  127. data/bin/sandbox_rails +0 -18
  128. data/db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb +0 -21
  129. data/lib/assets/stylesheets/spree/frontend/solidus_stripe.scss +0 -11
  130. data/lib/solidus_stripe/testing_support/card_input_helper.rb +0 -34
  131. data/lib/tasks/solidus_stripe/db/seed.rake +0 -14
  132. data/lib/views/api/spree/api/payments/source_views/_stripe.json.jbuilder +0 -3
  133. data/lib/views/backend/spree/admin/log_entries/_stripe.html.erb +0 -28
  134. data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +0 -1
  135. data/lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb +0 -1
  136. data/lib/views/frontend/spree/checkout/existing_payment/_stripe.html.erb +0 -1
  137. data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +0 -8
  138. data/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb +0 -78
  139. data/lib/views/frontend/spree/checkout/payment/v3/_elements.html.erb +0 -1
  140. data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +0 -40
  141. data/lib/views/frontend/spree/checkout/payment/v3/_intents.html.erb +0 -1
  142. data/lib/views/frontend/spree/checkout/payment/v3/_stripe.html.erb +0 -2
  143. data/lib/views/frontend/spree/orders/_stripe_payment_request_button.html.erb +0 -14
  144. data/spec/features/stripe_checkout_spec.rb +0 -486
  145. data/spec/models/solidus_stripe/address_from_params_service_spec.rb +0 -87
  146. data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +0 -127
  147. data/spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb +0 -65
  148. data/spec/models/solidus_stripe/shipping_rates_service_spec.rb +0 -54
  149. data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +0 -354
  150. data/spec/requests/payment_requests_spec.rb +0 -152
  151. data/spec/solidus_frontend_app_template.rb +0 -17
  152. data/spec/spec_helper.rb +0 -37
  153. data/spec/support/solidus_address_helper.rb +0 -15
data/.rubocop_todo.yml DELETED
@@ -1,298 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2022-08-30 14:09:43 UTC using RuboCop version 1.35.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # This cop supports safe autocorrection (--autocorrect).
11
- # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
- # Include: **/*.gemspec
13
- Gemspec/OrderedDependencies:
14
- Exclude:
15
- - 'solidus_stripe.gemspec'
16
-
17
- # Offense count: 3
18
- # This cop supports safe autocorrection (--autocorrect).
19
- # Configuration parameters: EnforcedStyle, IndentationWidth.
20
- # SupportedStyles: with_first_argument, with_fixed_indentation
21
- Layout/ArgumentAlignment:
22
- Exclude:
23
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
24
-
25
- # Offense count: 2
26
- # This cop supports safe autocorrection (--autocorrect).
27
- Layout/ClosingParenthesisIndentation:
28
- Exclude:
29
- - 'spec/requests/payment_requests_spec.rb'
30
-
31
- # Offense count: 2
32
- # This cop supports safe autocorrection (--autocorrect).
33
- Layout/ElseAlignment:
34
- Exclude:
35
- - 'app/models/solidus_stripe/address_from_params_service.rb'
36
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
37
-
38
- # Offense count: 2
39
- # This cop supports safe autocorrection (--autocorrect).
40
- # Configuration parameters: EnforcedStyleAlignWith, Severity.
41
- # SupportedStylesAlignWith: keyword, variable, start_of_line
42
- Layout/EndAlignment:
43
- Exclude:
44
- - 'app/models/solidus_stripe/address_from_params_service.rb'
45
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
46
-
47
- # Offense count: 2
48
- # This cop supports safe autocorrection (--autocorrect).
49
- # Configuration parameters: Width, AllowedPatterns, IgnoredPatterns.
50
- Layout/IndentationWidth:
51
- Exclude:
52
- - 'app/models/solidus_stripe/address_from_params_service.rb'
53
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
54
-
55
- # Offense count: 2
56
- # This cop supports safe autocorrection (--autocorrect).
57
- # Configuration parameters: EnforcedStyle.
58
- # SupportedStyles: symmetrical, new_line, same_line
59
- Layout/MultilineMethodCallBraceLayout:
60
- Exclude:
61
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
62
-
63
- # Offense count: 1
64
- # This cop supports safe autocorrection (--autocorrect).
65
- # Configuration parameters: EnforcedStyle, IndentationWidth.
66
- # SupportedStyles: aligned, indented, indented_relative_to_receiver
67
- Layout/MultilineMethodCallIndentation:
68
- Exclude:
69
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
70
-
71
- # Offense count: 1
72
- # This cop supports safe autocorrection (--autocorrect).
73
- # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
74
- # SupportedStyles: space, no_space, compact
75
- # SupportedStylesForEmptyBrackets: space, no_space
76
- Layout/SpaceInsideArrayLiteralBrackets:
77
- Exclude:
78
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
79
-
80
- # Offense count: 5
81
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
82
- Lint/AmbiguousBlockAssociation:
83
- Exclude:
84
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
85
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
86
- - 'spec/requests/payment_requests_spec.rb'
87
-
88
- # Offense count: 2
89
- # This cop supports safe autocorrection (--autocorrect).
90
- Lint/RedundantCopDisableDirective:
91
- Exclude:
92
- - 'bin/sandbox_rails'
93
- - 'lib/generators/solidus_stripe/install/install_generator.rb'
94
-
95
- # Offense count: 10
96
- RSpec/AnyInstance:
97
- Exclude:
98
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
99
- - 'spec/requests/payment_requests_spec.rb'
100
-
101
- # Offense count: 6
102
- # Configuration parameters: Prefixes.
103
- # Prefixes: when, with, without
104
- RSpec/ContextWording:
105
- Exclude:
106
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
107
-
108
- # Offense count: 8
109
- # This cop supports unsafe autocorrection (--autocorrect-all).
110
- # Configuration parameters: EnforcedStyle.
111
- # SupportedStyles: method_call, block
112
- RSpec/ExpectChange:
113
- Exclude:
114
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
115
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
116
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
117
-
118
- # Offense count: 6
119
- RSpec/ExpectInHook:
120
- Exclude:
121
- - 'spec/features/stripe_checkout_spec.rb'
122
-
123
- # Offense count: 1
124
- # This cop supports safe autocorrection (--autocorrect).
125
- RSpec/LeadingSubject:
126
- Exclude:
127
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
128
-
129
- # Offense count: 2
130
- RSpec/LetSetup:
131
- Exclude:
132
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
133
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
134
-
135
- # Offense count: 9
136
- # Configuration parameters: .
137
- # SupportedStyles: have_received, receive
138
- RSpec/MessageSpies:
139
- EnforcedStyle: receive
140
-
141
- # Offense count: 13
142
- RSpec/MultipleExpectations:
143
- Max: 15
144
-
145
- # Offense count: 40
146
- # Configuration parameters: AllowSubject.
147
- RSpec/MultipleMemoizedHelpers:
148
- Max: 11
149
-
150
- # Offense count: 47
151
- # Configuration parameters: IgnoreSharedExamples.
152
- RSpec/NamedSubject:
153
- Exclude:
154
- - 'spec/models/solidus_stripe/address_from_params_service_spec.rb'
155
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
156
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
157
- - 'spec/models/solidus_stripe/shipping_rates_service_spec.rb'
158
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
159
-
160
- # Offense count: 13
161
- RSpec/NestedGroups:
162
- Max: 5
163
-
164
- # Offense count: 2
165
- RSpec/RepeatedExampleGroupBody:
166
- Exclude:
167
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
168
-
169
- # Offense count: 3
170
- # This cop supports safe autocorrection (--autocorrect).
171
- # Configuration parameters: EnforcedStyle.
172
- # SupportedStyles: and_return, block
173
- RSpec/ReturnFromStub:
174
- Exclude:
175
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
176
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
177
-
178
- # Offense count: 4
179
- RSpec/StubbedMock:
180
- Exclude:
181
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
182
-
183
- # Offense count: 3
184
- RSpec/SubjectStub:
185
- Exclude:
186
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
187
-
188
- # Offense count: 12
189
- # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
190
- RSpec/VerifiedDoubles:
191
- Exclude:
192
- - 'spec/models/solidus_stripe/create_intents_payment_service_spec.rb'
193
- - 'spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb'
194
- - 'spec/models/spree/payment_method/stripe_credit_card_spec.rb'
195
-
196
- # Offense count: 1
197
- # This cop supports safe autocorrection (--autocorrect).
198
- # Configuration parameters: EnforceForPrefixed.
199
- Rails/Delegate:
200
- Exclude:
201
- - 'app/models/spree/payment_method/stripe_credit_card.rb'
202
-
203
- # Offense count: 1
204
- # This cop supports unsafe autocorrection (--autocorrect-all).
205
- # Configuration parameters: Whitelist, AllowedMethods, AllowedReceivers.
206
- # Whitelist: find_by_sql
207
- # AllowedMethods: find_by_sql
208
- # AllowedReceivers: Gem::Specification
209
- Rails/DynamicFindBy:
210
- Exclude:
211
- - 'app/models/solidus_stripe/address_from_params_service.rb'
212
-
213
- # Offense count: 1
214
- # This cop supports safe autocorrection (--autocorrect).
215
- # Configuration parameters: Include, IgnoredMethods.
216
- # Include: app/models/**/*.rb
217
- # IgnoredMethods: order, limit, select, lock
218
- Rails/FindEach:
219
- Exclude:
220
- - 'app/models/solidus_stripe/create_intents_payment_service.rb'
221
-
222
- # Offense count: 5
223
- # This cop supports unsafe autocorrection (--autocorrect-all).
224
- # Configuration parameters: Include.
225
- # Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
226
- Rails/Output:
227
- Exclude:
228
- - 'db/seeds.rb'
229
-
230
- # Offense count: 3
231
- # Configuration parameters: ForbiddenMethods, AllowedMethods.
232
- # ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
233
- Rails/SkipsModelValidations:
234
- Exclude:
235
- - 'db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb'
236
- - 'spec/models/solidus_stripe/shipping_rates_service_spec.rb'
237
-
238
- # Offense count: 1
239
- # This cop supports safe autocorrection (--autocorrect).
240
- # Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
241
- # SupportedStyles: assign_to_condition, assign_inside_condition
242
- Style/ConditionalAssignment:
243
- Exclude:
244
- - 'app/models/spree/payment_method/stripe_credit_card.rb'
245
-
246
- # Offense count: 1
247
- # This cop supports safe autocorrection (--autocorrect).
248
- Style/ExplicitBlockArgument:
249
- Exclude:
250
- - 'spec/features/stripe_checkout_spec.rb'
251
-
252
- # Offense count: 2
253
- # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
254
- Style/GuardClause:
255
- Exclude:
256
- - 'app/decorators/models/spree/order_update_attributes_decorator.rb'
257
- - 'app/models/solidus_stripe/create_intents_payment_service.rb'
258
-
259
- # Offense count: 1
260
- # This cop supports safe autocorrection (--autocorrect).
261
- Style/MultilineIfModifier:
262
- Exclude:
263
- - 'app/models/spree/payment_method/stripe_credit_card.rb'
264
-
265
- # Offense count: 1
266
- # This cop supports unsafe autocorrection (--autocorrect-all).
267
- # Configuration parameters: EnforcedStyle.
268
- # SupportedStyles: literals, strict
269
- Style/MutableConstant:
270
- Exclude:
271
- - 'app/models/spree/payment_method/stripe_credit_card.rb'
272
-
273
- # Offense count: 2
274
- # This cop supports safe autocorrection (--autocorrect).
275
- # Configuration parameters: AllowedMethods.
276
- # AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with
277
- Style/NestedParenthesizedCalls:
278
- Exclude:
279
- - 'lib/solidus_stripe/testing_support/card_input_helper.rb'
280
-
281
- # Offense count: 1
282
- # This cop supports safe autocorrection (--autocorrect).
283
- Style/RedundantBegin:
284
- Exclude:
285
- - 'app/models/solidus_stripe/address_from_params_service.rb'
286
-
287
- # Offense count: 1
288
- # This cop supports unsafe autocorrection (--autocorrect-all).
289
- Style/RedundantInterpolation:
290
- Exclude:
291
- - 'lib/solidus_stripe/testing_support/card_input_helper.rb'
292
-
293
- # Offense count: 19
294
- # This cop supports safe autocorrection (--autocorrect).
295
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
296
- # URISchemes: http, https
297
- Layout/LineLength:
298
- Max: 163
data/.travis.yml DELETED
@@ -1,28 +0,0 @@
1
- sudo: required
2
- dist: trusty
3
- cache: bundler
4
- language: ruby
5
- addons:
6
- chrome: stable
7
- rvm:
8
- - 2.5.1
9
- before_install:
10
- - mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'%';"
11
- before_script:
12
- - "export DISPLAY=:99.0"
13
- - "sh -e /etc/init.d/xvfb start"
14
- - sleep 3 # give xvfb some time to start
15
- env:
16
- matrix:
17
- - SOLIDUS_BRANCH=v2.4 DB=postgres
18
- - SOLIDUS_BRANCH=v2.5 DB=postgres
19
- - SOLIDUS_BRANCH=v2.6 DB=postgres
20
- - SOLIDUS_BRANCH=v2.7 DB=postgres
21
- - SOLIDUS_BRANCH=v2.8 DB=postgres
22
- - SOLIDUS_BRANCH=master DB=postgres
23
- - SOLIDUS_BRANCH=v2.4 DB=mysql
24
- - SOLIDUS_BRANCH=v2.5 DB=mysql
25
- - SOLIDUS_BRANCH=v2.6 DB=mysql
26
- - SOLIDUS_BRANCH=v2.7 DB=mysql
27
- - SOLIDUS_BRANCH=v2.8 DB=mysql
28
- - SOLIDUS_BRANCH=master DB=mysql
@@ -1,122 +0,0 @@
1
- SolidusStripe.CartPageCheckout = function() {
2
- SolidusStripe.Payment.call(this);
3
-
4
- this.errorElement = $('#card-errors');
5
- };
6
-
7
- SolidusStripe.CartPageCheckout.prototype = Object.create(SolidusStripe.Payment.prototype);
8
- Object.defineProperty(SolidusStripe.CartPageCheckout.prototype, 'constructor', {
9
- value: SolidusStripe.CartPageCheckout,
10
- enumerable: false,
11
- writable: true
12
- });
13
-
14
- SolidusStripe.CartPageCheckout.prototype.init = function() {
15
- this.setUpPaymentRequest({requestShipping: true});
16
- };
17
-
18
- SolidusStripe.CartPageCheckout.prototype.showError = function(error) {
19
- var message = error.message || error;
20
-
21
- this.errorElement.text(message).show();
22
- };
23
-
24
- SolidusStripe.CartPageCheckout.prototype.submitPayment = function(payment) {
25
- var showError = this.showError.bind(this);
26
- var prTokenHandler = this.prTokenHandler.bind(this);
27
-
28
- $.ajax({
29
- url: $('[data-submit-url]').data('submit-url'),
30
- headers: {
31
- 'X-Spree-Order-Token': $('[data-order-token]').data('order-token')
32
- },
33
- type: 'PATCH',
34
- contentType: 'application/json',
35
- data: JSON.stringify(prTokenHandler(payment.paymentMethod)),
36
- success: function() {
37
- window.location = $('[data-complete-url]').data('complete-url');
38
- },
39
- error: function(xhr,status,error) {
40
- showError(xhr.responseJSON.error);
41
- }
42
- });
43
- };
44
-
45
- SolidusStripe.CartPageCheckout.prototype.onPrPayment = function(payment) {
46
- var createIntent = this.createIntent.bind(this);
47
-
48
- fetch('/stripe/update_order', {
49
- method: 'POST',
50
- headers: { 'Content-Type': 'application/json' },
51
- body: JSON.stringify({
52
- shipping_address: payment.shippingAddress,
53
- shipping_option: payment.shippingOption,
54
- email: payment.payerEmail,
55
- name: payment.payerName,
56
- phone: payment.payerPhone,
57
- authenticity_token: this.authToken
58
- })
59
- }).then(function(response) {
60
- response.json().then(function(json) {
61
- createIntent(json, payment);
62
- })
63
- });
64
- };
65
-
66
- SolidusStripe.CartPageCheckout.prototype.createIntent = function(result, payment) {
67
- var handleServerResponse = this.handleServerResponse.bind(this);
68
-
69
- if (result.error) {
70
- this.completePaymentRequest(payment, 'fail');
71
- this.showError(result.error);
72
- } else {
73
- if (payment.error) {
74
- this.showError(payment.error.message);
75
- } else {
76
- fetch('/stripe/create_intent', {
77
- method: 'POST',
78
- headers: {
79
- 'Content-Type': 'application/json'
80
- },
81
- body: JSON.stringify({
82
- form_data: payment.shippingAddress,
83
- spree_payment_method_id: this.config.id,
84
- stripe_payment_method_id: payment.paymentMethod.id,
85
- authenticity_token: this.authToken
86
- })
87
- }).then(function(response) {
88
- response.json().then(function(result) {
89
- handleServerResponse(result, payment)
90
- })
91
- });
92
- }
93
- }
94
- };
95
-
96
- SolidusStripe.CartPageCheckout.prototype.onPrButtonMounted = function(buttonId, success) {
97
- var container = document.getElementById(buttonId).parentElement;
98
-
99
- if (success) {
100
- container.style.display = '';
101
- } else {
102
- container.style.display = 'none';
103
- }
104
- };
105
-
106
- SolidusStripe.CartPageCheckout.prototype.prTokenHandler = function(token) {
107
- return {
108
- order: {
109
- payments_attributes: [
110
- {
111
- payment_method_id: this.config.id,
112
- source_attributes: {
113
- gateway_payment_profile_id: token.id,
114
- last_digits: token.card.last4,
115
- month: token.card.exp_month,
116
- year: token.card.exp_year
117
- }
118
- }
119
- ]
120
- }
121
- }
122
- };
@@ -1,148 +0,0 @@
1
- SolidusStripe.Elements = function() {
2
- SolidusStripe.Payment.call(this);
3
-
4
- this.form = this.element.parents('form');
5
- this.errorElement = this.form.find('#card-errors');
6
- this.submitButton = this.form.find('input[type="submit"]');
7
- };
8
-
9
- SolidusStripe.Elements.prototype = Object.create(SolidusStripe.Payment.prototype);
10
- Object.defineProperty(SolidusStripe.Elements.prototype, 'constructor', {
11
- value: SolidusStripe.Elements,
12
- enumerable: false,
13
- writable: true
14
- });
15
-
16
- SolidusStripe.Elements.prototype.init = function() {
17
- this.initElements();
18
- };
19
-
20
- SolidusStripe.Elements.prototype.initElements = function() {
21
- var cardExpiry = this.elements.create('cardExpiry', this.cardExpiryElementOptions());
22
- cardExpiry.mount('#card_expiry');
23
-
24
- var cardCvc = this.elements.create('cardCvc', this.cardCvcElementOptions());
25
- cardCvc.mount('#card_cvc');
26
-
27
- this.cardNumber = this.elements.create('cardNumber', this.cardNumberElementOptions());
28
- this.cardNumber.mount('#card_number');
29
-
30
- this.form.bind('submit', this.onFormSubmit.bind(this));
31
-
32
- // Listen for errors from each input field.
33
- // Adapted from https://github.com/stripe/elements-examples/blob/master/js/index.js
34
- var savedErrors = {};
35
- [cardExpiry, cardCvc, this.cardNumber].forEach(function(element, idx) {
36
- element.on('change', function(event) {
37
- if (event.error) {
38
- savedErrors[idx] = event.error.message;
39
- this.showError(event.error.message);
40
- } else {
41
- savedErrors[idx] = null;
42
-
43
- // Loop over the saved errors and find the first one, if any.
44
- var nextError = Object.keys(savedErrors)
45
- .sort()
46
- .reduce(function(maybeFoundError, key) {
47
- return maybeFoundError || savedErrors[key];
48
- }, null);
49
-
50
- if (nextError) {
51
- // Now that they've fixed the current error, show another one.
52
- this.showError(nextError);
53
- } else {
54
- // The user fixed the last error; no more errors.
55
- this.errorElement.hide().text('');
56
- }
57
- }
58
- }.bind(this));
59
- }.bind(this));
60
- };
61
-
62
- SolidusStripe.Elements.prototype.baseStyle = function () {
63
- return {
64
- base: {
65
- color: 'black',
66
- fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
67
- fontSmoothing: 'antialiased',
68
- fontSize: '14px',
69
- '::placeholder': {
70
- color: 'silver'
71
- }
72
- },
73
- invalid: {
74
- color: 'red',
75
- iconColor: 'red'
76
- }
77
- };
78
- };
79
-
80
- SolidusStripe.Elements.prototype.cardNumberElementOptions = function () {
81
- return {
82
- style: this.baseStyle()
83
- }
84
- }
85
-
86
- SolidusStripe.Elements.prototype.cardExpiryElementOptions = function () {
87
- return {
88
- style: this.baseStyle()
89
- }
90
- }
91
-
92
- SolidusStripe.Elements.prototype.cardCvcElementOptions = function () {
93
- return {
94
- style: this.baseStyle()
95
- }
96
- }
97
-
98
- SolidusStripe.Elements.prototype.showError = function(error) {
99
- var message = error.message || error;
100
-
101
- this.errorElement.text(message).show();
102
- this.submitButton.removeAttr('disabled').removeClass('disabled');
103
- };
104
-
105
- SolidusStripe.Elements.prototype.onFormSubmit = function(event) {
106
- if (this.element.is(':visible')) {
107
- event.preventDefault();
108
-
109
- var onTokenCreate = function(result) {
110
- if (result.error) {
111
- this.showError(result.error.message);
112
- } else {
113
- this.elementsTokenHandler(result.token);
114
- this.form[0].submit();
115
- }
116
- };
117
-
118
- this.stripe.createToken(this.cardNumber).then(onTokenCreate.bind(this));
119
- }
120
- };
121
-
122
- SolidusStripe.Elements.prototype.elementsTokenHandler = function(token) {
123
- var mapCC = function(ccType) {
124
- if (ccType === 'MasterCard' || ccType === 'mastercard') {
125
- return 'mastercard';
126
- } else if (ccType === 'Visa' || ccType === 'visa') {
127
- return 'visa';
128
- } else if (ccType === 'American Express' || ccType === 'amex') {
129
- return 'amex';
130
- } else if (ccType === 'Discover' || ccType === 'discover') {
131
- return 'discover';
132
- } else if (ccType === 'Diners Club' || ccType === 'diners') {
133
- return 'dinersclub';
134
- } else if (ccType === 'JCB' || ccType === 'jcb') {
135
- return 'jcb';
136
- } else if (ccType === 'Unionpay' || ccType === 'unionpay') {
137
- return 'unionpay';
138
- }
139
- };
140
-
141
- var baseSelector = `<input type='hidden' class='stripeToken' name='payment_source[${this.config.id}]`;
142
-
143
- this.element.append(`${baseSelector}[gateway_payment_profile_id]' value='${token.id}'/>`);
144
- this.element.append(`${baseSelector}[last_digits]' value='${token.card.last4}'/>`);
145
- this.element.append(`${baseSelector}[month]' value='${token.card.exp_month}'/>`);
146
- this.element.append(`${baseSelector}[year]' value='${token.card.exp_year}'/>`);
147
- this.form.find('input#cc_type').val(mapCC(token.card.brand || token.card.type));
148
- };
@@ -1,20 +0,0 @@
1
- $(function() {
2
- var stripeV3Api = $('[data-v3-api]').data('v3-api');
3
-
4
- if (stripeV3Api) {
5
- $.getScript('https://js.stripe.com/v3/')
6
- .done(function() {
7
- switch (stripeV3Api) {
8
- case 'elements':
9
- new SolidusStripe.Elements().init();
10
- break;
11
- case 'payment-intents':
12
- new SolidusStripe.PaymentIntents().init();
13
- break;
14
- case 'payment-request-button':
15
- new SolidusStripe.CartPageCheckout().init();
16
- break;
17
- }
18
- });
19
- }
20
- });
@@ -1,84 +0,0 @@
1
- SolidusStripe.PaymentIntents = function() {
2
- SolidusStripe.Elements.call(this);
3
- };
4
-
5
- SolidusStripe.PaymentIntents.prototype = Object.create(SolidusStripe.Elements.prototype);
6
- Object.defineProperty(SolidusStripe.PaymentIntents.prototype, 'constructor', {
7
- value: SolidusStripe.PaymentIntents,
8
- enumerable: false,
9
- writable: true
10
- });
11
-
12
- SolidusStripe.PaymentIntents.prototype.init = function() {
13
- this.setUpPaymentRequest();
14
- this.initElements();
15
- };
16
-
17
- SolidusStripe.PaymentIntents.prototype.onPrPayment = function(payment) {
18
- if (payment.error) {
19
- this.showError(payment.error.message);
20
- } else {
21
- var that = this;
22
-
23
- this.elementsTokenHandler(payment.paymentMethod);
24
- fetch('/stripe/create_intent', {
25
- method: 'POST',
26
- headers: {
27
- 'Content-Type': 'application/json'
28
- },
29
- body: JSON.stringify({
30
- form_data: this.form.serialize(),
31
- spree_payment_method_id: this.config.id,
32
- stripe_payment_method_id: payment.paymentMethod.id,
33
- authenticity_token: this.authToken
34
- })
35
- }).then(function(response) {
36
- response.json().then(function(json) {
37
- that.handleServerResponse(json, payment);
38
- })
39
- });
40
- }
41
- };
42
-
43
- SolidusStripe.PaymentIntents.prototype.onFormSubmit = function(event) {
44
- if (this.element.is(':visible')) {
45
- event.preventDefault();
46
-
47
- this.errorElement.text('').hide();
48
-
49
- this.stripe.createPaymentMethod(
50
- 'card',
51
- this.cardNumber
52
- ).then(this.onIntentsPayment.bind(this));
53
- }
54
- };
55
-
56
- SolidusStripe.PaymentIntents.prototype.submitPayment = function(_payment) {
57
- this.form.unbind('submit').submit();
58
- };
59
-
60
- SolidusStripe.PaymentIntents.prototype.onIntentsPayment = function(payment) {
61
- if (payment.error) {
62
- this.showError(payment.error.message);
63
- } else {
64
- var that = this;
65
-
66
- this.elementsTokenHandler(payment.paymentMethod);
67
- fetch('/stripe/create_intent', {
68
- method: 'POST',
69
- headers: {
70
- 'Content-Type': 'application/json'
71
- },
72
- body: JSON.stringify({
73
- form_data: this.form.serialize(),
74
- spree_payment_method_id: this.config.id,
75
- stripe_payment_method_id: payment.paymentMethod.id,
76
- authenticity_token: this.authToken
77
- })
78
- }).then(function(response) {
79
- response.json().then(function(json) {
80
- that.handleServerResponse(json, payment);
81
- })
82
- });
83
- }
84
- };