spree_vpago 2.3.10 → 2.3.12

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: 83977e379d14f72df6f9812c0053817ead75a9a29d9dbb26efbb505679fd34f1
4
- data.tar.gz: d478a6a31649dba472adebefb5890c60a5222107252c71b9a835d7260e95cf97
3
+ metadata.gz: f7c6fc347bce48aed54a98bf47d4432f79ec1144a882f7c6cf14b55ad1f87663
4
+ data.tar.gz: c62d76d1e6661bc0460b3a4be75feeb6d4c6c8a3b1278d1b62dccb53324b6e1a
5
5
  SHA512:
6
- metadata.gz: 9c76fd67f78cacde387d8b817ec6b2ff9707dc39fb31d1419498af347c8aee1bf12d4d533af79c0ad90efb44ae80517096a9578e803e6fd2fe937380eca8478b
7
- data.tar.gz: 3d44c01a03c35f692ba70d5091a41ca03d9c7e3e9fdd37e0a87b984196e155c37534462b39d396e970462a2522fa6fdde9d60b525147689ccc1184c28e8cb42f
6
+ metadata.gz: 2973459504b60f1f6308e6f0db319c1b2e25f19747d2f94aeb3bf48f69b75e87c508f57c197a49440920464952df30e1cb3b6797ba9a782ff375ec1a7c0b0893
7
+ data.tar.gz: e8418cf6a8298850075104813a93da543ab148327d7ee6cafdd63be2c1ce5eb64fe457888d695af4931a1b459ee3e60282553e22875a7b530d3099d002c60b8b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.3.10)
4
+ spree_vpago (2.3.12)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -0,0 +1,21 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentAcledaV2BaseController < Spree::Admin::BaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ before_action :load_payment, only: %i[show update]
7
+ before_action :validate_order, only: [:update]
8
+
9
+ def validate_order
10
+ return unless @payment.order.completed?
11
+
12
+ flash[:error] = Spree.t('vpago.payments.not_allow_for_order_completed')
13
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
14
+ end
15
+
16
+ def load_payment
17
+ @payment = Payment.find_by!(number: params[:id])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentAcledaV2CheckersController < PaymentAcledaV2BaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ def update
7
+ options = {
8
+ updated_by_user_id: try_spree_current_user.id,
9
+ updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
10
+ }
11
+ spree_updater = Vpago::AcledaV2::PaymentRequestUpdater.new(@payment, options)
12
+ spree_updater.call
13
+
14
+ @payment.reload
15
+
16
+ if @payment.order.completed?
17
+ flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payments))
18
+ else
19
+ flash[:error] = Spree.t(:unsuccessfully_updated, resource: Spree.t(:payments))
20
+ end
21
+
22
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentAcledaV2QueriersController < PaymentAcledaV2BaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ around_action :set_writing_role, only: %i[show]
7
+
8
+ def show
9
+ tran_status = @payment.payment_method.check_transaction(@payment)
10
+
11
+ if tran_status.success?
12
+ @payment.update_column(:gateway_status, true)
13
+ flash[:success] =
14
+ Spree.t('vpago.payments.payment_found_with_result', result: tran_status.json_response)
15
+ else
16
+ flash[:error] = Spree.t('vpago.payments.payment_not_found_with_error', error: tran_status.error_message)
17
+ end
18
+
19
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
20
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
21
+ VpagoLogger.error(
22
+ label: 'Spree::Admin::PaymentAcledaV2QueriersController#show gateway_timeout',
23
+ data: { payment_number: @payment.number, error_class: e.class.name, error_message: e.message }
24
+ )
25
+ flash[:error] = Spree.t('vpago.payments.gateway_timeout')
26
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
27
+ end
28
+
29
+ private
30
+
31
+ def set_writing_role
32
+ ActiveRecord::Base.connected_to(role: :writing) do
33
+ yield if block_given?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentVattanacBaseController < Spree::Admin::BaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ before_action :load_payment, only: %i[show update]
7
+ before_action :validate_order, only: [:update]
8
+
9
+ def validate_order
10
+ return unless @payment.order.completed?
11
+
12
+ flash[:error] = Spree.t('vpago.payments.not_allow_for_order_completed')
13
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
14
+ end
15
+
16
+ def load_payment
17
+ @payment = Payment.find_by!(number: params[:id])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentVattanacCheckersController < PaymentVattanacBaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ def update
7
+ options = {
8
+ updated_by_user_id: try_spree_current_user.id,
9
+ updated_reason: Spree.t('vpago.payments.checker_updated_by_description')
10
+ }
11
+ spree_updater = Vpago::Vattanac::PaymentRequestUpdater.new(@payment, options)
12
+ spree_updater.call
13
+
14
+ @payment.reload
15
+
16
+ if @payment.order.completed?
17
+ flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payments))
18
+ else
19
+ flash[:error] = Spree.t(:unsuccessfully_updated, resource: Spree.t(:payments))
20
+ end
21
+
22
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ module Spree
2
+ module Admin
3
+ class PaymentVattanacQueriersController < PaymentVattanacBaseController
4
+ include Spree::Backend::Callbacks
5
+
6
+ around_action :set_writing_role, only: %i[show]
7
+
8
+ def show
9
+ tran_status = @payment.payment_method.check_transaction(@payment)
10
+
11
+ if tran_status.success?
12
+ @payment.update_column(:gateway_status, true)
13
+ flash[:success] =
14
+ Spree.t('vpago.payments.payment_found_with_result', result: tran_status.json_response)
15
+ else
16
+ flash[:error] = Spree.t('vpago.payments.payment_not_found_with_error', error: tran_status.error_message)
17
+ end
18
+
19
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
20
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
21
+ VpagoLogger.error(
22
+ label: 'Spree::Admin::PaymentVattanacQueriersController#show gateway_timeout',
23
+ data: { payment_number: @payment.number, error_class: e.class.name, error_message: e.message }
24
+ )
25
+ flash[:error] = Spree.t('vpago.payments.gateway_timeout')
26
+ redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
27
+ end
28
+
29
+ private
30
+
31
+ def set_writing_role
32
+ ActiveRecord::Base.connected_to(role: :writing) do
33
+ yield if block_given?
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -23,6 +23,7 @@ module Spree
23
23
  # GET
