spree_vpago 2.3.11 → 2.3.13.pre.pre1

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test_and_publish_gem.yml +6 -6
  3. data/Gemfile.lock +28 -28
  4. data/app/assets/config/spree_vpago_manifest.js +1 -0
  5. data/app/assets/javascripts/vpago/vpago_payments/create_transaction.js +35 -0
  6. data/app/controllers/spree/admin/payment_acleda_v2_base_controller.rb +21 -0
  7. data/app/controllers/spree/admin/payment_acleda_v2_checkers_controller.rb +26 -0
  8. data/app/controllers/spree/admin/payment_acleda_v2_queriers_controller.rb +38 -0
  9. data/app/controllers/spree/admin/payment_vattanac_base_controller.rb +21 -0
  10. data/app/controllers/spree/admin/payment_vattanac_checkers_controller.rb +26 -0
  11. data/app/controllers/spree/admin/payment_vattanac_queriers_controller.rb +38 -0
  12. data/app/controllers/spree/vpago_payments_controller.rb +21 -0
  13. data/app/models/spree/gateway/payway_v2.rb +6 -0
  14. data/app/models/spree/gateway/true_money.rb +4 -0
  15. data/app/models/vpago/payment_decorator.rb +1 -0
  16. data/app/models/vpago/payment_method_decorator.rb +14 -0
  17. data/app/services/vpago/payment_url_constructor.rb +1 -0
  18. data/app/views/layouts/vpago_payments.html.erb +1 -0
  19. data/app/views/spree/admin/payments/source_views/_acleda_v2.html.erb +2 -2
  20. data/app/views/spree/admin/payments/source_views/_vattanac.html.erb +3 -3
  21. data/app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb +35 -42
  22. data/app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb +15 -15
  23. data/config/routes.rb +7 -0
  24. data/lib/spree_vpago/version.rb +1 -1
  25. data/lib/vpago/acleda_v2/payment_request_updater.rb +54 -0
  26. data/lib/vpago/payway_v2/transaction_creator.rb +29 -0
  27. data/lib/vpago/vattanac/payment_request_updater.rb +54 -0
  28. data/lib/vpago/vattanac/transaction_status.rb +17 -1
  29. data/node_modules/.yarn-integrity +232 -4
  30. data/spree_vpago.gemspec +1 -1
  31. metadata +18 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 135ae8e71835e73aacb8af2817bf0702b7a9b09e5e7a978380235b6e694b286e
4
- data.tar.gz: a9d35bf4ce64a37c90e50217be487b218674ba1c7e5abdfbeb5117407371994e
3
+ metadata.gz: 1a704b3b4c6172fcfac73d2b395be971f8706c137260c6d122e530160260f276
4
+ data.tar.gz: fc86b46f2cde8a9de6426b413196cc707b32dc141c78d756d17ae9de654893f3
5
5
  SHA512:
6
- metadata.gz: 51e6f6db2eee4946a21b5d344718432befd1ceb9f67a89c5d2af44dcd1ce707fc369a10d5a4c14aca07e20ac15904fd63581191623070fec92397eaea1efb12a
7
- data.tar.gz: fd4dc35df53a19b819bcdb761d76d8badf59b6d1416232978167a4fab9733781c2a4bc5a5605319736c7bcb47ec1e82f805142fe3094b1562cb79b6c392e671f
6
+ metadata.gz: 229e3073db012f2f0a1ab6a9b47ea893eaf751b0d3937211490743d81a41800024e2263dd07269fdfdc3549449288bf13263df0737bf6a4dcda2a4a768acae53
7
+ data.tar.gz: a8ea4e06485c9bd95d6f6616379c6c8dee5e8b6090dddb1a30446ec16ea0697984db1480a027ad7150b68e801bf295c50e13998fcc8232eddeb2fe9e32605920
@@ -12,7 +12,7 @@ on:
12
12
  - 112-ci-cd
13
13
  - 245-build-and-publish-gem
14
14
  tags:
15
- - "*"
15
+ - "*"
16
16
  jobs:
17
17
  test_and_publish_gem:
18
18
  runs-on: ubuntu-latest
@@ -66,11 +66,11 @@ jobs:
66
66
  # run: |
67
67
  # bundle exec brakeman
68
68
 
69
- # - name: Run test
70
- # env:
71
- # DATABASE_URL: postgres://myuser:mypassword@localhost:5432/test_db
72
- # run: |
73
- # bundle exec rake
69
+ - name: Run test
70
+ env:
71
+ DATABASE_URL: postgres://myuser:mypassword@localhost:5432/test_db
72
+ run: |
73
+ bundle exec rake
74
74
 
