spree_vpago 2.1.3 → 2.1.4.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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/helpers/vpago/admin/base_helper_decorator.rb +1 -0
- data/app/models/spree/gateway/payway_v2.rb +0 -1
- data/app/models/spree/gateway/vattanac.rb +70 -0
- data/app/models/vpago/payment_decorator.rb +4 -0
- data/app/models/vpago/payment_method_decorator.rb +3 -1
- data/app/services/vpago/payment_finder.rb +3 -8
- data/app/views/spree/admin/payments/source_views/_vattanac.html.erb +6 -0
- data/app/views/spree/vpago_payments/forms/spree/gateway/_vattanac.html.erb +18 -0
- data/lib/spree_vpago/engine.rb +1 -0
- data/lib/spree_vpago/version.rb +1 -1
- data/lib/vpago/payway_v2/base.rb +3 -9
- data/lib/vpago/vattanac/base.rb +87 -0
- data/lib/vpago/vattanac/checkout.rb +27 -0
- data/lib/vpago/vattanac/transaction_status.rb +23 -0
- metadata +10 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8e5d1ebc75ade2a4d140a91ff3b3502fb8109420692dbae8151e32c3b1d68f0
|
|
4
|
+
data.tar.gz: 16dc1a6c62f143417432dd9aefd1be3c247ff0279e204da8dda0d73a436c6c65
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4574565cf96154a08f4bcc8918331715daf9364b455f8d34f1a38327239d278909f0af91a20be819c69fe63f7bbb461ffd2de4ea4bf057ed293acab850f1594a
|
|
7
|
+
data.tar.gz: aba7990821991e66322ba01fee2d955c3faa76e7564c3bd327b80381aec9827f8557137b1699a968633b5802e443e8249ab2b39041836b83e139df6bc6b9cf0f
|
data/Gemfile.lock
CHANGED
|
@@ -4,7 +4,6 @@ module Spree
|
|
|
4
4
|
preference :api_key, :string
|
|
5
5
|
preference :merchant_id, :string
|
|
6
6
|
preference :payment_option, :string # 'abapay', 'cards', 'abapay_deeplink'
|
|
7
|
-
preference :app_scheme, :text
|
|
8
7
|
preference :transaction_fee_fix, :string
|
|
9
8
|
preference :transaction_fee_percentage, :string
|
|
10
9
|
preference :public_key, :text
|
|
@@ -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
|
|
@@ -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 =
|
|
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,18 @@
|
|
|
1
|
+
<%
|
|
2
|
+
checkout = Vpago::Vattanac::Checkout.new(@payment)
|
|
3
|
+
result = checkout.create
|
|
4
|
+
%>
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
const platform = "<%= params[:platform] %>";
|
|
8
|
+
const mobileUrl = "<%= raw(result[:mobile_url]) %>";
|
|
9
|
+
const webUrl = "<%= raw(result[:web_url]) %>";
|
|
10
|
+
|
|
11
|
+
if (platform === "app" && mobileUrl) {
|
|
12
|
+
window.location.href = mobileUrl;
|
|
13
|
+
} else if (platform === "web" && webUrl) {
|
|
14
|
+
window.location.href = webUrl;
|
|
15
|
+
} else {
|
|
16
|
+
console.error("Failed to create payment link:", { mobileUrl, webUrl });
|
|
17
|
+
}
|
|
18
|
+
</script>
|
data/lib/spree_vpago/engine.rb
CHANGED
data/lib/spree_vpago/version.rb
CHANGED
data/lib/vpago/payway_v2/base.rb
CHANGED
|
@@ -105,15 +105,9 @@ module Vpago
|
|
|
105
105
|
# redirect to continue URL, let it handle redirecting to app.
|
|
106
106
|
# allowed override to specific app eg. from tg://t.me
|
|
107
107
|
def return_deeplink_url
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
uri = URI.parse(continue_success_url)
|
|
112
|
-
uri.scheme = app_scheme
|
|
113
|
-
uri.to_s
|
|
114
|
-
else
|
|
115
|
-
continue_success_url
|
|
116
|
-
end
|
|
108
|
+
return @options[:override_return_deeplink_url] if @options[:override_return_deeplink_url].present?
|
|
109
|
+
|
|
110
|
+
continue_success_url
|
|
117
111
|
end
|
|
118
112
|
|
|
119
113
|
def return_deeplink
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
|
|
75
|
+
raise "Access Token Error: #{response.status} - #{response.body}" unless response.success?
|
|
76
|
+
|
|
77
|
+
parse_json(response.body).dig('data', 'accessToken') || raise('Missing accessToken in response')
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def post(url, body)
|
|
81
|
+
|
|
82
|
+
response = Faraday.post(url, body.to_json, default_headers)
|
|
83
|
+
parse_json(response.body)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
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.
|
|
4
|
+
version: 2.1.4.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-11-
|
|
11
|
+
date: 2025-11-03 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:
|
|
439
|
+
version: 1.3.1
|
|
434
440
|
requirements:
|
|
435
441
|
- none
|
|
436
442
|
rubygems_version: 3.4.1
|