24
24
  def processing
25
25
  @order = @payment.order
26
+ return redirect_to @payment.success_url, allow_other_host: true if @order.completed?
26
27
 
27
28
  VpagoLogger.log(label: 'Spree::VpagoPaymentsController#processing', data: vpago_log_context)
28
29
  end
@@ -80,6 +80,10 @@ module Vpago
80
80
  ::Vpago::Acleda::PaymentRequestUpdater
81
81
  elsif type_acleda_mobile?
82
82
  ::Vpago::AcledaMobile::PaymentRequestUpdater
83
+ elsif type_acleda_v2?
84
+ ::Vpago::AcledaV2::PaymentRequestUpdater
85
+ elsif type_vattanac?
86
+ ::Vpago::Vattanac::PaymentRequestUpdater
83
87
  end
84
88
  end
85
89
 
@@ -107,6 +111,10 @@ module Vpago
107
111
  type == Spree::PaymentMethod::TYPE_WINGSDK
108
112
  end
109
113
 
114
+ def type_vattanac?
115
+ type == Spree::PaymentMethod::TYPE_VATTANAC
116
+ end
117
+
110
118
  def type_vattanac_mini_app?
111
119
  type == Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
112
120
  end
@@ -14,6 +14,12 @@ module Spree
14
14
 
15
15
  pref.blank? || pref[:payment_option].blank? ? payment_method.method_type : pref[:payment_option]
16
16
  end
17
+
18
+ # Overried the payment method type to show all payment methods as one list on App.
19
+ # Controlled by ENV["PAYMENT_METHOD_VIEW"] = "split" | "join" (default: "join").
20
+ base.attribute :type do |payment_method|
21
+ ENV.fetch('PAYMENT_METHOD_VIEW', 'join') == 'split' ? payment_method.type : 'payment_method'
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -1,5 +1,5 @@
1
1
  <%= render 'spree/admin/payments/source_views/vpago_payment_tmpl',
2
2
  payment: payment,