75
75
  - name: Build gem
76
76
  env:
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.3.11)
4
+ spree_vpago (2.3.13.pre.pre1)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
8
8
  spree_backend (>= 4.5)
9
9
  spree_core (>= 4.5)
10
- spree_extension
10
+ spree_extension (< 1.0)
11
11
  spree_multi_vendor (>= 2.4.1)
12
12
 
13
13
  GEM
@@ -128,7 +128,7 @@ GEM
128
128
  babel-source (>= 4.0, < 6)
129
129
  execjs (~> 2.0)
130
130
  base64 (0.3.0)
131
- bcrypt (3.1.22)
131
+ bcrypt (3.1.21)
132
132
  bigdecimal (3.1.8)
133
133
  bootstrap (4.6.2.1)
134
134
  autoprefixer-rails (>= 9.1.0)
@@ -176,11 +176,10 @@ GEM
176
176
  rainbow (>= 2.1.0)
177
177
  diff-lcs (1.5.0)
178
178
  docile (1.4.0)
179
- doorkeeper (5.9.6)
179
+ doorkeeper (5.8.2)
180
180
  railties (>= 5)
181
181
  erubi (1.12.0)
182
- execjs (2.10.2)
183
- json (>= 2)
182
+ execjs (2.10.0)
184
183
  factory_bot (4.11.1)
185
184
  activesupport (>= 3.0.0)
186
185
  faraday (2.7.4)
@@ -189,7 +188,7 @@ GEM
189
188
  faraday-http-cache (2.5.0)
190
189
  faraday (>= 0.8)
191
190
  faraday-net_http (3.0.2)
192
- faraday-retry (2.4.0)
191
+ faraday-retry (2.3.2)
193
192
  faraday (~> 2.0)
194
193
  ffaker (2.21.0)
195
194
  ffi (1.15.5)
@@ -199,7 +198,7 @@ GEM
199
198
  flatpickr (4.6.13.1)
200
199
  friendly_id (5.5.0)
201
200
  activerecord (>= 4.0.0)
202
- gapic-common (1.3.0)
201
+ gapic-common (1.2.0)
203
202
  faraday (>= 1.9, < 3.a)
204
203
  faraday-retry (>= 1.0, < 3.a)
205
204
  google-cloud-env (~> 2.2)
@@ -222,45 +221,45 @@ GEM
222
221
  globalid (1.1.0)
223
222
  activesupport (>= 5.0)
224
223
  glyphicons (1.0.2)
225
- google-cloud-core (1.9.0)
224
+ google-cloud-core (1.8.0)
226
225
  google-cloud-env (>= 1.0, < 3.a)
227
226
  google-cloud-errors (~> 1.0)
228
- google-cloud-env (2.4.0)
227
+ google-cloud-env (2.3.1)
229
228
  base64 (~> 0.2)
230
229
  faraday (>= 1.0, < 3.a)
231
- google-cloud-errors (1.7.0)
232
- google-cloud-firestore (3.2.0)
230
+ google-cloud-errors (1.5.0)
231
+ google-cloud-firestore (3.1.1)
233
232
  bigdecimal (~> 3.0)
234
233
  concurrent-ruby (~> 1.0)
235
234
  google-cloud-core (~> 1.7)
236
235
  google-cloud-firestore-v1 (~> 2.0)
237
236
  rbtree (~> 0.4.2)
238
- google-cloud-firestore-v1 (2.4.0)
239
- gapic-common (~> 1.3)
237
+ google-cloud-firestore-v1 (2.3.0)
238
+ gapic-common (~> 1.2)
240
239
  google-cloud-errors (~> 1.0)
241
240
  google-cloud-location (~> 1.0)
242
- google-cloud-location (1.5.1)
243
- gapic-common (~> 1.3)
241
+ google-cloud-location (1.2.1)
242
+ gapic-common (~> 1.2)
244
243
  google-cloud-errors (~> 1.0)
245
244
  google-logging-utils (0.2.0)
246
- google-protobuf (4.33.6)
245
+ google-protobuf (4.33.4)
247
246
  bigdecimal
248
247
  rake (>= 13)
249
- googleapis-common-protos (1.10.0)
248
+ googleapis-common-protos (1.9.0)
250
249
  google-protobuf (~> 4.26)
251
250
  googleapis-common-protos-types (~> 1.21)
252
251
  grpc (~> 1.41)
253
- googleapis-common-protos-types (1.23.0)
252
+ googleapis-common-protos-types (1.22.0)
254
253
  google-protobuf (~> 4.26)
