solidus_stripe 4.4.0 → 5.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +95 -41
- data/.gitignore +3 -0
- data/.rubocop.yml +94 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +1 -265
- data/Gemfile +10 -30
- data/LICENSE +2 -2
- data/Procfile.dev +3 -0
- data/README.md +145 -215
- data/Rakefile +7 -6
- data/app/assets/javascripts/spree/backend/solidus_stripe.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_stripe.css +4 -0
- data/app/controllers/solidus_stripe/intents_controller.rb +36 -52
- data/app/controllers/solidus_stripe/webhooks_controller.rb +28 -0
- data/app/models/concerns/solidus_stripe/log_entries.rb +31 -0
- data/app/models/solidus_stripe/customer.rb +21 -0
- data/app/models/solidus_stripe/gateway.rb +231 -0
- data/app/models/solidus_stripe/payment_intent.rb +111 -0
- data/app/models/solidus_stripe/payment_method.rb +106 -0
- data/app/models/solidus_stripe/payment_source.rb +31 -0
- data/app/models/solidus_stripe/slug_entry.rb +20 -0
- data/app/models/solidus_stripe.rb +7 -0
- data/app/subscribers/solidus_stripe/webhook/charge_subscriber.rb +28 -0
- data/app/subscribers/solidus_stripe/webhook/payment_intent_subscriber.rb +112 -0
- data/app/views/spree/admin/payments/source_forms/_stripe.html.erb +29 -0
- data/app/views/spree/admin/payments/source_forms/existing_payment/_stripe.html.erb +14 -0
- data/app/views/spree/admin/payments/source_forms/existing_payment/stripe/_card.html.erb +8 -0
- data/app/views/spree/admin/payments/source_forms/existing_payment/stripe/_default.html.erb +7 -0
- data/app/views/spree/admin/payments/source_views/_stripe.html.erb +15 -0
- data/app/views/spree/api/payments/source_views/_stripe.json.jbuilder +8 -0
- data/bin/dev +13 -0
- data/bin/dummy-app +29 -0
- data/bin/rails +38 -3
- data/bin/rails-dummy-app +3 -0
- data/bin/rails-engine +1 -11
- data/bin/rails-new +55 -0
- data/bin/rails-sandbox +1 -14
- data/bin/rspec +10 -0
- data/bin/sandbox +12 -74
- data/bin/setup +1 -0
- data/bin/update-migrations +56 -0
- data/codecov.yml +12 -0
- data/config/locales/en.yml +16 -1
- data/config/routes.rb +5 -11
- data/coverage.rb +42 -0
- data/db/migrate/20230109183332_create_solidus_stripe_payment_sources.rb +10 -0
- data/db/migrate/20230303154931_create_solidus_stripe_setup_intent.rb +10 -0
- data/db/migrate/20230306105520_create_solidus_stripe_payment_intents.rb +10 -0
- data/db/migrate/20230308122414_create_solidus_stripe_webhook_endpoints.rb +10 -0
- data/db/migrate/20230310152615_add_payment_method_reference_to_stripe_intents.rb +6 -0
- data/db/migrate/20230310171444_normalize_stripe_intent_id_attributes.rb +6 -0
- data/db/migrate/20230313150008_create_solidus_stripe_customers.rb +16 -0
- data/db/migrate/20230323154931_drop_solidus_stripe_setup_intent.rb +13 -0
- data/db/migrate/20230403094916_rename_webhook_endpoint_to_payment_method_slug_entries.rb +5 -0
- data/db/seeds.rb +6 -24
- data/lib/generators/solidus_stripe/install/install_generator.rb +121 -14
- data/lib/generators/solidus_stripe/install/templates/app/assets/stylesheets/spree/frontend/solidus_stripe.css +13 -0
- data/lib/generators/solidus_stripe/install/templates/app/javascript/controllers/solidus_stripe_confirm_controller.js +39 -0
- data/lib/generators/solidus_stripe/install/templates/app/javascript/controllers/solidus_stripe_payment_controller.js +89 -0
- data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/_stripe.html.erb +16 -0
- data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/stripe/_card.html.erb +8 -0
- data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/existing_payment/stripe/_default.html.erb +7 -0
- data/lib/generators/solidus_stripe/install/templates/app/views/checkouts/payment/_stripe.html.erb +39 -0
- data/lib/generators/solidus_stripe/install/templates/app/views/orders/payment_info/_stripe.html.erb +20 -0
- data/lib/generators/solidus_stripe/install/templates/config/initializers/solidus_stripe.rb +31 -0
- data/lib/solidus_stripe/configuration.rb +24 -3
- data/lib/solidus_stripe/engine.rb +19 -6
- data/lib/solidus_stripe/money_to_stripe_amount_converter.rb +109 -0
- data/lib/solidus_stripe/refunds_synchronizer.rb +96 -0
- data/lib/solidus_stripe/seeds.rb +19 -0
- data/lib/solidus_stripe/testing_support/factories.rb +153 -0
- data/lib/solidus_stripe/version.rb +1 -1
- data/lib/solidus_stripe/webhook/event.rb +90 -0
- data/lib/solidus_stripe.rb +0 -2
- data/solidus_stripe.gemspec +29 -6
- data/spec/lib/solidus_stripe/configuration_spec.rb +21 -0
- data/spec/lib/solidus_stripe/money_to_stripe_amount_converter_spec.rb +133 -0
- data/spec/lib/solidus_stripe/refunds_synchronizer_spec.rb +238 -0
- data/spec/lib/solidus_stripe/seeds_spec.rb +43 -0
- data/spec/lib/solidus_stripe/webhook/event_spec.rb +134 -0
- data/spec/models/concerns/solidus_stripe/log_entries_spec.rb +54 -0
- data/spec/models/solidus_stripe/customer_spec.rb +47 -0
- data/spec/models/solidus_stripe/gateway_spec.rb +283 -0
- data/spec/models/solidus_stripe/payment_intent_spec.rb +17 -0
- data/spec/models/solidus_stripe/payment_method_spec.rb +137 -0
- data/spec/models/solidus_stripe/payment_source_spec.rb +25 -0
- data/spec/requests/solidus_stripe/intents_controller_spec.rb +29 -0
- data/spec/requests/solidus_stripe/webhooks_controller/charge/refunded_spec.rb +31 -0
- data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/canceled_spec.rb +23 -0
- data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/payment_failed_spec.rb +23 -0
- data/spec/requests/solidus_stripe/webhooks_controller/payment_intent/succeeded_spec.rb +29 -0
- data/spec/requests/solidus_stripe/webhooks_controller_spec.rb +52 -0
- data/spec/solidus_stripe_spec_helper.rb +10 -0
- data/spec/subscribers/solidus_stripe/webhook/charge_subscriber_spec.rb +33 -0
- data/spec/subscribers/solidus_stripe/webhook/payment_intent_subscriber_spec.rb +297 -0
- data/spec/support/solidus_stripe/backend_test_helper.rb +210 -0
- data/spec/support/solidus_stripe/checkout_test_helper.rb +339 -0
- data/spec/support/solidus_stripe/factories.rb +5 -0
- data/spec/support/solidus_stripe/webhook/data_fixtures.rb +106 -0
- data/spec/support/solidus_stripe/webhook/event_with_context_factory.rb +82 -0
- data/spec/support/solidus_stripe/webhook/request_helper.rb +32 -0
- data/spec/system/backend/solidus_stripe/orders/payments_spec.rb +119 -0
- data/spec/system/frontend/.keep +0 -0
- data/spec/system/frontend/solidus_stripe/checkout_spec.rb +187 -0
- data/tmp/.keep +0 -0
- metadata +201 -75
- data/.rubocop_todo.yml +0 -298
- data/.travis.yml +0 -28
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-cart-page-checkout.js +0 -122
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-elements.js +0 -148
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-init.js +0 -20
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-intents.js +0 -84
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment-request-button-shared.js +0 -160
- data/app/assets/javascripts/spree/frontend/solidus_stripe/stripe-payment.js +0 -16
- data/app/assets/javascripts/spree/frontend/solidus_stripe.js +0 -6
- data/app/controllers/solidus_stripe/payment_request_controller.rb +0 -52
- data/app/controllers/spree/stripe_controller.rb +0 -13
- data/app/decorators/models/spree/order_update_attributes_decorator.rb +0 -39
- data/app/decorators/models/spree/payment_decorator.rb +0 -11
- data/app/decorators/models/spree/refund_decorator.rb +0 -9
- data/app/models/solidus_stripe/address_from_params_service.rb +0 -72
- data/app/models/solidus_stripe/create_intents_payment_service.rb +0 -114
- data/app/models/solidus_stripe/prepare_order_for_payment_service.rb +0 -46
- data/app/models/solidus_stripe/shipping_rates_service.rb +0 -46
- data/app/models/spree/payment_method/stripe_credit_card.rb +0 -230
- data/bin/r +0 -13
- data/bin/sandbox_rails +0 -18
- data/db/migrate/20181010123508_update_stripe_payment_method_type_to_credit_card.rb +0 -21
- data/lib/assets/stylesheets/spree/frontend/solidus_stripe.scss +0 -11
- data/lib/solidus_stripe/testing_support/card_input_helper.rb +0 -34
- data/lib/tasks/solidus_stripe/db/seed.rake +0 -14
- data/lib/views/api/spree/api/payments/source_views/_stripe.json.jbuilder +0 -3
- data/lib/views/backend/spree/admin/log_entries/_stripe.html.erb +0 -28
- data/lib/views/backend/spree/admin/payments/source_forms/_stripe.html.erb +0 -1
- data/lib/views/backend/spree/admin/payments/source_views/_stripe.html.erb +0 -1
- data/lib/views/frontend/spree/checkout/existing_payment/_stripe.html.erb +0 -1
- data/lib/views/frontend/spree/checkout/payment/_stripe.html.erb +0 -8
- data/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb +0 -78
- data/lib/views/frontend/spree/checkout/payment/v3/_elements.html.erb +0 -1
- data/lib/views/frontend/spree/checkout/payment/v3/_form_elements.html.erb +0 -40
- data/lib/views/frontend/spree/checkout/payment/v3/_intents.html.erb +0 -1
- data/lib/views/frontend/spree/checkout/payment/v3/_stripe.html.erb +0 -2
- data/lib/views/frontend/spree/orders/_stripe_payment_request_button.html.erb +0 -14
- data/spec/features/stripe_checkout_spec.rb +0 -486
- data/spec/models/solidus_stripe/address_from_params_service_spec.rb +0 -87
- data/spec/models/solidus_stripe/create_intents_payment_service_spec.rb +0 -127
- data/spec/models/solidus_stripe/prepare_order_for_payment_service_spec.rb +0 -65
- data/spec/models/solidus_stripe/shipping_rates_service_spec.rb +0 -54
- data/spec/models/spree/payment_method/stripe_credit_card_spec.rb +0 -350
- data/spec/requests/payment_requests_spec.rb +0 -152
- data/spec/spec_helper.rb +0 -37
- data/spec/support/solidus_address_helper.rb +0 -15
@@ -1,230 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
class PaymentMethod
|
5
|
-
class StripeCreditCard < Spree::PaymentMethod::CreditCard
|
6
|
-
preference :secret_key, :string
|
7
|
-
preference :publishable_key, :string
|
8
|
-
preference :stripe_country, :string
|
9
|
-
preference :v3_elements, :boolean
|
10
|
-
preference :v3_intents, :boolean
|
11
|
-
|
12
|
-
CARD_TYPE_MAPPING = {
|
13
|
-
'American Express' => 'american_express',
|
14
|
-
'Diners Club' => 'diners_club',
|
15
|
-
'Visa' => 'visa'
|
16
|
-
}
|
17
|
-
|
18
|
-
delegate :create_intent, :update_intent, :confirm_intent, :show_intent, to: :gateway
|
19
|
-
|
20
|
-
def stripe_config(order)
|
21
|
-
{
|
22
|
-
id: id,
|
23
|
-
publishable_key: preferred_publishable_key
|
24
|
-
}.tap do |config|
|
25
|
-
config.merge!(
|
26
|
-
payment_request: {
|
27
|
-
country: preferred_stripe_country,
|
28
|
-
currency: order.currency.downcase,
|
29
|
-
label: "Payment for order #{order.number}",
|
30
|
-
amount: (order.total * 100).to_i
|
31
|
-
}
|
32
|
-
) if payment_request?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def partial_name
|
37
|
-
'stripe'
|
38
|
-
end
|
39
|
-
|
40
|
-
def v3_elements?
|
41
|
-
!!preferred_v3_elements
|
42
|
-
end
|
43
|
-
|
44
|
-
def payment_request?
|
45
|
-
v3_intents? && preferred_stripe_country.present?
|
46
|
-
end
|
47
|
-
|
48
|
-
def v3_intents?
|
49
|
-
!!preferred_v3_intents
|
50
|
-
end
|
51
|
-
|
52
|
-
def gateway_class
|
53
|
-
if v3_intents?
|
54
|
-
ActiveMerchant::Billing::StripePaymentIntentsGateway
|
55
|
-
else
|
56
|
-
ActiveMerchant::Billing::StripeGateway
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def payment_profiles_supported?
|
61
|
-
true
|
62
|
-
end
|
63
|
-
|
64
|
-
def non_fractional_money(money, currency)
|
65
|
-
amount = money.is_a?(Integer) ? money : money.cents
|
66
|
-
Spree::Money.new((amount * 100), { currency: currency })
|
67
|
-
end
|
68
|
-
|
69
|
-
def localize(money, currency)
|
70
|
-
ActiveMerchant::Billing::Gateway.currencies_without_fractions.include?(currency) ? non_fractional_money(money, currency) : money
|
71
|
-
end
|
72
|
-
|
73
|
-
def purchase(money, creditcard, transaction_options)
|
74
|
-
gateway.purchase(*options_for_purchase_or_auth(localize(money, transaction_options[:currency]), creditcard, transaction_options))
|
75
|
-
end
|
76
|
-
|
77
|
-
def authorize(money, creditcard, transaction_options)
|
78
|
-
gateway.authorize(*options_for_purchase_or_auth(localize(money, transaction_options[:currency]), creditcard, transaction_options))
|
79
|
-
end
|
80
|
-
|
81
|
-
def capture(money, response_code, transaction_options)
|
82
|
-
gateway.capture(localize(money, transaction_options[:currency]), response_code, transaction_options)
|
83
|
-
end
|
84
|
-
|
85
|
-
def credit(money, _creditcard, response_code, transaction_options)
|
86
|
-
gateway.refund(localize(money, transaction_options[:currency]), response_code, {})
|
87
|
-
end
|
88
|
-
|
89
|
-
def void(response_code, _creditcard, _transaction_options)
|
90
|
-
gateway.void(response_code, {})
|
91
|
-
end
|
92
|
-
|
93
|
-
def payment_intents_refund_reason
|
94
|
-
Spree::RefundReason.where(name: Spree::Payment::Cancellation::DEFAULT_REASON).first_or_create
|
95
|
-
end
|
96
|
-
|
97
|
-
def try_void(payment)
|
98
|
-
if v3_intents? && payment.completed?
|
99
|
-
refund = perform_refund(payment)
|
100
|
-
|
101
|
-
if refund.respond_to?(:perform_response)
|
102
|
-
refund.perform_response
|
103
|
-
else
|
104
|
-
refund.response
|
105
|
-
end
|
106
|
-
else
|
107
|
-
void(payment.response_code, nil, nil)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def cancel(response_code)
|
112
|
-
gateway.void(response_code, {})
|
113
|
-
end
|
114
|
-
|
115
|
-
def create_profile(payment)
|
116
|
-
return unless payment.source.gateway_customer_profile_id.nil?
|
117
|
-
|
118
|
-
options = {
|
119
|
-
email: payment.order.email,
|
120
|
-
login: preferred_secret_key,
|
121
|
-
}.merge! address_for(payment)
|
122
|
-
|
123
|
-
source = update_source!(payment.source)
|
124
|
-
if reuse_existing_source?(source)
|
125
|
-
if v3_intents?
|
126
|
-
creditcard = ActiveMerchant::Billing::StripeGateway::StripePaymentToken.new('id' => source.gateway_payment_profile_id)
|
127
|
-
else
|
128
|
-
creditcard = source.gateway_payment_profile_id
|
129
|
-
end
|
130
|
-
else
|
131
|
-
creditcard = source
|
132
|
-
end
|
133
|
-
|
134
|
-
response = gateway.store(creditcard, options)
|
135
|
-
if response.success?
|
136
|
-
if v3_intents? && reuse_existing_source?(source)
|
137
|
-
payment.source.update!(
|
138
|
-
cc_type: payment.source.cc_type,
|
139
|
-
gateway_customer_profile_id: response.params['customer'],
|
140
|
-
gateway_payment_profile_id: response.params['id']
|
141
|
-
)
|
142
|
-
else
|
143
|
-
payment.source.update!(
|
144
|
-
cc_type: payment.source.cc_type,
|
145
|
-
gateway_customer_profile_id: response.params['id'],
|
146
|
-
gateway_payment_profile_id: response.params['default_source'] || response.params['default_card']
|
147
|
-
)
|
148
|
-
end
|
149
|
-
else
|
150
|
-
payment.send(:gateway_error, response.message)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
private
|
155
|
-
|
156
|
-
# In this gateway, what we call 'secret_key' is the 'login'
|
157
|
-
def options
|
158
|
-
options = super
|
159
|
-
options.merge(login: preferred_secret_key)
|
160
|
-
end
|
161
|
-
|
162
|
-
def options_for_purchase_or_auth(money, creditcard, transaction_options)
|
163
|
-
options = {}
|
164
|
-
options[:description] = "Solidus Order ID: #{transaction_options[:order_id]}"
|
165
|
-
options[:currency] = transaction_options[:currency]
|
166
|
-
options[:off_session] = true if v3_intents?
|
167
|
-
options[:statement_descriptor_suffix] = transaction_options[:statement_descriptor_suffix] if transaction_options[:statement_descriptor_suffix]
|
168
|
-
|
169
|
-
if customer = creditcard.gateway_customer_profile_id
|
170
|
-
options[:customer] = customer
|
171
|
-
end
|
172
|
-
if token_or_card_id = creditcard.gateway_payment_profile_id
|
173
|
-
# The Stripe ActiveMerchant gateway supports passing the token directly as the creditcard parameter
|
174
|
-
# The Stripe ActiveMerchant gateway supports passing the customer_id and credit_card id
|
175
|
-
# https://github.com/Shopify/active_merchant/issues/770
|
176
|
-
creditcard = token_or_card_id
|
177
|
-
end
|
178
|
-
[money, creditcard, options]
|
179
|
-
end
|
180
|
-
|
181
|
-
def address_for(payment)
|
182
|
-
{}.tap do |options|
|
183
|
-
if address = payment.order.bill_address
|
184
|
-
options[:address] = {
|
185
|
-
address1: address.address1,
|
186
|
-
address2: address.address2,
|
187
|
-
city: address.city,
|
188
|
-
zip: address.zipcode
|
189
|
-
}
|
190
|
-
|
191
|
-
if country = address.country
|
192
|
-
options[:address][:country] = country.name
|
193
|
-
end
|
194
|
-
|
195
|
-
if state = address.state
|
196
|
-
options[:address].merge!(state: state.name)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def update_source!(source)
|
203
|
-
source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
|
204
|
-
source
|
205
|
-
end
|
206
|
-
|
207
|
-
def perform_refund(payment)
|
208
|
-
refund = payment.refunds.build(
|
209
|
-
amount: payment.credit_allowed,
|
210
|
-
reason: payment_intents_refund_reason
|
211
|
-
)
|
212
|
-
|
213
|
-
if refund.respond_to?(:perform_after_create)
|
214
|
-
refund.perform_after_create = false
|
215
|
-
refund.save!
|
216
|
-
refund.perform!
|
217
|
-
else
|
218
|
-
refund.save!
|
219
|
-
refund.perform! if Gem::Requirement.new('>= 3.0.0.alpha').satisfied_by?(Spree.solidus_gem_version)
|
220
|
-
end
|
221
|
-
|
222
|
-
refund
|
223
|
-
end
|
224
|
-
|
225
|
-
def reuse_existing_source?(source)
|
226
|
-
source.number.blank? && source.gateway_payment_profile_id.present?
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
data/bin/r
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
-
# installed from the root of your application.
|
4
|
-
|
5
|
-
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
-
ENGINE_PATH = File.expand_path('../lib/solidus_stripe/engine', __dir__)
|
7
|
-
|
8
|
-
# Set up gems listed in the Gemfile.
|
9
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
-
|
12
|
-
require 'rails/all'
|
13
|
-
require 'rails/engine/commands'
|
data/bin/sandbox_rails
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
app_root = 'sandbox'
|
6
|
-
|
7
|
-
unless File.exist? "#{app_root}/bin/rails"
|
8
|
-
warn 'Creating the sandbox app...'
|
9
|
-
Dir.chdir "#{__dir__}/.." do
|
10
|
-
system "#{__dir__}/sandbox" or begin # rubocop:disable Style/AndOr
|
11
|
-
warn 'Automatic creation of the sandbox app failed'
|
12
|
-
exit 1
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Dir.chdir app_root
|
18
|
-
exec 'bin/rails', *ARGV
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class UpdateStripePaymentMethodTypeToCreditCard < SolidusSupport::Migration[5.1]
|
4
|
-
def up
|
5
|
-
Spree::PaymentMethod.where(type: 'Spree::Gateway::StripeGateway').update_all(type: 'Spree::PaymentMethod::StripeCreditCard')
|
6
|
-
|
7
|
-
Spree::Preference.where("#{ActiveRecord::Base.connection.quote_column_name('key')} LIKE 'spree/gateway/stripe_gateway'").each do |pref|
|
8
|
-
pref.key = pref.key.gsub('spree/gateway/stripe_gateway', 'spree/payment_method/stripe_credit_card')
|
9
|
-
pref.save
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def down
|
14
|
-
Spree::PaymentMethod.where(type: 'Spree::PaymentMethod::StripeCreditCard').update_all(type: 'Spree::Gateway::StripeGateway')
|
15
|
-
|
16
|
-
Spree::Preference.where("#{ActiveRecord::Base.connection.quote_column_name('key')} LIKE 'spree/payment_method/stripe_credit_card'").each do |pref|
|
17
|
-
pref.key = pref.key.gsub('spree/payment_method/stripe_credit_card', 'spree/gateway/stripe_gateway')
|
18
|
-
pref.save
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SolidusCardInputHelper
|
4
|
-
def fill_in_card(card = {})
|
5
|
-
card[:number] ||= "4242 4242 4242 4242"
|
6
|
-
card[:code] ||= "123"
|
7
|
-
card[:exp_month] ||= "01"
|
8
|
-
card[:exp_year] ||= "#{Time.zone.now.year + 1}"
|
9
|
-
|
10
|
-
if preferred_v3_elements || preferred_v3_intents
|
11
|
-
within_frame find('#card_number iframe') do
|
12
|
-
fill_in_number("cardnumber", card)
|
13
|
-
end
|
14
|
-
within_frame(find '#card_cvc iframe') { fill_in 'cvc', with: card[:code] }
|
15
|
-
within_frame(find '#card_expiry iframe') do
|
16
|
-
fill_in_expiration("exp-date", card)
|
17
|
-
end
|
18
|
-
else
|
19
|
-
fill_in_number("Card Number", card)
|
20
|
-
fill_in "Card Code", with: card[:code]
|
21
|
-
fill_in_expiration("Expiration", card)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def fill_in_number(field_name, card)
|
28
|
-
card[:number].split('').each { |n| find_field(field_name).native.send_keys(n) }
|
29
|
-
end
|
30
|
-
|
31
|
-
def fill_in_expiration(field_name, card)
|
32
|
-
"#{card[:exp_month]}#{card[:exp_year].last(2)}".split('').each { |n| find_field(field_name).native.send_keys(n) }
|
33
|
-
end
|
34
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :db do
|
4
|
-
namespace :seed do
|
5
|
-
desc 'Loads stripe sample data'
|
6
|
-
task solidus_stripe: :environment do
|
7
|
-
seed_file = Dir[SolidusStripe::Engine.root.join('db', 'seeds.rb')][0]
|
8
|
-
return unless File.exist?(seed_file)
|
9
|
-
|
10
|
-
puts "Seeding #{seed_file}..."
|
11
|
-
load(seed_file)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<tr>
|
2
|
-
<td><%= t(:message, :scope => [:spree, :log_entry, :stripe]) %></td>
|
3
|
-
<td><%= entry.parsed_details.message %></td>
|
4
|
-
</tr>
|
5
|
-
<tr>
|
6
|
-
<td><%= t(:charge_id, :scope => [:spree, :log_entry, :stripe]) %></td>
|
7
|
-
<td><%= entry.parsed_details.params['id'] %></td>
|
8
|
-
</tr>
|
9
|
-
<% if card = entry.parsed_details.params['card'] %>
|
10
|
-
<tr>
|
11
|
-
<td><%= t(:card_id, :scope => [:spree, :log_entry, :stripe]) %></td>
|
12
|
-
<td><%= card['id'] %></td>
|
13
|
-
</tr>
|
14
|
-
|
15
|
-
<tr>
|
16
|
-
<td><%= t(:cvc_check, :scope => [:spree, :log_entry, :stripe]) %></td>
|
17
|
-
<td><%= card['cvc_check'] %></td>
|
18
|
-
</tr>
|
19
|
-
|
20
|
-
<tr>
|
21
|
-
<td><%= t(:address_zip_check, :scope => [:spree, :log_entry, :stripe]) %></td>
|
22
|
-
<td><%= card['address_zip_check'] %></td>
|
23
|
-
</tr>
|
24
|
-
<% end %>
|
25
|
-
<tr>
|
26
|
-
<td><%= t(:cvv_result, :scope => [:spree, :log_entry, :stripe]) %></td>
|
27
|
-
<td><%= entry.parsed_details.cvv_result['message'].to_s %></td>
|
28
|
-
</tr>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render "spree/admin/payments/source_forms/gateway", payment_method: payment_method, previous_cards: payment_method.reusable_sources(@order) %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render "spree/admin/payments/source_views/gateway", payment: payment %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render partial: "spree/checkout/existing_payment/gateway", locals: { wallet_payment_source: wallet_payment_source, default: default } %>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
<% if payment_method.v3_elements? %>
|
2
|
-
<%= render 'spree/checkout/payment/v3/elements', payment_method: payment_method %>
|
3
|
-
<% elsif payment_method.v3_intents? %>
|
4
|
-
<%= render 'spree/checkout/payment/v3/intents', payment_method: payment_method %>
|
5
|
-
<% else %>
|
6
|
-
<%= render "spree/checkout/payment/gateway", payment_method: payment_method %>
|
7
|
-
<%= render 'spree/checkout/payment/v2/javascript', payment_method: payment_method %>
|
8
|
-
<% end %>
|
@@ -1,78 +0,0 @@
|
|
1
|
-
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
|
2
|
-
<script type="text/javascript">
|
3
|
-
Stripe.setPublishableKey("<%= payment_method.preferred_publishable_key %>");
|
4
|
-
</script>
|
5
|
-
|
6
|
-
<script>
|
7
|
-
window.SolidusStripe = window.SolidusStripe || {};
|
8
|
-
SolidusStripe.paymentMethod = $('#payment_method_' + <%= payment_method.id %>);
|
9
|
-
var mapCC, stripeResponseHandler;
|
10
|
-
|
11
|
-
mapCC = function(ccType) {
|
12
|
-
if (ccType === 'MasterCard') {
|
13
|
-
return 'mastercard';
|
14
|
-
} else if (ccType === 'Visa') {
|
15
|
-
return 'visa';
|
16
|
-
} else if (ccType === 'American Express') {
|
17
|
-
return 'amex';
|
18
|
-
} else if (ccType === 'Discover') {
|
19
|
-
return 'discover';
|
20
|
-
} else if (ccType === 'Diners Club') {
|
21
|
-
return 'dinersclub';
|
22
|
-
} else if (ccType === 'JCB') {
|
23
|
-
return 'jcb';
|
24
|
-
}
|
25
|
-
};
|
26
|
-
|
27
|
-
stripeResponseHandler = function(status, response) {
|
28
|
-
var paymentMethodId, token;
|
29
|
-
if (response.error) {
|
30
|
-
$('#stripeError').html(response.error.message);
|
31
|
-
return $('#stripeError').show();
|
32
|
-
} else {
|
33
|
-
SolidusStripe.paymentMethod.find('#card_number, #card_expiry, #card_code').prop("disabled", true);
|
34
|
-
SolidusStripe.paymentMethod.find(".ccType").prop("disabled", false);
|
35
|
-
SolidusStripe.paymentMethod.find(".ccType").val(mapCC(response.card.brand));
|
36
|
-
token = response['id'];
|
37
|
-
paymentMethodId = SolidusStripe.paymentMethod.prop('id').split("_")[2];
|
38
|
-
SolidusStripe.paymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][gateway_payment_profile_id]' value='" + token + "'/>");
|
39
|
-
SolidusStripe.paymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][last_digits]' value='" + response.card.last4 + "'/>");
|
40
|
-
SolidusStripe.paymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][month]' value='" + response.card.exp_month + "'/>");
|
41
|
-
SolidusStripe.paymentMethod.append("<input type='hidden' class='stripeToken' name='payment_source[" + paymentMethodId + "][year]' value='" + response.card.exp_year + "'/>");
|
42
|
-
return SolidusStripe.paymentMethod.parents("form").get(0).submit();
|
43
|
-
}
|
44
|
-
};
|
45
|
-
|
46
|
-
$(document).ready(function() {
|
47
|
-
SolidusStripe.paymentMethod.prepend("<div id='stripeError' class='errorExplanation' style='display:none'></div>");
|
48
|
-
return $('#checkout_form_payment [data-hook=buttons]').click(function() {
|
49
|
-
var expiration, params;
|
50
|
-
$('#stripeError').hide();
|
51
|
-
if (SolidusStripe.paymentMethod.is(':visible')) {
|
52
|
-
expiration = $('.cardExpiry:visible').payment('cardExpiryVal');
|
53
|
-
params = $.extend({
|
54
|
-
number: $('.cardNumber:visible').val(),
|
55
|
-
cvc: $('.cardCode:visible').val(),
|
56
|
-
exp_month: expiration.month || 0,
|
57
|
-
exp_year: expiration.year || 0
|
58
|
-
}, Spree.stripeAdditionalInfo);
|
59
|
-
Stripe.card.createToken(params, stripeResponseHandler);
|
60
|
-
return false;
|
61
|
-
}
|
62
|
-
});
|
63
|
-
});
|
64
|
-
</script>
|
65
|
-
|
66
|
-
<%- if @order.has_checkout_step?('address') -%>
|
67
|
-
<script>
|
68
|
-
Spree.stripeAdditionalInfo = {
|
69
|
-
name: "<%= SolidusSupport.combined_first_and_last_name_in_address? ? @order.bill_address.name : @order.bill_address.full_name %>",
|
70
|
-
address_line1: "<%= @order.bill_address.address1 %>",
|
71
|
-
address_line2: "<%= @order.bill_address.address2 %>",
|
72
|
-
address_city: "<%= @order.bill_address.city %>",
|
73
|
-
address_state: "<%= @order.bill_address.state_text %>",
|
74
|
-
address_zip: "<%= @order.bill_address.zipcode %>",
|
75
|
-
address_country: "<%= @order.bill_address.country %>"
|
76
|
-
}
|
77
|
-
</script>
|
78
|
-
<%- end -%>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method, stripe_v3_api: 'elements' %>
|
@@ -1,40 +0,0 @@
|
|
1
|
-
<div id="payment-request-button" data-stripe-config="<%= payment_method.stripe_config(current_order).to_json %>" data-v3-api="<%= stripe_v3_api %>"></div>
|
2
|
-
|
3
|
-
<% param_prefix = "payment_source[#{payment_method.id}]" %>
|
4
|
-
<% name = SolidusSupport.combined_first_and_last_name_in_address? ? @order.name : "#{@order.billing_firstname} #{@order.billing_lastname}" %>
|
5
|
-
|
6
|
-
<div class="field field-required">
|
7
|
-
<%= label_tag "name_on_card_#{payment_method.id}", t('spree.name_on_card') %>
|
8
|
-
<%= text_field_tag "#{param_prefix}[name]", name, { id: "name_on_card_#{payment_method.id}", autocomplete: "cc-name" } %>
|
9
|
-
</div>
|
10
|
-
|
11
|
-
<div class="field field-required" data-hook="card_number">
|
12
|
-
<%= label_tag "card_number", t('spree.card_number') %>
|
13
|
-
<div id="card_number"></div>
|
14
|
-
<span id="card_type" style="display:none;">
|
15
|
-
( <span id="looks_like" ><%= t('spree.card_type_is') %> <span id="type"></span></span>
|
16
|
-
<span id="unrecognized"><%= t('spree.unrecognized_card_type') %></span>
|
17
|
-
)
|
18
|
-
</span>
|
19
|
-
</div>
|
20
|
-
|
21
|
-
<div class="field field-required" data-hook="card_expiration">
|
22
|
-
<%= label_tag "card_expiry", t('spree.expiration') %>
|
23
|
-
<div id="card_expiry"></div>
|
24
|
-
</div>
|
25
|
-
|
26
|
-
<div class="field field-required" data-hook="card_code">
|
27
|
-
<%= label_tag "card_cvc", t('spree.card_code') %>
|
28
|
-
<div id="card_cvc"></div>
|
29
|
-
<%= link_to "(#{t('spree.what_is_this')})", spree.cvv_path, target: '_blank', "data-hook" => "cvv_link", id: "cvv_link" %>
|
30
|
-
</div>
|
31
|
-
|
32
|
-
<div id="card-errors" class='errorExplanation' role="alert" style="display: none"></div>
|
33
|
-
|
34
|
-
<% if @order.bill_address %>
|
35
|
-
<%= fields_for "#{param_prefix}[address_attributes]", @order.bill_address do |f| %>
|
36
|
-
<%= render partial: 'spree/address/form_hidden', locals: { form: f } %>
|
37
|
-
<% end %>
|
38
|
-
<% end %>
|
39
|
-
|
40
|
-
<%= hidden_field_tag "#{param_prefix}[cc_type]", '', id: "cc_type", class: 'ccType' %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= render 'spree/checkout/payment/v3/form_elements', payment_method: payment_method, stripe_v3_api: 'payment-intents' %>
|
@@ -1,2 +0,0 @@
|
|
1
|
-
<% ActiveSupport::Deprecation.warn 'Partial `spree/checkout/payment/v3/_stripe.html.erb` is deprecated and will be removed soon. Please use partial `spree/checkout/payment/v3/elements`', caller(1) %>
|
2
|
-
<%= render 'spree/checkout/payment/v3/elements', payment_method: payment_method, stripe_v3_api: 'elements' %>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<% if current_order.present? && cart_checkout_payment_method.present? %>
|
2
|
-
<div id="stripe-payment-request" class="stripe-payment-request" data-v3-api="payment-request-button" style="display:none">
|
3
|
-
<div id="payment-request-button"
|
4
|
-
data-stripe-config="<%= cart_checkout_payment_method.stripe_config(current_order).to_json %>"
|
5
|
-
data-order-token="<%= current_order.guest_token %>"
|
6
|
-
data-submit-url="<%= api_checkout_path(current_order.number) %>"
|
7
|
-
data-complete-url="<%= checkout_path %>"
|
8
|
-
class="payment-request-button">
|
9
|
-
</div>
|
10
|
-
|
11
|
-
<div id="card-errors" class='errorExplanation' role="alert" style="display: none">
|
12
|
-
</div>
|
13
|
-
</div>
|
14
|
-
<% end %>
|