spree_braintree_vzero 3.5.1 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.travis.yml +39 -46
  4. data/Appraisals +19 -28
  5. data/README.md +6 -4
  6. data/app/assets/images/backend-settle.svg +3 -0
  7. data/app/assets/javascripts/spree/frontend/spree_braintree_vzero.js +3 -1
  8. data/app/controllers/spree/admin/payments_controller_decorator.rb +9 -4
  9. data/app/controllers/spree/orders_controller_decorator.rb +2 -0
  10. data/app/helpers/spree/admin/payment_methods_helper.rb +11 -5
  11. data/app/helpers/spree/braintree_helper.rb +2 -2
  12. data/app/models/concerns/spree/gateway/braintree_vzero/legacy_rails_patch.rb +20 -0
  13. data/app/models/spree/address_decorator.rb +2 -2
  14. data/app/models/spree/braintree_vzero/order_decorator.rb +155 -0
  15. data/app/models/spree/gateway/braintree_vzero_base/utils.rb +50 -3
  16. data/app/models/spree/gateway/braintree_vzero_base.rb +4 -0
  17. data/app/models/spree/gateway/braintree_vzero_drop_in_ui.rb +3 -1
  18. data/app/models/spree/gateway/braintree_vzero_hosted_fields.rb +3 -1
  19. data/app/models/spree/log_entry_decorator.rb +52 -0
  20. data/app/models/spree/payment_processing_decorator.rb +12 -0
  21. data/app/models/spree/preferences/preferable_decorator.rb +1 -1
  22. data/app/overrides/spree/orders/edit.rb +1 -1
  23. data/app/views/spree/braintree_vzero/_paypal_checkout.html.erb +77 -59
  24. data/app/views/spree/checkout/payment/braintree_vzero/_non_three_d_secure.html.erb +178 -0
  25. data/app/views/spree/checkout/payment/braintree_vzero/_payment.html.erb +32 -13
  26. data/app/views/spree/checkout/payment/braintree_vzero/_three_d_secure.html.erb +54 -14
  27. data/config/initializers/prepend_helpers.rb +3 -1
  28. data/db/migrate/20160112153422_add_admin_payment_to_spree_braintree_checkout.rb +1 -1
  29. data/gemfiles/spree_3_7.gemfile +2 -0
  30. data/gemfiles/spree_4_0.gemfile +1 -0
  31. data/gemfiles/{spree_3_5.gemfile → spree_4_1.gemfile} +2 -5
  32. data/gemfiles/{spree_4_0_spree_auth_devise.gemfile → spree_4_2.gemfile} +2 -2
  33. data/gemfiles/spree_master.gemfile +1 -3
  34. data/lib/spree_braintree_vzero/engine.rb +3 -1
  35. data/lib/spree_braintree_vzero/version.rb +2 -2
  36. data/spec/controllers/spree/checkout_controller_spec.rb +1 -1
  37. data/spec/features/spree/admin/log_entries_spec.rb +18 -3
  38. data/spec/models/gateway/braintree_vzero_base_spec.rb +8 -5
  39. data/spec/models/spree/address_spec.rb +18 -0
  40. data/spec/support/vcr.rb +1 -1
  41. data/spec/vcr/Spree_Gateway_BraintreeVzeroBase/valid_credentials/_purchase/using_Vault/sends_address_data_when_address_is_new.yml +72 -0
  42. data/spree_braintree_vzero.gemspec +4 -5
  43. metadata +22 -49
  44. data/app/controllers/spree/user_sessions_controller_decorator.rb +0 -15
  45. data/app/models/spree/order_decorator.rb +0 -153
  46. data/gemfiles/spree_3_5_spree_auth_devise.gemfile +0 -13
  47. data/gemfiles/spree_3_7_spree_auth_devise.gemfile +0 -13
  48. data/gemfiles/spree_master_spree_auth_devise.gemfile +0 -12