3
- check_status_url: '',
4
- heal_payment_url: '',
3
+ check_status_url: admin_payment_acleda_v2_querier_path(payment),
4
+ heal_payment_url: admin_payment_acleda_v2_checker_path(payment),
5
5
  manual_update_payment_url: '' %>
@@ -1,6 +1,6 @@
1
1
  <%= render 'spree/admin/payments/source_views/vpago_payment_tmpl',
2
- payment: payment,
3
- check_status_url: '',
4
- heal_payment_url: '',
2
+ payment: payment,
3
+ check_status_url: admin_payment_vattanac_querier_path(payment),
4
+ heal_payment_url: admin_payment_vattanac_checker_path(payment),
5
5
  manual_update_payment_url: ''
6
6
  %>
data/config/routes.rb CHANGED
@@ -73,6 +73,12 @@ Spree::Core::Engine.add_routes do
73
73
  resources :payment_payway_checkers
74
74
  resources :payment_payway_markers
75
75
 
76
+ resources :payment_acleda_v2_queriers, only: [:show]
77
+ resources :payment_acleda_v2_checkers, only: [:update]
78
+
79
+ resources :payment_vattanac_queriers, only: [:show]
80
+ resources :payment_vattanac_checkers, only: [:update]
81
+
76
82
  resources :products do
77
83
  resources :payout_profile_products
78
84
  end
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.3.10'.freeze
4
+ VERSION = '2.3.12'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -0,0 +1,54 @@
1
+ module Vpago
2
+ module AcledaV2
3
+ class PaymentRequestUpdater < ::Vpago::PaymentRequestUpdater
4
+ def call
5
+ return if @payment.order.paid?
6
+
7
+ if items_eligible?
8
+ process_payment_status
9
+ else
10
+ mark_items_as_ineligible
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def process_payment_status
17
+ checker = @payment.payment_method.check_transaction(@payment)
18
+
19
+ if checker.success?
20
+ mark_payment_as_success
21
+ elsif checker.failed? && !ignore_on_failed?
22
+ mark_payment_as_failed(checker.error_message)
23
+ end
24
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
25
+ VpagoLogger.error(
26
+ label: 'Vpago::AcledaV2::PaymentRequestUpdater#process_payment_status gateway_timeout',
27
+ data: { payment_number: @payment.number, error_class: e.class.name, error_message: e.message }
28
+ )
29
+ end
30
+
31
+ def items_eligible?
32
+ @payment&.order&.line_items&.all?(&:sufficient_stock?) == true # rubocop:disable Style/SafeNavigationChainLength
33
+ end
34
+
35
+ def mark_items_as_ineligible
36
+ @error_message = 'Items are not eligible due to insufficient stock'
37
+ marker_options = @options.merge(status: false, description: @error_message)
38
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
39
+ end
40
+
41
+ def mark_payment_as_success
42
+ @error_message = nil
43
+ marker_options = @options.merge(status: true, description: nil)
44
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
45
+ end
46
+
47
+ def mark_payment_as_failed(error_message)
48
+ @error_message = error_message
49
+ marker_options = @options.merge(status: false, description: @error_message)
50
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ module Vpago
2
+ module Vattanac
3
+ class PaymentRequestUpdater < ::Vpago::PaymentRequestUpdater
4
+ def call
5
+ return if @payment.order.paid?
6
+
7
+ if items_eligible?
8
+ process_payment_status
9
+ else
10
+ mark_items_as_ineligible
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def process_payment_status
17
+ checker = @payment.payment_method.check_transaction(@payment)
18
+
19
+ if checker.success?
20
+ mark_payment_as_success
21
+ elsif checker.failed? && !ignore_on_failed?
22
+ mark_payment_as_failed(checker.error_message)
23
+ end
24
+ rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
25
+ VpagoLogger.error(
26
+ label: 'Vpago::Vattanac::PaymentRequestUpdater#process_payment_status gateway_timeout',
27
+ data: { payment_number: @payment.number, error_class: e.class.name, error_message: e.message }
28
+ )
29
+ end
30
+
31
+ def items_eligible?
32
+ @payment&.order&.line_items&.all?(&:sufficient_stock?) == true # rubocop:disable Style/SafeNavigationChainLength
33
+ end
34
+
35
+ def mark_items_as_ineligible
36
+ @error_message = 'Items are not eligible due to insufficient stock'
37
+ marker_options = @options.merge(status: false, description: @error_message)
38
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
39
+ end
40
+
41
+ def mark_payment_as_success
42
+ @error_message = nil
43
+ marker_options = @options.merge(status: true, description: nil)
44
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
45
+ end
46
+
47
+ def mark_payment_as_failed(error_message)
48
+ @error_message = error_message
49
+ marker_options = @options.merge(status: false, description: @error_message)
50
+ ::Vpago::PaymentStatusMarker.new(@payment, marker_options).call
51
+ end
52
+ end
53
+ end
54
+ end
@@ -13,6 +13,22 @@ module Vpago
13
13
  @response.dig('data', 'status') == 'SUCCESS'