255
- googleauth (1.17.4)
254
+ googleauth (1.16.1)
256
255
  faraday (>= 1.0, < 3.a)
257
256
  google-cloud-env (~> 2.2)
258
257
  google-logging-utils (~> 0.1)
259
258
  jwt (>= 1.4, < 4.0)
259
+ multi_json (~> 1.11)
260
260
  os (>= 0.9, < 2.0)
261
- pstore (~> 0.1)
262
261
  signet (>= 0.16, < 2.a)
263
- grpc (1.83.1)
262
+ grpc (1.76.0)
264
263
  google-protobuf (>= 3.25, < 5.0)
265
264
  googleapis-common-protos-types (~> 1.0)
266
265
  hashdiff (1.1.0)
@@ -370,7 +369,6 @@ GEM
370
369
  pry (0.14.2)
371
370
  coderay (~> 1.1)
372
371
  method_source (~> 1.0)
373
- pstore (0.2.1)
374
372
  public_suffix (5.0.1)
375
373
  puma (6.2.2)
376
374
  nio4r (~> 2.0)
@@ -414,13 +412,13 @@ GEM
414
412
  activerecord (>= 6.0.4)
415
413
  activesupport (>= 6.0.4)
416
414
  i18n
417
- rbtree (0.4.7)
415
+ rbtree (0.4.6)
418
416
  redis (5.0.6)
419
417
  redis-client (>= 0.9.0)
420
418
  redis-client (0.14.1)
421
419
  connection_pool
422
420
  regexp_parser (2.11.3)
423
- responders (3.2.1)
421
+ responders (3.2.0)
424
422
  actionpack (>= 7.0)
425
423
  railties (>= 7.0)
426
424
  rexml (3.2.9)
@@ -494,10 +492,11 @@ GEM
494
492
  websocket (~> 1.0)
495
493
  shoulda-matchers (6.2.0)
496
494
  activesupport (>= 5.2.0)
497
- signet (0.22.0)
495
+ signet (0.21.0)
498
496
  addressable (~> 2.8)
499
497
  faraday (>= 0.17.5, < 3.a)
500
498
  jwt (>= 1.5, < 4.0)
499
+ multi_json (~> 1.10)
501
500
  simplecov (0.22.0)
502
501
  docile (~> 1.1)
503
502
  simplecov-html (~> 0.11)
@@ -594,8 +593,9 @@ GEM
594
593
  actionmailer
595
594
  spree_core (>= 4.5.3)
596
595
  sprockets (>= 4.0)
597
- spree_extension (1.0.2)
598
- thor (~> 1.0)
596
+ spree_extension (0.1.0)
597
+ activerecord (>= 4.2)
598
+ spree_core
599
599
  spree_multi_vendor (2.4.1)
600
600
  deface (~> 1.0)
601
601
  spree (>= 4.3.0.rc1)
@@ -1,4 +1,5 @@
1
1
  //= link_tree ../images
2
2
  //= link vpago/vpago_payments/check_transaction_periodically.js
3
+ //= link vpago/vpago_payments/create_transaction.js
3
4
  //= link vpago/vpago_payments/request_process_payment.js
4
5
  //= link vpago/vpago_payments/user_informers/firebase.js
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Calls our own server, which creates the bank transaction on the browser's
3
+ * behalf and returns the bank's response as JSON.
4
+ *
5
+ * @param {Object} options
6
+ * @param {string} options.url
7
+ * @param {Function} options.onSuccess
8
+ * @param {Function} options.onError
9
+ */
10
+ async function createTransaction({ url, onSuccess, onError }) {
11
+ try {
12
+ const response = await fetch(url, {
13
+ method: "POST",
14
+ headers: {
15
+ "X-CSRF-Token": document
16
+ .querySelector('meta[name="csrf-token"]')
17
+ .getAttribute("content"),
18
+ },
19
+ });
20
+ const data = await response.json();
21
+
22
+ if (!response.ok || data.error) {
23
+ console.error("[Vpago] createTransaction failed:", JSON.stringify(data));
24
+ onError(data);
25
+ return;
26
+ }
27
+
28
+ onSuccess(data);
29
+ } catch (error) {
30
+ console.error("[Vpago] createTransaction request failed:", error);
31
+ onError(error);
32
+ }
33
+ }
34
+
35
+ window.createTransaction = createTransaction;
@@ -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
@@ -69,6 +69,27 @@ module Spree
69
69
  render json: { status: :pending }, status: :ok
70
70
  end
71
71
 
