spree_vpago 2.1.2 → 2.1.3.pre.beta

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: e82b6ed2c52fdcd372da38e034ab404db96e14054311146497f22e16e8b0b7cb
4
- data.tar.gz: 97deb457994a42b61a6ad0583336d4d0b0b52d14594b4990ee74700754d5a8e3
3
+ metadata.gz: 050cbc236c6ee73efa288a53ccb9ed0d997d5056a364c329cc1d6fdf943c2588
4
+ data.tar.gz: '09dac79729125ce876a4865bc17b9dc58fc37f4153bcf803014f5ed17afc06b3'
5
5
  SHA512:
6
- metadata.gz: 2c53f7fbac300190cfe294852eecc82f67f047b2e66021e2f4f3330f80ea5b7632b9aee6543dd6199bef7c17b9a420e537ff1e5cb8174056b5cd567f004aef02
7
- data.tar.gz: 7484172952f36a0b0802836dbcec0e9d487535605f16340fd3b4a246c0e8b583cce7a5f36feac1b46edc4886f5cef4fea3771298056076e29660fcf246a60aa2
6
+ metadata.gz: b1b906c102871367972b3deff873c39bc5bdc0c2e6748c2324f00e0e0b7db946699b9e2984b8364050c4ff6f929d3dd36473605ee06904141213cb9957b10517
7
+ data.tar.gz: 8b9392064584a88fbb22f0554680c90ba2b3943764e08b8123548d20112946b356e23b7b5fbca533d983e64865c37dcab38af7f03e7b280485c78453f1d99b2e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.1.2)
4
+ spree_vpago (2.1.3.pre.beta)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -198,12 +198,12 @@ GEM
198
198
  flatpickr (4.6.13.1)
199
199
  friendly_id (5.5.0)
200
200
  activerecord (>= 4.0.0)
201
- gapic-common (1.1.0)
201
+ gapic-common (1.2.0)
202
202
  faraday (>= 1.9, < 3.a)
203
203
  faraday-retry (>= 1.0, < 3.a)
204
204
  google-cloud-env (~> 2.2)
205
205
  google-logging-utils (~> 0.1)
206
- google-protobuf (>= 3.25, < 5.a)
206
+ google-protobuf (~> 4.26)
207
207
  googleapis-common-protos (~> 1.6)
208
208
  googleapis-common-protos-types (~> 1.15)
209
209
  googleauth (~> 1.12)
@@ -234,24 +234,24 @@ GEM
234
234
  google-cloud-core (~> 1.7)
235
235
  google-cloud-firestore-v1 (~> 2.0)
236
236
  rbtree (~> 0.4.2)
237
- google-cloud-firestore-v1 (2.1.1)
238
- gapic-common (~> 1.0)
237
+ google-cloud-firestore-v1 (2.2.0)
238
+ gapic-common (~> 1.2)
239
239
  google-cloud-errors (~> 1.0)
240
240
  google-cloud-location (~> 1.0)
241
- google-cloud-location (1.1.0)
242
- gapic-common (~> 1.0)
241
+ google-cloud-location (1.2.0)
242
+ gapic-common (~> 1.2)
243
243
  google-cloud-errors (~> 1.0)
244
244
  google-logging-utils (0.2.0)
245
- google-protobuf (4.32.0)
245
+ google-protobuf (4.33.0-arm64-darwin)
246
246
  bigdecimal
247
247
  rake (>= 13)
248
- googleapis-common-protos (1.8.0)
249
- google-protobuf (>= 3.18, < 5.a)
250
- googleapis-common-protos-types (~> 1.20)
248
+ googleapis-common-protos (1.9.0)
249
+ google-protobuf (~> 4.26)
250
+ googleapis-common-protos-types (~> 1.21)
251
251
  grpc (~> 1.41)
252
- googleapis-common-protos-types (1.20.0)
253
- google-protobuf (>= 3.18, < 5.a)
254
- googleauth (1.15.0)
252
+ googleapis-common-protos-types (1.22.0)
253
+ google-protobuf (~> 4.26)
254
+ googleauth (1.15.1)
255
255
  faraday (>= 1.0, < 3.a)
256
256
  google-cloud-env (~> 2.2)
257
257
  google-logging-utils (~> 0.1)
@@ -259,7 +259,7 @@ GEM
259
259
  multi_json (~> 1.11)
260
260
  os (>= 0.9, < 2.0)
261
261
  signet (>= 0.16, < 2.a)
262
- grpc (1.74.1)
262
+ grpc (1.76.0-arm64-darwin)
263
263
  google-protobuf (>= 3.25, < 5.0)
264
264
  googleapis-common-protos-types (~> 1.0)
265
265
  hashdiff (1.1.0)