14
14
  end
15
15
 
16
+ def error_message
17
+ @response.dig('msgEntity', 'message') || @response.dig('data', 'message') || 'Unknown error'
18
+ end
19
+
20
+ # msgEntity.code is the API-envelope result code ("0" = call succeeded; check
21
+ # data.status for the actual transaction state). Any other code is a gateway-level
22
+ # error with no transaction data (e.g. "03" / "Transaction not found") and is
23
+ # treated as terminal failure.
24
+ def failed?
25
+ @response.dig('msgEntity', 'code').to_s != '0'
26
+ end
27
+
28
+ def pending?
29
+ !success? && !failed?
30
+ end
31
+
16
32
  private
17
33
 
18
34
  def payload
@@ -20,4 +36,4 @@ module Vpago
20
36
  end
21
37
  end
22
38
  end
23
- end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_vpago
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.10
4
+ version: 2.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-08-27 00:00:00.000000000 Z
11
+ date: 2026-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -151,11 +151,17 @@ files:
151
151
  - app/assets/javascripts/vpago/vpago_payments/user_informers/firebase.js
152
152
  - app/controllers/.gitkeep
153
153
  - app/controllers/spree/acleda_redirects_controller.rb
154
+ - app/controllers/spree/admin/payment_acleda_v2_base_controller.rb
155
+ - app/controllers/spree/admin/payment_acleda_v2_checkers_controller.rb
156
+ - app/controllers/spree/admin/payment_acleda_v2_queriers_controller.rb
154
157
  - app/controllers/spree/admin/payment_methods_controller_decorator.rb
155
158
  - app/controllers/spree/admin/payment_payway_base_controller.rb
156
159
  - app/controllers/spree/admin/payment_payway_checkers_controller.rb
157
160
  - app/controllers/spree/admin/payment_payway_markers_controller.rb
158
161
  - app/controllers/spree/admin/payment_payway_queriers_controller.rb
162
+ - app/controllers/spree/admin/payment_vattanac_base_controller.rb
163
+ - app/controllers/spree/admin/payment_vattanac_checkers_controller.rb
164
+ - app/controllers/spree/admin/payment_vattanac_queriers_controller.rb
159
165
  - app/controllers/spree/admin/payment_wing_sdk_base_controller.rb
160
166
  - app/controllers/spree/admin/payment_wing_sdk_checkers_controller.rb
161
167
  - app/controllers/spree/admin/payment_wing_sdk_markers_controller.rb
@@ -400,6 +406,7 @@ files:
400
406
  - lib/vpago/acleda_mobile/transaction_status.rb
401
407
  - lib/vpago/acleda_v2/base.rb
402
408
  - lib/vpago/acleda_v2/checkout.rb
409
+ - lib/vpago/acleda_v2/payment_request_updater.rb
403
410
  - lib/vpago/acleda_v2/transaction_status.rb
404
411
  - lib/vpago/http_timeouts.rb
405
412
  - lib/vpago/payment_amount_calculator.rb
@@ -425,6 +432,7 @@ files:
425
432
  - lib/vpago/true_money/transaction_status.rb
426
433
  - lib/vpago/vattanac/base.rb
427
434
  - lib/vpago/vattanac/checkout.rb
435
+ - lib/vpago/vattanac/payment_request_updater.rb
428
436
  - lib/vpago/vattanac/transaction_status.rb
429
437
  - lib/vpago/vattanac_mini_app/base.rb
430
438
  - lib/vpago/vattanac_mini_app/checkout.rb