72
+ # POST
73
+ def create_transaction
74
+ @payment = Vpago::PaymentFinder.new(params.permit!.to_h).find_and_verify
75
+ raise ActiveRecord::RecordNotFound unless @payment.present?
76
+
77
+ return render json: { error: true, message: 'unsupported' }, status: :not_implemented unless @payment.payment_method.support_create_transaction_api?
78
+
79
+ result = VpagoLogger.log(
80
+ label: 'Spree::VpagoPaymentsController#create_transaction',
81
+ data: vpago_log_context
82
+ ) { @payment.payment_method.create_transaction(@payment, platform: params[:platform]) }
83
+
84
+ render json: result, status: :ok
85
+ rescue Faraday::Error, JSON::ParserError, NoMethodError => e
86
+ VpagoLogger.error(
87
+ label: 'Spree::VpagoPaymentsController#create_transaction failed',
88
+ data: vpago_log_context(error_class: e.class.name, error_message: e.message)
89
+ )
90
+ render json: { error: true, message: 'Failed to create transaction' }, status: :bad_gateway
91
+ end
92
+
72
93
  # POST
73
94
  def process_payment
74
95
  return render json: { status: :ok }, status: :ok if request.method != 'POST'
@@ -168,6 +168,12 @@ module Spree
168
168
  checker
169
169
  end
170
170
 
171
+ def create_transaction(payment, options = {})
172
+ creator = Vpago::PaywayV2::TransactionCreator.new(payment, disable_return_deeplink: options[:platform] == 'web')
173
+ creator.call
174
+ creator.json_response
175
+ end
176
+
171
177
  private
172
178
 
173
179
  def cancel_pre_auth(payment)
@@ -78,5 +78,9 @@ module Spree
78
78
  checker.call
79
79
  checker
80
80
  end
81
+
82
+ def create_transaction(payment, options = {})
83
+ Vpago::TrueMoney::Checkout.new(payment).generate_payment_urls(options[:platform])
84
+ end
81
85
  end
82
86
  end
@@ -24,6 +24,7 @@ module Vpago
24
24
  :success_url,
25
25
  :success_deeplink_url,
26
26
  :check_transaction_url,
27
+ :create_transaction_url,
27
28
  :process_payment_url,
28
29
  to: :url_constructor
29
30
 
@@ -43,6 +43,12 @@ module Vpago
43
43
  respond_to?(:check_transaction)
44
44
  end
45
45
 
46
+ # The payment method must implement `create_transaction(payment, options = {})`,
47
+ # returning a Hash suitable for `render json:` directly.
48
+ def support_create_transaction_api?
49
+ respond_to?(:create_transaction)
50
+ end
51
+
46
52
  # TODO: we have already implement purchase for payway_v2.
47
53
  # make sure to implement this on other payment method as well.
48
54
  def purchase(_amount, _source, _gateway_options = {})
@@ -80,6 +86,10 @@ module Vpago
80
86
  ::Vpago::Acleda::PaymentRequestUpdater
81
87
  elsif type_acleda_mobile?
82
88
  ::Vpago::AcledaMobile::PaymentRequestUpdater
89
+ elsif type_acleda_v2?
90
+ ::Vpago::AcledaV2::PaymentRequestUpdater
91
+ elsif type_vattanac?
92
+ ::Vpago::Vattanac::PaymentRequestUpdater
83
93
  end
84
94
  end
85
95
 
@@ -107,6 +117,10 @@ module Vpago
107
117
  type == Spree::PaymentMethod::TYPE_WINGSDK
108
118
  end
109
119
 
120
+ def type_vattanac?
121
+ type == Spree::PaymentMethod::TYPE_VATTANAC
122
+ end
123
+
110
124
  def type_vattanac_mini_app?
111
125
  type == Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
112
126
  end
@@ -18,6 +18,7 @@ module Vpago
18
18
  def success_deeplink_url = "#{app_scheme}://#{URI(base_url).host}/book/payment?number=#{order.number}&tk=#{order.token}"
19
19
 
20
20
  def check_transaction_url = "#{base_url}/vpago_payments/check_transaction?#{query}"
21
+ def create_transaction_url = "#{base_url}/vpago_payments/create_transaction?#{query}"
21
22
  def process_payment_url = "#{base_url}/vpago_payments/process_payment?#{query}"
22
23
 
23
24
  def query
@@ -11,6 +11,7 @@
11
11
  <%= yield :head %>
12
12
 
13
13
  <%= javascript_include_tag "vpago/vpago_payments/check_transaction_periodically", 'data-turbo-track': 'reload' %>