@@ -19,6 +19,7 @@ module Vpago
19
19
  payway_cards
20
20
  wingpay
21
21
  vattanac_mini_app
22
+ vattanac
22
23
  true_money
23
24
  ]
24
25
  end
@@ -0,0 +1,70 @@
1
+ module Spree
2
+ class Gateway::Vattanac < PaymentMethod
3
+ preference :generate_payment_url, :string
4
+ preference :access_token_url, :string
5
+ preference :check_transaction_url, :string
6
+
7
+ preference :username, :string
8
+ preference :password, :string
9
+ preference :merchant_id, :string
10
+ preference :payment_type, :string, default: 'GOLF_TICKET'
11
+ preference :open_type, :string, default: 'both'
12
+
13
+ def method_type
14
+ 'vattanac'
15
+ end
16
+
17
+ def payment_source_class
18
+ Spree::VpagoPaymentSource
19
+ end
20
+
21
+ # force to purchase instead of authorize
22
+ def auto_capture?
23
+ true
24
+ end
25
+
26
+ # override
27
+ # purchase is used when pre auth disabled
28
+ def purchase(_amount, _source, gateway_options = {})
29
+ _, payment_number = gateway_options[:order_id].split('-')
30
+ payment = Spree::Payment.find_by(number: payment_number)
31
+
32
+ checker = check_transaction(payment)
33
+ payment.update(transaction_response: checker.json_response)
34
+
35
+ success = checker.success?
36
+ params = {}
37
+
38
+ params[:payment_response] = payment.transaction_response
39
+
40
+ if success
41
+ ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Purchased', params)
42
+ else
43
+ ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Purchasing Failed', params)
44
+ end
45
+ end
46
+
47
+ def vattanac_refund(payment)
48
+ refund_issuer = Vpago::Vattanac::RefundIssuer.new(payment, {})
49
+ refund_issuer.call
50
+
51
+ [refund_issuer.success?, refund_issuer.parsed_response]
52
+ end
53
+
54
+ def cancel(_response_code, _payment)
55
+ # we can use this to send request to payment gateway api to cancel the payment ( void )
56
+ # currently Vattanac does not support to cancel the gateway
57
+
58
+ # in our case don't do anything
59
+ ActiveMerchant::Billing::Response.new(true, '')
60
+ end
61
+
62
+ private
63
+
64
+ def check_transaction(payment)
65
+ checker = Vpago::Vattanac::TransactionStatus.new(payment)
66
+ checker.call
67
+ checker
68
+ end
69
+ end
70
+ end
@@ -61,6 +61,10 @@ module Vpago
61
61
  payment_method.type_true_money?
62
62
  end
63
63
 
64
+ def vattanac_payment?
65
+ payment_method.type_vattanac?
66
+ end
67
+
64
68
  def vattanac_mini_app_payment?
65
69
  payment_method.type_vattanac_mini_app?
66
70
  end
@@ -5,8 +5,9 @@ module Vpago
5
5
  TYPE_WINGSDK = 'Spree::Gateway::WingSdk'.freeze
6
6
  TYPE_ACLEDA = 'Spree::Gateway::Acleda'.freeze
7
7
  TYPE_ACLEDA_MOBILE = 'Spree::Gateway::AcledaMobile'.freeze
8
- TYPE_VATTANAC_MINI_APP = 'Spree::Gateway::VattanacMiniApp'.freeze
9
8
  TYPE_TRUE_MONEY = 'Spree::Gateway::TrueMoney'.freeze
9
+ TYPE_VATTANAC = 'Spree::Gateway::Vattanac'.freeze
10
+ TYPE_VATTANAC_MINI_APP = 'Spree::Gateway::VattanacMiniApp'.freeze
10
11
 
11
12
  def self.prepended(base)
12
13
  base.preference :icon_name, :string, default: 'cheque'
@@ -19,6 +20,7 @@ module Vpago
19
20
  Spree::PaymentMethod::TYPE_WINGSDK,
20
21
  Spree::PaymentMethod::TYPE_ACLEDA,
21
22
  Spree::PaymentMethod::TYPE_ACLEDA_MOBILE,
23
+ Spree::PaymentMethod::TYPE_VATTANAC,
22
24
  Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP,
23
25
  Spree::PaymentMethod::TYPE_TRUE_MONEY
24
26
  ]
@@ -7,7 +7,6 @@ module Vpago
7
7
  end
8
8
 
9
9
  def find_and_verify
10
-
11
10
  find_and_verify!
12
11
  rescue StandardError, ActiveRecord::RecordNotFound => e
13
12
  Rails.logger.error("PaymentJwtVerifier#find_and_verify error: #{e.class} - #{e.message}")
@@ -15,16 +14,15 @@ module Vpago
15
14
  end
16
15
 
