spree_gateway 3.9.4 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a29093f977d40e708b032c608a9e25f1949352bee57b9321fa36488000d7711f
4
- data.tar.gz: 5f5d7ff9014be360d444df942dc24d1313ef0881e786ac37a49f4fe884b5d0fe
3
+ metadata.gz: 056db537dbbb9403df9df6e2822fa462b9c0b2eac0f880548d7ad9deb93e91c5
4
+ data.tar.gz: aeb658e8f6abfe36b8b84d45bb819a2cc02510f27010cf6ef059c3ae7fc78e30
5
5
  SHA512:
6
- metadata.gz: 807b40308555c5149f146fa3fc38c52f10c47ec765a1988f0562adcc296115d43670f09052a80a2493edd166d6d195092e7861ae07457c8c47eedb0cca90559b
7
- data.tar.gz: 0ce03934963ea212e16aed6148eff226362d90544789ec1fa283c69dbff81c1d2834c91bce4aab81794935c5d3e825ffb89f07b95d66d1d9994128b11f8e31de
6
+ metadata.gz: 9896b8790e3ad9bfd23cd5387fe8718d0e1dcb52edd4dcfce1026fdbe875192bd1287b45613be7a1ec395eeb8279e06817f92d9f45a7ab510dd37b910f27394a
7
+ data.tar.gz: 3659666f037e516a8ac535d11e5f95d4dcb64f7794e110ddb51b2a8087f699948c0e37c12c0d91bd48ca38633f1ced10dfb31528bbf873bfc09606f4fc994593
data/Gemfile CHANGED
@@ -2,7 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails-controller-testing'
4
4
  gem 'spree', github: 'spree/spree', branch: 'main'
5
- gem 'spree_backend', github: 'spree/spree', branch: 'main'
6
- gem 'spree_frontend', github: 'spree/spree', branch: 'main'
5
+ gem 'spree_backend', github: 'spree/spree_backend', branch: 'main'
6
+ gem 'spree_frontend', github: 'spree/spree_legacy_frontend', branch: 'main'
7
+
8
+ if ENV['DB'] == 'mysql'
9
+ gem 'mysql2'
10
+ else
11
+ gem 'pg', '~> 1.1'
12
+ end
7
13
 
8
14
  gemspec
@@ -12,6 +12,7 @@ en:
12
12
  payment_has_been_cancelled: The payment has been cancelled.
13
13
  please_wait_for_confirmation_popup: Please wait for payment confirmation popup to appear.
14
14
  payment_successfully_authorized: The payment was successfully authorized.
15
+ no_payment_authorization_needed: Payment autorization not needed.
15
16
  order_state:
16
17
  payment_confirm: Verify payment
17
18
  log_entry:
data/config/routes.rb CHANGED
@@ -10,6 +10,7 @@ Spree::Core::Engine.add_routes do
10
10
  namespace :v2 do
11
11
  namespace :storefront do
12
12
  namespace :intents do
13
+ post :payment_confirmation_data
13
14
  post :handle_response
14
15
  end
15
16
  end
@@ -3,19 +3,19 @@ class AddSpreeCheckPaymentSource < ActiveRecord::Migration[5.1]
3
3
  create_table :spree_checks do |t|
4
4
  t.references :payment_method
5
5
  t.references :user
6
- t.string "account_holder_name"
7
- t.string "account_holder_type"
8
- t.string "routing_number"
9
- t.string "account_number"
10
- t.string "account_type", default: 'checking'
11
- t.string "status"
12
- t.string "last_digits"
13
- t.string "gateway_customer_profile_id"
14
- t.string "gateway_payment_profile_id"
6
+ t.string 'account_holder_name'
7
+ t.string 'account_holder_type'
8
+ t.string 'routing_number'
9
+ t.string 'account_number'
10
+ t.string 'account_type', default: 'checking'
11
+ t.string 'status'
12
+ t.string 'last_digits'
13
+ t.string 'gateway_customer_profile_id'
14
+ t.string 'gateway_payment_profile_id'
15
15
 
16
- t.datetime "created_at", null: false
17
- t.datetime "updated_at", null: false
18
- t.datetime "deleted_at"
16
+ t.datetime 'created_at', null: false
17
+ t.datetime 'updated_at', null: false
18
+ t.datetime 'deleted_at'
19
19
  end
20
20
  add_index :spree_payment_methods, :id
21
21
  end
@@ -1,4 +1,4 @@
1
- class AddIntentKeyToPayment < ActiveRecord::Migration[4.2]
1
+ class AddIntentKeyToPayment < ActiveRecord::Migration[5.2]
2
2
  def change