@@ -1,153 +0,0 @@
1
- module Spree
2
- module OrderDecorator
3
- def self.prepended(base)
4
- base.state_machine.before_transition to: :complete, do: :process_paypal_express_payments
5
- end
6
-
7
- def save_paypal_address(type, address_hash)
8
- return if address_hash.blank?
9
- address = Spree::Address.new(prepare_address_hash(address_hash))
10
- return unless address.save
11
-
12
- update_column("#{type}_id", address.id)
13
- end
14
-
15
- def save_paypal_payment(options)
16
- options[:source] = Spree::BraintreeCheckout.create!(options.slice(:paypal_email, :advanced_fraud_data))
17
- payments.create(options.slice(:braintree_nonce, :payment_method_id, :source))
18
- end
19
-
20
- def set_billing_address
21
- return if bill_address_id
22
- return unless ship_address_id
23
-
24
- address = Spree::Address.create(shipping_address.attributes.except('id', 'updated_at', 'created_at', 'braintree_id'))
25
- update_column(:bill_address_id, address.try(:id))
26
- end
27
-
28
- # override needed to add braintree source attribute
29
- def update_from_params(params, permitted_params, request_env = {})
30
- success = false
31
- @updating_params = params
32
- run_callbacks :updating_from_params do
33
- # Set existing card after setting permitted parameters because
34
- # rails would slice parameters containg ruby objects, apparently
35
- existing_card_id = @updating_params[:order] ? @updating_params[:order].delete(:existing_card) : nil
36
-
37
- attributes = @updating_params[:order] ? @updating_params[:order].permit(permitted_params).delete_if { |_k, v| v.nil? } : {}
38
- payment_attributes = attributes[:payments_attributes].first if attributes[:payments_attributes].present?
39
-
40
- if existing_card_id.present?
41
- credit_card = Spree::CreditCard.find existing_card_id
42
- if credit_card.user_id != user_id || credit_card.user_id.blank?
43
- raise Spree::Core::GatewayError, Spree.t(:invalid_credit_card)
44
- end
45
-
46
- credit_card.verification_value = params[:cvc_confirm] if params[:cvc_confirm].present?
47
-
48
- attributes[:payments_attributes].first[:source] = credit_card
49
- attributes[:payments_attributes].first[:payment_method_id] = credit_card.payment_method_id
50
- attributes[:payments_attributes].first.delete :source_attributes
51
- end
52
-
53
- if payment_attributes.present?
54
- payment_attributes[:request_env] = request_env
55
-
56
- if (token = payment_attributes[:braintree_token]).present?
57
- payment_attributes[:source] = Spree::BraintreeCheckout.create_from_token(token, payment_attributes[:payment_method_id])
58
- elsif payment_attributes[:braintree_nonce].present?
59
- payment_attributes[:source] = Spree::BraintreeCheckout.create_from_params(params)
60
- end
61
- end
62
-
63
- success = update(attributes)
64
- set_shipments_cost if shipments.any?
65
- end
66
-
67
- @updating_params = nil
68
- success
69
- end
70
-
71
- def payment_required?
72
- # default payment processing requires order to have state == payment
73
- # so there is no need to divide this method for checkout steps and actual payment processing
74
- return false if paid_with_paypal_express?
75
- total.to_f > 0.0
76
- end
77
-
78
- def confirmation_required?
79
- Spree::Config[:always_include_confirm_step] ||
80
- payments.valid.map(&:payment_method).compact.any?(&:payment_profiles_supported?) ||
81
- # setting payment_profiles_supported? for braintree gateways would require few additional changes in payments profiles system
82
- braintree_confirmation_required? || state == 'confirm'
83
- end
84
-
85
- def paid_with_braintree?
86
- payments.valid.map(&:payment_method).compact.any? { |p| p.is_a?(Spree::Gateway::BraintreeVzeroBase) }
87
- end
88
-
89
- def paid_with_paypal_express?
90
- payments.valid.map(&:payment_method).compact.any? { |p| p.is_a?(Spree::Gateway::BraintreeVzeroPaypalExpress) }
91
- end
92
-
93
- def invalidate_paypal_express_payments
94
- return unless paid_with_paypal_express?
95
-
96
- payments.valid.each do |payment|
97
- payment.invalidate! if payment.payment_method.is_a?(Spree::Gateway::BraintreeVzeroPaypalExpress)
98
- end
99
- end
100
-
101
- def no_phone_number?
102
- [ship_address, bill_address].each do |address|
103
- return true if address.try(:phone).eql?(I18n.t('braintree.phone_number_placeholder'))
104
- end
105
- false
106
- end
107
-
108
- def remove_phone_number_placeholder
109
- [ship_address, bill_address].each do |address|
110
- address.update_column(:phone, nil) if address.try(:phone).eql?(I18n.t('braintree.phone_number_placeholder'))
111
- end
112
- end
113
-
114
- private
115
-
116
- def braintree_confirmation_required?
117
- paid_with_braintree? && state.eql?('payment')
118
- end
119
-
120
- def prepare_address_hash(hash)
121
- hash.delete_if { |e| hash[e].eql?('undefined') }
122
- country_id = Spree::Country.find_by(iso: hash.delete(:country)).try(:id)
123
-
124
- hash[:country_id] = country_id
125
- state_param = hash.delete(:state)
126
- state = Spree::State.where('spree_states.abbr = :abbr OR upper(spree_states.name) = :name',
127
- abbr: state_param, name: state_param.upcase).find_by(country_id: country_id)
128
- hash[:state_id] = state.try(:id)
129
- hash[:phone] ||= I18n.t('braintree.phone_number_placeholder')
130
-
131
- return hash if hash[:full_name].blank?
132
-
133
- full_name = hash.delete(:full_name).split(' ')
134
- hash[:lastname] = full_name.slice!(-1)
135
- hash[:firstname] = full_name.join(' ')
136
- hash
137
- end
138
-
139
- def process_paypal_express_payments
140
- return unless paid_with_paypal_express?
141
-
142
- if payments.valid.empty?
143
- order.errors.add(:base, Spree.t(:no_payment_found))
144
- false
145
- else
146
- payments.valid.last.update(amount: order_total_after_store_credit)
147
- process_payments!
148
- end
149
- end
150
- end
151
- end
152
-
153
- ::Spree::Order.prepend(Spree::OrderDecorator)
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "spree", "~> 3.5.0"
6
- gem "pg"
7
- gem "mysql2"
8
- gem "webmock", ">= 2.3.1"
9
- gem "rails-controller-testing"
10
- gem "spree_auth_devise", "~> 3.3.0"
11
- gem 'sprockets', '~> 3.7'
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem 'sassc-rails'
6
- gem "spree", "~> 3.7.1"
7
- gem "pg"
8
- gem "mysql2"
9
- gem "webmock", ">= 2.3.1"
10
- gem "rails-controller-testing"
11
- gem "spree_auth_devise", "~> 3.5.2"
12
-
13
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "spree", github: "spree/spree", branch: "master"
6
- gem "pg"
7
- gem "mysql2"
8
- gem "webmock", ">= 2.3.1"
9
- gem "rails-controller-testing"
10
- gem "spree_auth_devise", github: "spree/spree_auth_devise", branch: "master"
11
-
12
- gemspec path: "../"