17
16
  def find_and_verify!
18
-
19
17
  if vattanac_mini_app_payload?
20
- payload = Vpago::VattanacMiniAppDataHandler.new.decrypt_data(@params_hash[:data])
18
+ payload = Vpago::VattanacMiniAppDataHandler.new.decrypt_data(@params_hash[:data])
21
19
  payment = Spree::Payment.find_by!(number: payload['paymentId'])
22
20
  payment.update(transaction_response: payload)
23
21
  payment
24
- else
22
+ else
25
23
  order = Spree::Order.find_by!(number: params_hash[:order_number])
26
24
  verify_jwt!(order)
27
-
25
+
28
26
  Spree::Payment.find_by!(number: params_hash[:payment_number])
29
27
  end
30
28
  end
@@ -36,8 +34,5 @@ module Vpago
36
34
  def vattanac_mini_app_payload?
37
35
  params_hash[:data].present?
38
36
  end
39
-
40
37
  end
41
38
  end
42
-
43
-
@@ -0,0 +1,6 @@
1
+ <%= render 'spree/admin/payments/source_views/vpago_payment_tmpl',
2
+ payment: payment,
3
+ check_status_url: '',
4
+ heal_payment_url: '',
5
+ manual_update_payment_url: ''
6
+ %>
@@ -0,0 +1,31 @@
1
+ <%
2
+ checkout = Vpago::Vattanac::Checkout.new(@payment)
3
+ result = checkout.create
4
+ payment_url = params[:platform] == 'app' ? result[:mobile_url] : result[:web_url]
5
+ open_type = @payment.payment_method.preferred_open_type
6
+ %>
7
+
8
+ <script>
9
+ const openType = "<%= open_type %>";
10
+ const mobileUrl = "<%= raw(result[:mobile_url]) %>";
11
+ const webUrl = "<%= raw(result[:web_url]) %>";
12
+
13
+ if (openType === "both") {
14
+ if (mobileUrl) {
15
+ window.location.href = mobileUrl;
16
+ setTimeout(() => {
17
+ window.location.href = webUrl;
18
+ }, 1500);
19
+ } else {
20
+ alert("Mobile payment URL not available.");
21
+ }
22
+ } else {
23
+ const paymentUrl = "<%= raw(payment_url) %>";
24
+ if (paymentUrl) {
25
+ window.location.href = paymentUrl;
26
+ } else {
27
+ alert("Failed to create payment link.");
28
+ }
29
+ }
30
+ </script>
31
+
@@ -22,6 +22,7 @@ module SpreeVpago
22
22
  Spree::Gateway::WingSdk,
23
23
  Spree::Gateway::Acleda,
24
24
  Spree::Gateway::AcledaMobile,
25
+ Spree::Gateway::Vattanac,
25
26
  Spree::Gateway::VattanacMiniApp,
26
27
  Spree::Gateway::TrueMoney