3
3
  add_column :spree_payments, :intent_client_key, :string
4
4
  end
@@ -5,6 +5,24 @@ module Spree
5
5
  class IntentsController < ::Spree::Api::V2::BaseController
6
6
  include Spree::Api::V2::Storefront::OrderConcern
7
7
 
8
+ def payment_confirmation_data
9
+ spree_authorize! :update, spree_current_order, order_token
10
+
11
+ if spree_current_order.intents?
12
+ spree_current_order.process_payments!
13
+ spree_current_order.reload
14
+ last_valid_payment = spree_current_order.payments.valid.where.not(intent_client_key: nil).last
15
+
16
+ if last_valid_payment.present?
17
+ client_secret = last_valid_payment.intent_client_key
18
+ publishable_key = last_valid_payment.payment_method&.preferred_publishable_key
19
+ return render json: { client_secret: client_secret, pk_key: publishable_key }, status: :ok
20
+ end
21
+ end
22
+
23
+ render_error_payload(I18n.t('spree.no_payment_authorization_needed'))
24
+ end
25
+
8
26
  def handle_response
9
27
  if params['response']['error']
10
28
  invalidate_payment
@@ -4,7 +4,7 @@ module SpreeGateway
4
4
 
5
5
  config.autoload_paths += %W(#{config.root}/lib)
6
6
 
7
- initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app|
7
+ config.after_initialize do |app|
8
8
  app.config.spree.payment_methods << Spree::Gateway::AuthorizeNet
9
9
  app.config.spree.payment_methods << Spree::Gateway::AuthorizeNetCim
10
10
  app.config.spree.payment_methods << Spree::Gateway::BalancedGateway
@@ -1,5 +1,5 @@
1
1
  module SpreeGateway
2
2
  def self.version
3
- '3.9.4'
3
+ '3.10.0'
4
4
  end
5
5
  end
@@ -0,0 +1,198 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Api V2 Storefront Intents Spec', type: :request do
4
+ let!(:store) { Spree::Store.default }
5
+ let(:currency) { store.default_currency }
6
+ let(:user) { create(:user) }
7
+ let(:order) { create(:order, user: user, store: store, currency: currency) }
8
+
9
+ include_context 'API v2 tokens'
10
+
11
+ describe '#payment_confirmation_data' do
12
+ subject :post_payment_confirmation_data do
13
+ post '/api/v2/storefront/intents/payment_confirmation_data', headers: headers, params: params
14
+ end
15
+
16
+ include_context 'API v2 tokens'
17
+
18
+ context 'when user is authorized' do
19
+ let(:params) { {} }
20
+ let(:headers) { headers_bearer.merge(headers_order_token) }
21
+
22
+ context 'when current order has payment intent' do
23
+ let(:provider) do
24
+ double('provider').tap do |p|
25
+ p.stub(:purchase)
26
+ p.stub(:authorize)
27
+ p.stub(:capture)
28
+ end
29
+ end
30
+ let(:gateway) do
31
+ gateway = Spree::Gateway::StripeElementsGateway.new(active: true)
32
+ gateway.set_preference :secret_key, 'secret_key'
33
+ gateway.set_preference :intents, 'true'
34
+ gateway.name = 'Stripe Elements'
35
+ gateway.stores << order.store
36
+ allow(gateway).to receive(:options_for_purchase_or_auth).and_return ['money','cc','opts']
37
+ allow(gateway).to receive_messages provider: provider
38
+ allow(gateway).to receive_messages source_required: true
39
+ allow(gateway).to receive_messages create_profile: true
40
+ gateway
41
+ end
42
+ let!(:payment) do
43
+ create(:payment,
44
+ source: create(:credit_card),
45
+ order: order,
46
+ payment_method: gateway,
47
+ state: 'pending',
48
+ intent_client_key: intent_client_key)
49
+ end
50
+
51
+ before { post_payment_confirmation_data }
52
+
53
+ context 'when last valid payment has intent client key' do
54
+ let(:intent_client_key) { 'intent_client_key' }
55
+
56
+ it_behaves_like 'returns 200 HTTP status'
57
+ end
58
+
59
+ context 'when last valid payment does not have intent client key' do
60
+ let(:intent_client_key) { nil }
61
+
62
+ it_behaves_like 'returns 422 HTTP status'
63
+
64
+ it 'includes valid response message' do
65
+ expect(response.body).to include I18n.t('spree.no_payment_authorization_needed')
66
+ end
67
+ end
68
+
69
+ context 'when current order has completed payments' do
70
+ let(:order) { create(:order_ready_to_ship, user: user, store: store, currency: currency) }
71
+ let(:intent_client_key) { 'intent_client_key' }
72
+
73
+ it_behaves_like 'returns 403 HTTP status'
74
+ end
75
+ end
76
+
77
+ context 'when current order does not have payment intent' do
78
+ before { post_payment_confirmation_data }
79
+
80
+ it_behaves_like 'returns 422 HTTP status'
81
+
82
+ it 'includes valid response message' do
83
+ expect(response.body).to include I18n.t('spree.no_payment_authorization_needed')
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'when some authorization data is missing' do
89
+ let(:params) { {} }
90
+ let(:headers) { {} }
91
+
92
+ before { post_payment_confirmation_data }
93
+
94
+ it_behaves_like 'returns 403 HTTP status'
95
+ end
96
+ end
97
+
98
+ describe '#handle_response' do
99
+ subject :post_handle_response do
100
+ post '/api/v2/storefront/intents/handle_response', headers: headers, params: params
101
+ end
102
+
103
+ let(:headers) { headers_bearer.merge(headers_order_token) }
104
+ let(:provider) do
105
+ double('provider').tap do |p|
106
+ p.stub(:purchase)
107
+ p.stub(:authorize)
108
+ p.stub(:capture)
109
+ end
110
+ end
111
+ let(:gateway) do
112
+ gateway = Spree::Gateway::StripeElementsGateway.new(active: true)
113
+ gateway.set_preference :secret_key, 'secret_key'
114
+ gateway.set_preference :intents, 'true'
115
+ gateway.name = 'Stripe Elements'
116
+ gateway.stores << order.store
117
+ allow(gateway).to receive(:options_for_purchase_or_auth).and_return ['money','cc','opts']
118
+ allow(gateway).to receive_messages provider: provider
119
+ allow(gateway).to receive_messages source_required: true
120
+ allow(gateway).to receive_messages create_profile: true
121
+ gateway
122
+ end
123
+ let!(:payment) do
124
+ create(:payment,
125
+ source: create(:credit_card),
126
+ order: order,
127
+ payment_method: gateway,
128
+ state: 'pending',
129
+ intent_client_key: 'intent_client_key')
130
+ end
131
+
132
+ include_context 'API v2 tokens'
133
+
134
+ context 'when response param does not include errors' do
135
+ let(:params) do
136
+ {
137
+ response: {
138
+ message: 'everything is ok'
139
+ }
140
+ }
141
+ end
142
+
143
+ before { post_handle_response }
144
+
145
+ it_behaves_like 'returns 200 HTTP status'
146
+
147
+ it 'includes valid response message' do
148
+ expect(response.body).to include I18n.t('spree.payment_successfully_authorized')
149
+ end
150
+
151
+ it 'does not update payment' do
152
+ expect { post_handle_response }.not_to change { payment }
153
+ end
154
+ end
155
+
156
+ context 'when response param includes errors' do
157
+ let(:payment_response_code) { payment.response_code }
158
+ let(:params) do
159
+ {
160
+ response: {
161
+ error: {
162
+ payment_intent: {
163
+ id: payment_response_code
164
+ },
165
+ message: 'something went wrong'
166
+ }
167
+ }
168
+ }
169
+ end
170
+
171
+ before { post_handle_response }
172
+
173
+ it_behaves_like 'returns 422 HTTP status'
174
+
175
+ context 'when payment to invalidate is found' do
176
+ it 'changes payment state to failed' do
177
+ expect(payment.state).not_to eq 'failed'
178
+ expect(payment.reload.state).to eq 'failed'
179
+ end
180
+
181
+ it 'clears payment intent_client_key' do
182
+ expect(payment.intent_client_key).not_to be nil
183
+ expect(payment.reload.intent_client_key).to be nil
184
+ end
185
+
186
+ it 'includes valid response message' do
187
+ expect(response.body).to include params[:response][:error][:message]
188
+ end
189
+ end
190
+
191
+ context 'when payment to invalidate is not found' do
192
+ let(:payment_response_code) { 'unexisting response code' }
193
+
194
+ it_behaves_like 'returns 404 HTTP status'
195
+ end
196
+ end
197
+ end
198
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.4
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spree Commerce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -139,11 +139,6 @@ files:
139
139
  - config/locales/en.yml
140
140
  - config/locales/sv.yml
141
141
  - config/routes.rb
142
- - db/migrate/20121017004102_update_braintree_payment_method_type.rb
143
- - db/migrate/20130213222555_update_stripe_payment_method_type.rb
144
- - db/migrate/20130415222802_update_balanced_payment_method_type.rb
145
- - db/migrate/20131008221012_update_paypal_payment_method_type.rb
146
- - db/migrate/20131112133401_migrate_stripe_preferences.rb
147
142
  - db/migrate/20200317135551_add_spree_check_payment_source.rb
148
143
  - db/migrate/20200422114908_add_intent_key_to_payment.rb
149
144
  - lib/active_merchant/billing/stripe_gateway_decorator.rb
@@ -204,6 +199,7 @@ files:
204
199
  - spec/models/gateway/worldpay_spec.rb
205
200
  - spec/models/spree/order_spec.rb
206
201
  - spec/requests/apple_pay_domain_verification.rb
202
+ - spec/requests/spree/api/v2/storefront/intents_controller_spec.rb
207
203
  - spec/spec_helper.rb
208
204
  - spec/support/order_walktrough.rb
209
205
  - spec/support/wait_for_stripe.rb
@@ -214,9 +210,9 @@ licenses:
214
210
  - BSD-3-Clause
215
211
  metadata:
216
212
  bug_tracker_uri: https://github.com/spree/spree_gateway/issues
217
- changelog_uri: https://github.com/spree/spree_gateway/releases/tag/v3.9.4
213
+ changelog_uri: https://github.com/spree/spree_gateway/releases/tag/v3.10.0
218
214
  documentation_uri: https://guides.spreecommerce.org/
219
- source_code_uri: https://github.com/spree/spree_gateway/tree/v3.9.4
215
+ source_code_uri: https://github.com/spree/spree_gateway/tree/v3.10.0
220
216
  post_install_message:
221
217
  rdoc_options: []
222
218
  require_paths:
@@ -233,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
229
  version: '0'
234
230
  requirements:
235
231
  - none
236
- rubygems_version: 3.2.3
232
+ rubygems_version: 3.0.9
237
233
  signing_key:
238
234
  specification_version: 4
239
235
  summary: Additional Payment Gateways for Spree Commerce
@@ -270,6 +266,7 @@ test_files:
270
266
  - spec/models/gateway/worldpay_spec.rb
271
267
  - spec/models/spree/order_spec.rb
272
268
  - spec/requests/apple_pay_domain_verification.rb
269
+ - spec/requests/spree/api/v2/storefront/intents_controller_spec.rb
273
270
  - spec/spec_helper.rb
274
271
  - spec/support/order_walktrough.rb
275
272
  - spec/support/wait_for_stripe.rb
@@ -1,9 +0,0 @@
1
- class UpdateBraintreePaymentMethodType < SpreeExtension::Migration[4.2]
2
- def up
3
- Spree::PaymentMethod.where(:type => "Spree::Gateway::Braintree").update_all(:type => "Spree::Gateway::BraintreeGateway")
4
- end
5
-
6
- def down
7
- Spree::PaymentMethod.where(:type => "Spree::Gateway::BraintreeGateway").update_all(:type => "Spree::Gateway::Braintree")
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class UpdateStripePaymentMethodType < SpreeExtension::Migration[4.2]
2
- def up
3
- Spree::PaymentMethod.where(:type => "Spree::Gateway::Stripe").update_all(:type => "Spree::Gateway::StripeGateway")
4
- end
5
-
6
- def down
7
- Spree::PaymentMethod.where(:type => "Spree::Gateway::StripeGateway").update_all(:type => "Spree::Gateway::Stripe")
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class UpdateBalancedPaymentMethodType < SpreeExtension::Migration[4.2]
2
- def up
3
- Spree::PaymentMethod.where(:type => "Spree::Gateway::Balanced").update_all(:type => "Spree::Gateway::BalancedGateway")
4
- end
5
-
6
- def down
7
- Spree::PaymentMethod.where(:type => "Spree::Gateway::BalancedGateway").update_all(:type => "Spree::Gateway::Balanced")
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class UpdatePaypalPaymentMethodType < SpreeExtension::Migration[4.2]
2
- def up
3
- Spree::PaymentMethod.where(:type => "Spree::Gateway::PayPal").update_all(:type => "Spree::Gateway::PayPalGateway")
4
- end
5
-
6
- def down
7
- Spree::PaymentMethod.where(:type => "Spree::Gateway::PayPalGateway").update_all(:type => "Spree::Gateway::PayPal")
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- class MigrateStripePreferences < SpreeExtension::Migration[4.2]
2
- def up
3
- Spree::Preference.where("#{ActiveRecord::Base.connection.quote_column_name("key")} LIKE 'spree/gateway/stripe_gateway/login%'").each do |pref|
4
- pref.key = pref.key.gsub('login', 'secret_key')
5
- pref.save
6
- end
7
- end
8
- end