14
+ <%= javascript_include_tag "vpago/vpago_payments/create_transaction", 'data-turbo-track': 'reload' %>
14
15
  <%= javascript_include_tag "vpago/vpago_payments/request_process_payment", 'data-turbo-track': 'reload' %>
15
16
  <%= javascript_include_tag "vpago/vpago_payments/user_informers/#{user_informer}", 'data-turbo-track': 'reload' %>
16
17
  </head>
@@ -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
  %>
@@ -43,55 +43,48 @@
43
43
  }
44
44
 
45
45
  function submitFormViaJs(){
46
- var formData = new FormData(document.getElementById("aba_merchant_request"));
47
- var checkoutUrl = document.getElementById("aba_merchant_request").action;
48
-
49
- fetch(checkoutUrl, {
50
- method: "POST",
51
- body: formData
52
- })
53
- .then(function(response) {
54
- return response.json();
55
- })
56
- .then(function(data) {
57
- console.log("[Vpago] checkout response data:", JSON.stringify(data));
58
-
59
- // When status code is 4 (duplicated transaction),
60
- // Possibly user refresh the checkout page even after the transaction is completed.
61
- // So in this case, we should hide loading spinner and show redirect container UI
62
- // While it check transaction status in the background. It will automatically redirect user to the result page after checking.
63
- if (data.status.code === 4){
64
- showRedirectContainer();
65
- return;
66
- }
46
+ window.createTransaction({
47
+ url: "<%= raw @payment.create_transaction_url %>&platform=<%= params[:platform] %>",
48
+ onSuccess: function(data) {
49
+ console.log("[Vpago] checkout response data:", JSON.stringify(data));
50
+
51
+ // When status code is 4 (duplicated transaction),
52
+ // Possibly user refresh the checkout page even after the transaction is completed.
53
+ // So in this case, we should hide loading spinner and show redirect container UI
54
+ // While it check transaction status in the background. It will automatically redirect user to the result page after checking.
55
+ if (data.status.code === 4){
56
+ showRedirectContainer();
57
+ return;
58
+ }
67
59
 
68
- let deeplinkTriggered = false;
60
+ let deeplinkTriggered = false;
69
61
 
70
- if (data.abapay_deeplink && shouldOpenAbaPayDeeplink) {
71
- window.location.href = data.abapay_deeplink;
72
- deeplinkTriggered = true;
73
- }
62
+ if (data.abapay_deeplink && shouldOpenAbaPayDeeplink) {
63
+ window.location.href = data.abapay_deeplink;
64
+ deeplinkTriggered = true;
65
+ }
74
66
 
75
- if (data.checkout_qr_url && shouldOpenCheckoutUrl) {
76
- // If a deeplink is triggered, add a short delay before navigating to the checkout URL.
77
- // Without this delay, some platforms (especially Android) may ignore or cancel the deeplink
78
- // because a second navigation happens too quickly.
79
- if (deeplinkTriggered){
80
- setTimeout(() => {
67
+ if (data.checkout_qr_url && shouldOpenCheckoutUrl) {
68
+ // If a deeplink is triggered, add a short delay before navigating to the checkout URL.
69
+ // Without this delay, some platforms (especially Android) may ignore or cancel the deeplink
70
+ // because a second navigation happens too quickly.
71
+ if (deeplinkTriggered){
72
+ setTimeout(() => {
73
+ window.location.href = data.checkout_qr_url;
74
+ }, 300);
75
+ } else {
81
76
  window.location.href = data.checkout_qr_url;
82
- }, 300);
83
- } else {
84
- window.location.href = data.checkout_qr_url;
77
+ }
85
78
  }
86
- }
87
79
 
88
- var shouldShowRedirectContainer = !shouldOpenCheckoutUrl && shouldOpenAbaPayDeeplink;
89
- if(shouldShowRedirectContainer){
90
- showRedirectContainer("Open ABA Mobile", () => window.location.href = data.abapay_deeplink);
80
+ var shouldShowRedirectContainer = !shouldOpenCheckoutUrl && shouldOpenAbaPayDeeplink;
81
+ if(shouldShowRedirectContainer){
82
+ showRedirectContainer("Open ABA Mobile", () => window.location.href = data.abapay_deeplink);
83
+ }
84
+ },
85
+ onError: function() {
86
+ document.getElementById('vpago_loading_container').textContent = "We couldn't start your payment. Please go back and try again.";
91
87
  }
92
- })
93
- .catch(function(error) {
94
- console.error("Payment request failed:", error);
95
88
  });
96
89
  }
97
90