solidus_paypal_braintree 0.4.0 → 1.0.0
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 +40 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +68 -0
- data/CHANGELOG.md +258 -0
- data/Gemfile +43 -0
- data/LICENSE +2 -2
- data/README.md +77 -23
- data/Rakefile +4 -25
- data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
- data/app/assets/javascripts/solidus_paypal_braintree/client.js +23 -4
- data/app/assets/javascripts/solidus_paypal_braintree/constants.js +19 -0
- data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +1 -0
- data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +47 -20
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
- data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
- data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
- data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
- data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +46 -0
- data/app/models/application_record.rb +2 -0
- data/app/models/solidus_paypal_braintree/address.rb +30 -0
- data/app/models/solidus_paypal_braintree/configuration.rb +26 -3
- data/app/models/solidus_paypal_braintree/customer.rb +7 -3
- data/app/models/solidus_paypal_braintree/gateway.rb +52 -20
- data/app/models/solidus_paypal_braintree/response.rb +3 -2
- data/app/models/solidus_paypal_braintree/source.rb +21 -7
- data/app/models/solidus_paypal_braintree/transaction.rb +2 -0
- data/app/models/solidus_paypal_braintree/transaction_address.rb +30 -12
- data/app/models/solidus_paypal_braintree/transaction_import.rb +13 -9
- data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
- data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
- data/app/views/spree/shared/_apple_pay_button.html.erb +2 -2
- data/app/views/spree/shared/_braintree_errors.html.erb +11 -17
- data/app/views/spree/shared/_braintree_hosted_fields.html.erb +24 -9
- data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +9 -6
- data/app/views/spree/shared/_paypal_cart_button.html.erb +16 -2
- data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
- data/bin/console +17 -0
- data/bin/rails +15 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +10 -0
- data/config/locales/it.yml +51 -8
- data/config/routes.rb +2 -0
- data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
- data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
- data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
- data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
- data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
- data/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +20 -5
- data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
- data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +55 -51
- data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -5
- data/lib/solidus_paypal_braintree.rb +4 -0
- data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
- data/lib/solidus_paypal_braintree/engine.rb +11 -11
- data/lib/solidus_paypal_braintree/factories.rb +8 -4
- data/lib/solidus_paypal_braintree/request_protection.rb +3 -0
- data/lib/solidus_paypal_braintree/version.rb +3 -1
- data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +30 -5
- data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
- data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +4 -2
- data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +30 -0
- data/solidus_paypal_braintree.gemspec +42 -0
- data/spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb +99 -0
- data/spec/controllers/solidus_paypal_braintree/client_tokens_controller_spec.rb +55 -0
- data/spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb +73 -0
- data/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +183 -0
- data/spec/features/backend/configuration_spec.rb +23 -0
- data/spec/features/backend/new_payment_spec.rb +137 -0
- data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +187 -0
- data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
- data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
- data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
- data/spec/fixtures/cassettes/braintree/token.yml +63 -0
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
- data/spec/fixtures/cassettes/checkout/update.yml +71 -0
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +156 -0
- data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
- data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
- data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
- data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
- data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
- data/spec/fixtures/cassettes/gateway/void.yml +137 -0
- data/spec/fixtures/cassettes/source/card_type.yml +267 -0
- data/spec/fixtures/cassettes/source/last4.yml +267 -0
- data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
- data/spec/fixtures/views/spree/orders/edit.html.erb +50 -0
- data/spec/helpers/solidus_paypal_braintree/braintree_admin_helper_spec.rb +17 -0
- data/spec/models/solidus_paypal_braintree/address_spec.rb +51 -0
- data/spec/models/solidus_paypal_braintree/avs_result_spec.rb +317 -0
- data/spec/models/solidus_paypal_braintree/gateway_spec.rb +692 -0
- data/spec/models/solidus_paypal_braintree/response_spec.rb +280 -0
- data/spec/models/solidus_paypal_braintree/source_spec.rb +360 -0
- data/spec/models/solidus_paypal_braintree/transaction_address_spec.rb +253 -0
- data/spec/models/solidus_paypal_braintree/transaction_import_spec.rb +283 -0
- data/spec/models/solidus_paypal_braintree/transaction_spec.rb +85 -0
- data/spec/models/spree/store_spec.rb +14 -0
- data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/capybara.rb +7 -0
- data/spec/support/factories.rb +2 -0
- data/spec/support/gateway_helpers.rb +29 -0
- data/spec/support/order_ready_for_payment.rb +37 -0
- data/spec/support/vcr.rb +42 -0
- data/spec/support/views.rb +1 -0
- metadata +182 -194
- data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -22
- data/app/helpers/braintree_admin_helper.rb +0 -18
- data/app/models/spree/store_decorator.rb +0 -11
- data/app/views/spree/shared/_paypal_checkout_button.html.erb +0 -27
- data/config/initializers/braintree.rb +0 -1
data/bin/setup
ADDED
data/config/locales/en.yml
CHANGED
@@ -2,6 +2,12 @@ en:
|
|
2
2
|
activerecord:
|
3
3
|
models:
|
4
4
|
solidus_paypal_braintree/gateway: Braintree
|
5
|
+
attributes:
|
6
|
+
solidus_paypal_braintree/configuration:
|
7
|
+
paypal: PayPal
|
8
|
+
apple_pay: Apple Pay
|
9
|
+
credit_card: Credit Card
|
10
|
+
three_d_secure: 3D Secure
|
5
11
|
spree:
|
6
12
|
admin:
|
7
13
|
tab:
|
@@ -14,12 +20,14 @@ en:
|
|
14
20
|
private_key: Private key
|
15
21
|
public_key: Public key
|
16
22
|
token_generation_enabled: Token generation enabled?
|
23
|
+
paypal_flow: PayPal flow
|
17
24
|
solidus_paypal_braintree:
|
18
25
|
braintree: Braintree
|
19
26
|
nonce: Nonce
|
20
27
|
token: Token
|
21
28
|
errors:
|
22
29
|
default_error: "Something bad happened!"
|
30
|
+
paypal_popup_closed: "PayPal popup has been closed before payment completion."
|
23
31
|
empty_fields: "All fields are empty! Please fill out the form."
|
24
32
|
invalid_fields: "Some payment input fields are invalid."
|
25
33
|
invalid_card: "Credit card data is incorrect."
|
@@ -27,6 +35,8 @@ en:
|
|
27
35
|
duplicate_iframe: "Duplicate Braintree iframe."
|
28
36
|
fail_on_duplicate: "This payment method already exists in your vault."
|
29
37
|
cvv_verification_failed: "CVV did not pass verification."
|
38
|
+
threeds:
|
39
|
+
authentication_failed: "3D Secure authentication failed. Please try again using a different payment method."
|
30
40
|
payment_type:
|
31
41
|
label: Payment Type
|
32
42
|
apple_pay_card: Apple Pay
|
data/config/locales/it.yml
CHANGED
@@ -1,11 +1,54 @@
|
|
1
1
|
it:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
solidus_paypal_braintree/gateway: Braintree
|
5
|
+
spree:
|
6
|
+
admin:
|
7
|
+
tab:
|
8
|
+
braintree: Braintree
|
9
|
+
client_sdk_enabled: Client SDK abilitato?
|
10
|
+
environment: Environment
|
11
|
+
merchant_currency_map: Associazioni tra merchant Braintree e valute
|
12
|
+
merchant_id: Merchant ID
|
13
|
+
paypal_payee_email_map: Associazioni tra email beneficiari PayPal e valute
|
14
|
+
private_key: Private key
|
15
|
+
public_key: Public key
|
16
|
+
token_generation_enabled: Generazione dei Token abilitata?
|
17
|
+
paypal_flow: Flusso PayPal
|
2
18
|
solidus_paypal_braintree:
|
19
|
+
braintree: Braintree
|
20
|
+
nonce: Nonce
|
21
|
+
token: Token
|
3
22
|
errors:
|
4
|
-
default_error:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
23
|
+
default_error: Qualcosa è andato storto!
|
24
|
+
paypal_popup_closed: La finestra di PayPal è stata chiusa prima di completare il pagamento.
|
25
|
+
empty_fields: I campi non possono essere vuoti!
|
26
|
+
invalid_fields: Alcuni campi non sono corretti.
|
27
|
+
invalid_card: I dati della carta di credito non sono corretti.
|
28
|
+
network_error: Si è verificato un errore di rete.
|
29
|
+
duplicate_iframe: Ci sono due iframe di Braintree.
|
30
|
+
fail_on_duplicate: Questo metodo di pagamento esiste già.
|
31
|
+
cvv_verification_failed: Il codice CVV non è corretto.
|
32
|
+
payment_type:
|
33
|
+
label: Metodo di Pagamento
|
34
|
+
apple_pay_card: Apple Pay
|
35
|
+
credit_card: Carta di credito
|
36
|
+
pay_pal_account: PayPal
|
37
|
+
configurations:
|
38
|
+
title: Configurazioni di Braintree
|
39
|
+
tab: Braintree
|
40
|
+
update_success: Configurazioni di Braintree aggiornate con successo.
|
41
|
+
update_error: Si è verificato un errore durante l'aggiornamento delle configurazioni di Braintree.
|
42
|
+
gateway_rejection_reasons:
|
43
|
+
avs: Controllo AVS fallito.
|
44
|
+
avs_and_cvv: Controlli AVS e CVV falliti.
|
45
|
+
cvv: Controllo CVV fallito.
|
46
|
+
duplicate: Transazione duplicata.
|
47
|
+
fraud: La carta di credito è stata rifiutata a seguito di un potenziale uso fraudolento.
|
48
|
+
three_d_secure: Controllo '3D Secure' fallito.
|
49
|
+
transaction_statuses:
|
50
|
+
authorization_expired: L'autorizzazione di pagamento è scaduta.
|
51
|
+
failed: Si è verificato un errore durante l'invio della transazione al sistema di pagamento.
|
52
|
+
gateway_rejected: Il gateway di pagamento ha rifiutato questa transazione.
|
53
|
+
processor_declined: Il sistema di pagamento ha rifiutato questa transazione.
|
54
|
+
settlement_declined: Il saldo di questa transazione è stato rifiutato dal sistema di pagamento.
|
data/config/routes.rb
CHANGED
@@ -3,9 +3,11 @@ class CreateSolidusPaypalBraintreeCustomers < SolidusSupport::Migration[4.2]
|
|
3
3
|
create_table :solidus_paypal_braintree_customers do |t|
|
4
4
|
t.references :user
|
5
5
|
t.string :braintree_customer_id
|
6
|
+
|
7
|
+
t.timestamps
|
6
8
|
end
|
7
9
|
|
8
10
|
add_index :solidus_paypal_braintree_customers, :user_id, unique: true, name: "index_braintree_customers_on_user_id"
|
9
|
-
add_index :solidus_paypal_braintree_customers, :braintree_customer_id, unique: true, name: "index_braintree_customers_on_braintree_customer_id"
|
11
|
+
add_index :solidus_paypal_braintree_customers, :braintree_customer_id, unique: true, name: "index_braintree_customers_on_braintree_customer_id" # rubocop:disable Layout/LineLength
|
10
12
|
end
|
11
13
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
class AddBraintreeConfigurationToStores < SolidusSupport::Migration[4.2]
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
SolidusPaypalBraintree::Configuration.joins(:store).destroy_all
|
8
|
-
end
|
2
|
+
# The content of this migration has been removed because store's Braintree
|
3
|
+
# configuration doesn't already have paypal_button_preferences fields, so
|
4
|
+
# their validations will break this migration.
|
5
|
+
#
|
6
|
+
# Ref here for more info https://github.com/solidusio/solidus_paypal_braintree/pull/249
|
9
7
|
end
|
@@ -15,7 +15,9 @@ class AddNullConstraintToSources < SolidusSupport::Migration[4.2]
|
|
15
15
|
|
16
16
|
Spree::Payment.joins(join_sources).find_each do |payment|
|
17
17
|
Rails.logger.info("Updating source #{payment.source_id} with payment method id #{payment.payment_method_id}")
|
18
|
-
SolidusPaypalBraintree::Source.where(id: payment.source_id).update_all(
|
18
|
+
SolidusPaypalBraintree::Source.where(id: payment.source_id).update_all(
|
19
|
+
payment_method_id: payment.payment_method_id
|
20
|
+
)
|
19
21
|
end
|
20
22
|
|
21
23
|
# We use a foreign key constraint on the model,
|
@@ -1,18 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusPaypalBraintree
|
2
|
-
class ConfigurationsController < Spree::Admin::BaseController
|
3
|
-
helper Spree::Core::Engine.routes.url_helpers
|
4
|
+
class ConfigurationsController < ::Spree::Admin::BaseController
|
5
|
+
helper ::Spree::Core::Engine.routes.url_helpers
|
4
6
|
|
5
7
|
def list
|
6
8
|
authorize! :list, SolidusPaypalBraintree::Configuration
|
7
9
|
|
8
|
-
@configurations = Spree::Store.all.map
|
10
|
+
@configurations = ::Spree::Store.all.map { |s| s.braintree_configuration || s.create_braintree_configuration }
|
9
11
|
end
|
10
12
|
|
11
13
|
def update
|
12
14
|
authorize! :update, SolidusPaypalBraintree::Configuration
|
13
15
|
|
14
16
|
params = configurations_params[:configuration_fields]
|
15
|
-
|
17
|
+
results = SolidusPaypalBraintree::Configuration.update(params.keys, params.values)
|
18
|
+
if results.all?(&:valid?)
|
16
19
|
flash[:success] = t('update_success', scope: 'solidus_paypal_braintree.configurations')
|
17
20
|
else
|
18
21
|
flash[:error] = t('update_error', scope: 'solidus_paypal_braintree.configurations')
|
@@ -24,7 +27,19 @@ module SolidusPaypalBraintree
|
|
24
27
|
|
25
28
|
def configurations_params
|
26
29
|
params.require(:configurations).
|
27
|
-
permit(configuration_fields: [
|
30
|
+
permit(configuration_fields: [
|
31
|
+
:paypal,
|
32
|
+
:apple_pay,
|
33
|
+
:credit_card,
|
34
|
+
:three_d_secure,
|
35
|
+
:preferred_paypal_button_locale,
|
36
|
+
:preferred_paypal_button_color,
|
37
|
+
:preferred_paypal_button_shape,
|
38
|
+
:preferred_paypal_button_label,
|
39
|
+
:preferred_paypal_button_tagline,
|
40
|
+
:preferred_paypal_button_layout,
|
41
|
+
:preferred_paypal_button_messaging
|
42
|
+
])
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
@@ -1,27 +1,31 @@
|
|
1
|
-
|
2
|
-
PERMITTED_PAYMENT_PARAMS = [
|
3
|
-
:payment_method_id,
|
4
|
-
source_attributes: [
|
5
|
-
:nonce,
|
6
|
-
:payment_type
|
7
|
-
]
|
8
|
-
].freeze
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
10
|
-
|
11
|
-
|
3
|
+
module SolidusPaypalBraintree
|
4
|
+
class CheckoutsController < ::Spree::CheckoutController
|
5
|
+
PERMITTED_PAYMENT_PARAMS = [
|
6
|
+
:payment_method_id,
|
7
|
+
{ source_attributes: [
|
8
|
+
:nonce,
|
9
|
+
:payment_type
|
10
|
+
] }
|
11
|
+
].freeze
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def update
|
14
|
+
@payment = ::Spree::PaymentCreate.new(@order, payment_params).build
|
15
|
+
|
16
|
+
if @payment.save
|
17
|
+
render plain: "ok"
|
18
|
+
else
|
19
|
+
render plain: "not-ok"
|
20
|
+
end
|
17
21
|
end
|
18
|
-
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def payment_params
|
24
|
+
params.
|
25
|
+
require(:order).
|
26
|
+
require(:payments_attributes).
|
27
|
+
first.
|
28
|
+
permit(PERMITTED_PAYMENT_PARAMS)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
@@ -1,62 +1,66 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
:
|
11
|
-
:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusPaypalBraintree
|
4
|
+
class TransactionsController < ::Spree::StoreController
|
5
|
+
class InvalidImportError < StandardError; end
|
6
|
+
|
7
|
+
PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
|
8
|
+
:nonce,
|
9
|
+
:payment_type,
|
10
|
+
:phone,
|
11
|
+
:email,
|
12
|
+
{ address_attributes: [
|
13
|
+
:country_code, :country_name, :name, :city, :zip, :state_code,
|
14
|
+
:address_line_1, :address_line_2, :first_name, :last_name
|
15
|
+
] }
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
def create
|
19
|
+
transaction = SolidusPaypalBraintree::Transaction.new transaction_params
|
20
|
+
import = SolidusPaypalBraintree::TransactionImport.new(current_order, transaction)
|
21
|
+
restart_checkout = params[:options] && params[:options][:restart_checkout] == "true"
|
22
|
+
|
23
|
+
respond_to do |format|
|
24
|
+
if import.valid?
|
25
|
+
import.import!(import_state, restart_checkout: restart_checkout)
|
26
|
+
|
27
|
+
format.html { redirect_to redirect_url(import) }
|
28
|
+
format.json { render json: { redirectUrl: redirect_url(import) } }
|
29
|
+
else
|
30
|
+
status = 422
|
31
|
+
format.html { import_error(import) }
|
32
|
+
format.json { render json: { errors: import.errors, status: status }, status: status }
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
|
-
end
|
33
36
|
|
34
|
-
|
37
|
+
private
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
def import_state
|
40
|
+
params[:state] || 'confirm'
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
def import_error(import)
|
44
|
+
raise InvalidImportError,
|
45
|
+
"Import invalid: #{import.errors.full_messages.join(', ')}"
|
46
|
+
end
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def redirect_url(import)
|
49
|
+
if import.order.complete?
|
50
|
+
spree.order_url(import.order)
|
51
|
+
else
|
52
|
+
spree.checkout_state_url(import.order.state)
|
53
|
+
end
|
50
54
|
end
|
51
|
-
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
def transaction_params
|
57
|
+
params.require(:transaction)
|
58
|
+
.permit(PERMITTED_BRAINTREE_TRANSACTION_PARAMS)
|
59
|
+
.merge({ payment_method: payment_method })
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
62
|
+
def payment_method
|
63
|
+
SolidusPaypalBraintree::Gateway.find(params[:payment_method_id])
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusPaypalBraintree
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
@@ -5,12 +7,12 @@ module SolidusPaypalBraintree
|
|
5
7
|
|
6
8
|
def add_javascripts
|
7
9
|
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require solidus_paypal_braintree/frontend\n"
|
8
|
-
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_braintree\n"
|
10
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_braintree\n" # rubocop:disable Layout/LineLength
|
9
11
|
end
|
10
12
|
|
11
13
|
def add_stylesheets
|
12
|
-
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_paypal_braintree\n", before:
|
13
|
-
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_paypal_braintree\n", before:
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_paypal_braintree\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
15
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_paypal_braintree\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
14
16
|
end
|
15
17
|
|
16
18
|
def add_migrations
|
@@ -24,11 +26,11 @@ module SolidusPaypalBraintree
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def run_migrations
|
27
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
29
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
|
28
30
|
if run_migrations
|
29
31
|
run 'bundle exec rake db:migrate'
|
30
32
|
else
|
31
|
-
|
33
|
+
say_status :skipping, 'rake db:migrate, don\'t forget to run it!'
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'solidus_core'
|
4
|
+
require 'solidus_paypal_braintree/version'
|
2
5
|
require 'solidus_paypal_braintree/engine'
|
3
6
|
require 'solidus_paypal_braintree/country_mapper'
|
4
7
|
require 'solidus_paypal_braintree/request_protection'
|
8
|
+
require 'solidus_support'
|
5
9
|
|
6
10
|
module SolidusPaypalBraintree
|
7
11
|
def self.table_name_prefix
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SolidusPaypalBraintree
|
2
4
|
module CountryMapper
|
3
5
|
extend ActiveSupport::Concern
|
@@ -12,12 +14,12 @@ module SolidusPaypalBraintree
|
|
12
14
|
"usa",
|
13
15
|
"u.s.",
|
14
16
|
"us"
|
15
|
-
]
|
17
|
+
].freeze
|
16
18
|
|
17
19
|
CANADA_VARIANTS = [
|
18
20
|
"canada",
|
19
21
|
"ca"
|
20
|
-
]
|
22
|
+
].freeze
|
21
23
|
|
22
24
|
# Generates a hash mapping each variant of the country name to the same ISO
|
23
25
|
# ie: { "usa" => "US", "united states" => "US", "canada" => "CA", ... }
|