27
28
  )
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.1.2'.freeze
4
+ VERSION = '2.1.3-beta'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -0,0 +1,90 @@
1
+ require 'faraday'
2
+
3
+ module Vpago
4
+ module Vattanac
5
+ class Base
6
+ CONTENT_TYPE_JSON = 'application/json'.freeze
7
+
8
+ def initialize(payment)
9
+ @payment = payment
10
+ end
11
+
12
+ def username
13
+ payment_method.preferred_username
14
+ end
15
+
16
+ def password
17
+ payment_method.preferred_password
18
+ end
19
+
20
+ def access_token_url
21
+ payment_method.preferred_access_token_url
22
+ end
23
+
24
+ def generate_payment_url
25
+ payment_method.preferred_generate_payment_url
26
+ end
27
+
28
+ def check_transaction_url
29
+ payment_method.preferred_check_transaction_url
30
+ end
31
+
32
+ def access_token
33
+ @access_token ||= fetch_access_token
34
+ end
35
+
36
+ def payment_method
37
+ @payment.payment_method
38
+ end
39
+
40
+ def payment_number
41
+ @payment.number
42
+ end
43
+
44
+ def payment_type
45
+ payment_method.preferred_payment_type
46
+ end
47
+
48
+ def merchant_id
49
+ payment_method.preferred_merchant_id
50
+ end
51
+
52
+ def amount
53
+ @payment.amount
54
+ end
55
+
56
+ def currency
57
+ 'USD'
58
+ end
59
+
60
+ def default_headers
61
+ { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => CONTENT_TYPE_JSON }
62
+ end
63
+
64
+ def parse_json(body)
65
+ JSON.parse(body)
66
+ rescue JSON::ParserError
67
+ {}
68
+ end
69
+
70
+ private
71
+
72
+ def fetch_access_token
73
+ response = Faraday.post(access_token_url, { username: username, password: password }.to_json, { 'Content-Type' => CONTENT_TYPE_JSON })
74
+ raise "Access Token Error: #{response.status} - #{response.body}" unless response.success?
75
+
76
+ parse_json(response.body).dig('data', 'accessToken') || raise('Missing accessToken in response')
77
+ end
78
+
79
+ def post(url, body)
80
+ response = Faraday.post(url, body.to_json, default_headers)
81
+ parse_json(response.body)
82
+ end
83
+
84
+ def get(url, params)
85
+ response = Faraday.get(url, params, default_headers)
86
+ parse_json(response.body)['data'] || {}
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,27 @@
1
+ module Vpago
2
+ module Vattanac
3
+ class Checkout < Base
4
+ def payload
5
+ {
6
+ transactionId: payment_number,
7
+ requestId: "req-#{SecureRandom.hex(8)}",
8
+ paymentType: payment_type,
9
+ amount: amount,
10
+ currency: currency,
11
+ merchantId: merchant_id,
12
+ returnUrl: @payment.processing_url
13
+ }
14
+ end
15
+
16
+ def create
17
+ response_data = post(generate_payment_url, payload)['data']
18
+ {
19
+ web_url: response_data['webPaymentUrl'],
20
+ mobile_url: response_data['mobileDeepLink'],
21
+ expires_at: response_data['expiredIn'],
22
+ generated_at: response_data['generatedAt']
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module Vpago
2
+ module Vattanac
3
+ class TransactionStatus < Base
4
+ def call
5
+ @response = post(check_transaction_url, payload)
6
+ end
7
+
8
+ def json_response
9
+ @response
10
+ end
11
+
12
+ def success?
13
+ @response.dig('msgEntity', 'code') == '0'
14
+ end
15
+
16
+ private
17
+
18
+ def payload
19
+ { transactionId: payment_number }
20
+ end
21
+ end
22
+ end
23
+ 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.1.2
4
+ version: 2.1.3.pre.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-26 00:00:00.000000000 Z
11
+ date: 2025-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -193,6 +193,7 @@ files:
193
193
  - app/models/spree/gateway/payway.rb
194
194
  - app/models/spree/gateway/payway_v2.rb
195
195
  - app/models/spree/gateway/true_money.rb
196
+ - app/models/spree/gateway/vattanac.rb
196
197
  - app/models/spree/gateway/vattanac_mini_app.rb
197
198
  - app/models/spree/gateway/wing_sdk.rb
198
199
  - app/models/spree/payout.rb
@@ -277,6 +278,7 @@ files:
277
278
  - app/views/spree/admin/payments/source_views/_payment_payway.html.erb
278
279
  - app/views/spree/admin/payments/source_views/_payway_v2.html.erb
279
280
  - app/views/spree/admin/payments/source_views/_true_money.html.erb
281
+ - app/views/spree/admin/payments/source_views/_vattanac.html.erb
280
282
  - app/views/spree/admin/payments/source_views/_vattanac_mini_app.html.erb
281
283
  - app/views/spree/admin/payments/source_views/_vpago_payment_tmpl.html.erb
282
284
  - app/views/spree/admin/payments/source_views/_wingsdk.html.erb
@@ -325,6 +327,7 @@ files:
325
327
  - app/views/spree/vpago_payments/checkout.html.erb
326
328
  - app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb
327
329
  - app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb
330
+ - app/views/spree/vpago_payments/forms/spree/gateway/_vattanac.html.erb
328
331
  - app/views/spree/vpago_payments/forms/spree/gateway/_vattanac_mini_app.html.erb
329
332
  - app/views/spree/vpago_payments/processing.html.erb
330
333
  - app/views/spree/vpago_payments/success.html.erb
@@ -398,6 +401,9 @@ files:
398
401
  - lib/vpago/true_money/checkout.rb
399
402
  - lib/vpago/true_money/refund_issuer.rb
400
403
  - lib/vpago/true_money/transaction_status.rb
404
+ - lib/vpago/vattanac/base.rb
405
+ - lib/vpago/vattanac/checkout.rb
406
+ - lib/vpago/vattanac/transaction_status.rb
401
407
  - lib/vpago/vattanac_mini_app/base.rb
402
408
  - lib/vpago/vattanac_mini_app/checkout.rb
403
409
  - lib/vpago/vattanac_mini_app/refund_issuer.rb
@@ -428,9 +434,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
428
434
  version: 3.2.0
429
435
  required_rubygems_version: !ruby/object:Gem::Requirement
430
436
  requirements:
431
- - - ">="
437
+ - - ">"
432
438
  - !ruby/object:Gem::Version
433
- version: '0'
439
+ version: 1.3.1
434
440
  requirements:
435
441
  - none
436
442
  rubygems_version: 3.4.1