spree_vpago 2.0.8.pre.beta2 → 2.0.8
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 +5 -5
- data/app/controllers/spree/vpago_payments_controller.rb +0 -6
- data/app/helpers/vpago/admin/base_helper_decorator.rb +0 -1
- data/app/models/vpago/payment_decorator.rb +1 -2
- data/app/models/vpago/payment_method_decorator.rb +1 -7
- data/app/models/vpago/payouts_generator.rb +36 -4
- data/app/services/vpago/payment_finder.rb +3 -8
- data/app/services/vpago/payment_url_constructor.rb +1 -15
- data/app/services/vpago/rsa_handler.rb +1 -7
- data/lib/spree_vpago/engine.rb +1 -2
- data/lib/spree_vpago/version.rb +1 -1
- metadata +4 -11
- data/app/models/spree/gateway/true_money.rb +0 -91
- data/app/views/spree/admin/payments/source_views/_true_money.html.erb +0 -6
- data/app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb +0 -12
- data/lib/vpago/true_money/base.rb +0 -139
- data/lib/vpago/true_money/checkout.rb +0 -33
- data/lib/vpago/true_money/refund_issuer.rb +0 -21
- data/lib/vpago/true_money/transaction_status.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d952b332b1f3cebefb707805b281c0ae90755496444576599e89bf6fbd3ec8d
|
4
|
+
data.tar.gz: e02298610af4eb99263b22b9b0a0893444ad96d36bf6b97d79407f18098737bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d15586610e25f52a3311a9c7e181569c876b0a01a35908b5a53d35b70d69ba86f0bafccb4b1f2387ad79a3e97a55182a718b62cd266c884f49b88c3f379727c
|
7
|
+
data.tar.gz: e57f32d3047acd6bb245fcc727ba751493ac88360cbeb747cdab45d5559e2a9b5d54770237039a619a7e46c833c8753988591ad1cd5a861667b777754c72bda8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spree_vpago (2.0.8
|
4
|
+
spree_vpago (2.0.8)
|
5
5
|
faraday
|
6
6
|
google-cloud-firestore
|
7
7
|
spree_api (>= 4.5)
|
@@ -198,7 +198,7 @@ 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.0.
|
201
|
+
gapic-common (1.0.1)
|
202
202
|
faraday (>= 1.9, < 3.a)
|
203
203
|
faraday-retry (>= 1.0, < 3.a)
|
204
204
|
google-cloud-env (~> 2.2)
|
@@ -234,7 +234,7 @@ 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.
|
237
|
+
google-cloud-firestore-v1 (2.1.1)
|
238
238
|
gapic-common (~> 1.0)
|
239
239
|
google-cloud-errors (~> 1.0)
|
240
240
|
google-cloud-location (~> 1.0)
|
@@ -242,7 +242,7 @@ GEM
|
|
242
242
|
gapic-common (~> 1.0)
|
243
243
|
google-cloud-errors (~> 1.0)
|
244
244
|
google-logging-utils (0.2.0)
|
245
|
-
google-protobuf (4.31.1
|
245
|
+
google-protobuf (4.31.1)
|
246
246
|
bigdecimal
|
247
247
|
rake (>= 13)
|
248
248
|
googleapis-common-protos (1.8.0)
|
@@ -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.73.0
|
262
|
+
grpc (1.73.0)
|
263
263
|
google-protobuf (>= 3.25, < 5.0)
|
264
264
|
googleapis-common-protos-types (~> 1.0)
|
265
265
|
hashdiff (1.1.0)
|
@@ -33,12 +33,6 @@ module Spree
|
|
33
33
|
|
34
34
|
@order = @payment.order
|
35
35
|
raise CanCan::AccessDenied unless @order.completed?
|
36
|
-
|
37
|
-
if params[:offsite_payment].present?
|
38
|
-
redirect_to @payment.payment_url, allow_other_host: true
|
39
|
-
else
|
40
|
-
render :success
|
41
|
-
end
|
42
36
|
end
|
43
37
|
|
44
38
|
# POST
|
@@ -8,8 +8,6 @@ module Vpago
|
|
8
8
|
:processing_url,
|
9
9
|
:success_url,
|
10
10
|
:process_payment_url,
|
11
|
-
:processing_app_url,
|
12
|
-
:payment_url,
|
13
11
|
to: :url_constructor
|
14
12
|
end
|
15
13
|
|
@@ -61,6 +59,7 @@ module Vpago
|
|
61
59
|
def vattanac_mini_app_payment?
|
62
60
|
payment_method.type_vattanac_mini_app?
|
63
61
|
end
|
62
|
+
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -6,7 +6,6 @@ module Vpago
|
|
6
6
|
TYPE_ACLEDA = 'Spree::Gateway::Acleda'.freeze
|
7
7
|
TYPE_ACLEDA_MOBILE = 'Spree::Gateway::AcledaMobile'.freeze
|
8
8
|
TYPE_VATTANAC_MINI_APP = 'Spree::Gateway::VattanacMiniApp'.freeze
|
9
|
-
TYPE_TRUE_MONEY = 'Spree::Gateway::TrueMoney'.freeze
|
10
9
|
|
11
10
|
def self.prepended(base)
|
12
11
|
base.preference :icon_name, :string, default: 'cheque'
|
@@ -19,8 +18,7 @@ module Vpago
|
|
19
18
|
Spree::PaymentMethod::TYPE_WINGSDK,
|
20
19
|
Spree::PaymentMethod::TYPE_ACLEDA,
|
21
20
|
Spree::PaymentMethod::TYPE_ACLEDA_MOBILE,
|
22
|
-
Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
|
23
|
-
Spree::PaymentMethod::TYPE_TRUE_MONEY
|
21
|
+
Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
|
24
22
|
]
|
25
23
|
end
|
26
24
|
end
|
@@ -93,10 +91,6 @@ module Vpago
|
|
93
91
|
def type_vattanac_mini_app?
|
94
92
|
type == Spree::PaymentMethod::TYPE_VATTANAC_MINI_APP
|
95
93
|
end
|
96
|
-
|
97
|
-
def type_true_money?
|
98
|
-
type == Spree::PaymentMethod::TYPE_TRUE_MONEY
|
99
|
-
end
|
100
94
|
end
|
101
95
|
end
|
102
96
|
|
@@ -30,7 +30,15 @@ module Vpago
|
|
30
30
|
return [] if payouts.all?(&:default?)
|
31
31
|
return [] unless payouts.all? { |payout| validated?(payout) }
|
32
32
|
|
33
|
-
ActiveRecord::Base.transaction
|
33
|
+
ActiveRecord::Base.transaction do
|
34
|
+
payouts.each(&:save!)
|
35
|
+
|
36
|
+
# If any payouts were rounded, the total may increase slightly.
|
37
|
+
# Update the payment amount to match the sum of payouts to avoid mismatch errors.
|
38
|
+
payment.update(amount: payouts.map(&:amount).sum)
|
39
|
+
|
40
|
+
payouts
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
44
|
def validated?(payout)
|
@@ -47,7 +55,7 @@ module Vpago
|
|
47
55
|
total_confirmed_payouts = line_item.confirmed_payouts_for_vendor.sum(:amount)
|
48
56
|
next if total_confirmed_payouts >= line_item.pre_commission_amount
|
49
57
|
|
50
|
-
amount_owed_to_vendor = line_item.pre_commission_amount - total_confirmed_payouts
|
58
|
+
amount_owed_to_vendor = round_up(line_item.pre_commission_amount - total_confirmed_payouts)
|
51
59
|
payout_amount = [amount_owed_to_vendor, remaining_amount].min
|
52
60
|
outstanding_amount = [amount_owed_to_vendor - payout_amount, 0].max
|
53
61
|
|
@@ -80,7 +88,7 @@ module Vpago
|
|
80
88
|
total_confirmed_payouts = shipment.confirmed_payouts_for_vendor.sum(:amount)
|
81
89
|
next if total_confirmed_payouts >= shipment.cost_with_vendor_adjustment_total
|
82
90
|
|
83
|
-
amount_owed_to_shipping_vendor = shipment.cost_with_vendor_adjustment_total - total_confirmed_payouts
|
91
|
+
amount_owed_to_shipping_vendor = round_up(shipment.cost_with_vendor_adjustment_total - total_confirmed_payouts)
|
84
92
|
payout_amount = [amount_owed_to_shipping_vendor, remaining_amount].min
|
85
93
|
outstanding_amount = [amount_owed_to_shipping_vendor - payout_amount, 0].max
|
86
94
|
|
@@ -117,9 +125,33 @@ module Vpago
|
|
117
125
|
state: :created,
|
118
126
|
payment: payment,
|
119
127
|
payout_profile: Spree::PayoutProfiles::PaywayV2.default,
|
120
|
-
amount: self.remaining_amount
|
128
|
+
amount: round_up(self.remaining_amount)
|
121
129
|
)
|
122
130
|
]
|
123
131
|
end
|
132
|
+
|
133
|
+
# ABA does not support amounts with more than 2 decimal places.
|
134
|
+
# Therefore, we must round all 3-decimal payouts to 2 decimals beforehand.
|
135
|
+
#
|
136
|
+
# Our rounding strategy:
|
137
|
+
# - We round up for vendors & shipment payouts (to favor external parties).
|
138
|
+
# - The remaining amount is adjusted in the platform's share (may be slightly less).
|
139
|
+
#
|
140
|
+
# Example:
|
141
|
+
# Total amount: $5.00
|
142
|
+
#
|
143
|
+
# Vendor payouts:
|
144
|
+
# - Vendor 1: $0.625 → $0.63
|
145
|
+
# - Vendor 2: $0.625 → $0.63
|
146
|
+
#
|
147
|
+
# Shipment payouts:
|
148
|
+
# - Shipment 1: $0.625 → $0.63
|
149
|
+
# - Shipment 2: $0.625 → $0.63
|
150
|
+
#
|
151
|
+
# Platform payout:
|
152
|
+
# - $2.50 → $2.48 (adjusted to ensure total remains $5.00)
|
153
|
+
def round_up(amount)
|
154
|
+
(amount * 100).ceil / 100.0
|
155
|
+
end
|
124
156
|
end
|
125
157
|
end
|
@@ -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
|
-
|
@@ -14,22 +14,8 @@ module Vpago
|
|
14
14
|
def success_url = "#{base_url}/vpago_payments/success?#{query}"
|
15
15
|
def process_payment_url = "#{base_url}/vpago_payments/process_payment?#{query}"
|
16
16
|
|
17
|
-
def processing_app_url = "#{@payment.payment_method.preferred_merchant_scheme}/vpago_payments/processing?#{query}"
|
18
|
-
|
19
17
|
def query
|
20
|
-
|
21
|
-
payment_number: payment.number,
|
22
|
-
order_number: order.number,
|
23
|
-
order_jwt_token: order_jwt_token
|
24
|
-
}
|
25
|
-
|
26
|
-
params[:offsite_payment] = true if payment.payment_method.type_true_money?
|
27
|
-
|
28
|
-
params.to_query
|
29
|
-
end
|
30
|
-
|
31
|
-
def payment_url
|
32
|
-
"#{base_url}/book/payment?number=#{@payment.order.number}&tk=#{@payment.order.token}"
|
18
|
+
{ payment_number: payment.number, order_number: order.number, order_jwt_token: order_jwt_token }.to_query
|
33
19
|
end
|
34
20
|
|
35
21
|
private
|
@@ -23,11 +23,5 @@ module Vpago
|
|
23
23
|
signature_bytes = Base64.decode64(signature)
|
24
24
|
public_key_object.verify(OpenSSL::Digest.new('SHA256'), signature_bytes, data)
|
25
25
|
end
|
26
|
-
|
27
|
-
def generate_signature(payload)
|
28
|
-
sign_hash = OpenSSL::Digest.new('SHA256')
|
29
|
-
private_key = OpenSSL::PKey::RSA.new(@private_key)
|
30
|
-
Base64.strict_encode64(private_key.sign(sign_hash, payload))
|
31
|
-
end
|
32
26
|
end
|
33
|
-
end
|
27
|
+
end
|
data/lib/spree_vpago/engine.rb
CHANGED
data/lib/spree_vpago/version.rb
CHANGED
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.0.8
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- You
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -179,7 +179,6 @@ files:
|
|
179
179
|
- app/models/spree/gateway/acleda_mobile.rb
|
180
180
|
- app/models/spree/gateway/payway.rb
|
181
181
|
- app/models/spree/gateway/payway_v2.rb
|
182
|
-
- app/models/spree/gateway/true_money.rb
|
183
182
|
- app/models/spree/gateway/vattanac_mini_app.rb
|
184
183
|
- app/models/spree/gateway/wing_sdk.rb
|
185
184
|
- app/models/spree/payout.rb
|
@@ -263,7 +262,6 @@ files:
|
|
263
262
|
- app/views/spree/admin/payments/source_views/_acleda_mobile.html.erb
|
264
263
|
- app/views/spree/admin/payments/source_views/_payment_payway.html.erb
|
265
264
|
- app/views/spree/admin/payments/source_views/_payway_v2.html.erb
|
266
|
-
- app/views/spree/admin/payments/source_views/_true_money.html.erb
|
267
265
|
- app/views/spree/admin/payments/source_views/_vattanac_mini_app.html.erb
|
268
266
|
- app/views/spree/admin/payments/source_views/_vpago_payment_tmpl.html.erb
|
269
267
|
- app/views/spree/admin/payments/source_views/_wingsdk.html.erb
|
@@ -311,7 +309,6 @@ files:
|
|
311
309
|
- app/views/spree/payway_v2_card_popups/show.html.erb
|
312
310
|
- app/views/spree/vpago_payments/checkout.html.erb
|
313
311
|
- app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb
|
314
|
-
- app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb
|
315
312
|
- app/views/spree/vpago_payments/forms/spree/gateway/_vattanac_mini_app.html.erb
|
316
313
|
- app/views/spree/vpago_payments/processing.html.erb
|
317
314
|
- app/views/spree/vpago_payments/success.html.erb
|
@@ -381,10 +378,6 @@ files:
|
|
381
378
|
- lib/vpago/payway_v2/pre_auth_canceler.rb
|
382
379
|
- lib/vpago/payway_v2/pre_auth_completer.rb
|
383
380
|
- lib/vpago/payway_v2/transaction_status.rb
|
384
|
-
- lib/vpago/true_money/base.rb
|
385
|
-
- lib/vpago/true_money/checkout.rb
|
386
|
-
- lib/vpago/true_money/refund_issuer.rb
|
387
|
-
- lib/vpago/true_money/transaction_status.rb
|
388
381
|
- lib/vpago/vattanac_mini_app/base.rb
|
389
382
|
- lib/vpago/vattanac_mini_app/checkout.rb
|
390
383
|
- lib/vpago/vattanac_mini_app/refund_issuer.rb
|
@@ -415,9 +408,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
415
408
|
version: 3.2.0
|
416
409
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
417
410
|
requirements:
|
418
|
-
- - "
|
411
|
+
- - ">="
|
419
412
|
- !ruby/object:Gem::Version
|
420
|
-
version:
|
413
|
+
version: '0'
|
421
414
|
requirements:
|
422
415
|
- none
|
423
416
|
rubygems_version: 3.4.1
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
class Gateway::TrueMoney < PaymentMethod
|
3
|
-
preference :check_transaction_url, :string
|
4
|
-
preference :refund_url, :string
|
5
|
-
preference :generate_payment_url, :string
|
6
|
-
preference :access_token_url, :string
|
7
|
-
|
8
|
-
preference :client_id, :string
|
9
|
-
preference :client_secret, :string
|
10
|
-
preference :private_key, :text
|
11
|
-
preference :merchant_scheme, :string
|
12
|
-
preference :merchant_android_package_name, :string
|
13
|
-
preference :redirection_type, :string
|
14
|
-
|
15
|
-
def method_type
|
16
|
-
'true_money'
|
17
|
-
end
|
18
|
-
|
19
|
-
def payment_source_class
|
20
|
-
Spree::VpagoPaymentSource
|
21
|
-
end
|
22
|
-
|
23
|
-
# force to purchase instead of authorize
|
24
|
-
def auto_capture?
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
# override
|
29
|
-
# purchase is used when pre auth disabled
|
30
|
-
def purchase(_amount, _source, gateway_options = {})
|
31
|
-
_, payment_number = gateway_options[:order_id].split('-')
|
32
|
-
payment = Spree::Payment.find_by(number: payment_number)
|
33
|
-
|
34
|
-
checker = check_transaction(payment)
|
35
|
-
payment.update(transaction_response: checker.json_response)
|
36
|
-
|
37
|
-
success = checker.success?
|
38
|
-
params = {}
|
39
|
-
|
40
|
-
params[:payment_response] = payment.transaction_response
|
41
|
-
|
42
|
-
if success
|
43
|
-
ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Purchased', params)
|
44
|
-
else
|
45
|
-
ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Purchasing Failed', params)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# override
|
50
|
-
def void(_response_code, gateway_options)
|
51
|
-
_, payment_number = gateway_options[:order_id].split('-')
|
52
|
-
payment = Spree::Payment.find_by(number: payment_number)
|
53
|
-
|
54
|
-
if payment.true_money_payment?
|
55
|
-
params = {}
|
56
|
-
success, params[:refund_response] = true_money_refund(payment)
|
57
|
-
|
58
|
-
if success
|
59
|
-
ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: successfully canceled.', params)
|
60
|
-
else
|
61
|
-
ActiveMerchant::Billing::Response.new(false, 'Payway Gateway: Failed to canceleed', params)
|
62
|
-
end
|
63
|
-
else
|
64
|
-
ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been voided.')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def true_money_refund(payment)
|
69
|
-
refund_issuer = Vpago::TrueMoney::RefundIssuer.new(payment, {})
|
70
|
-
refund_issuer.call
|
71
|
-
|
72
|
-
[refund_issuer.success?, refund_issuer.response]
|
73
|
-
end
|
74
|
-
|
75
|
-
def cancel(_response_code, _payment)
|
76
|
-
# we can use this to send request to payment gateway api to cancel the payment ( void )
|
77
|
-
# currently Payway does not support to cancel the gateway
|
78
|
-
|
79
|
-
# in our case don't do anything
|
80
|
-
ActiveMerchant::Billing::Response.new(true, '')
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def check_transaction(payment)
|
86
|
-
checker = Vpago::TrueMoney::TransactionStatus.new(payment)
|
87
|
-
checker.call
|
88
|
-
checker
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<% @checkout = ::Vpago::TrueMoney::Checkout.new(@payment) %>
|
2
|
-
<% webview_url = @checkout.generate_payment_urls[:webview] rescue nil %>
|
3
|
-
|
4
|
-
<% if webview_url.present? %>
|
5
|
-
<script>
|
6
|
-
document.addEventListener("DOMContentLoaded", function () {
|
7
|
-
window.top.location.href = "<%= j webview_url %>";
|
8
|
-
});
|
9
|
-
</script>
|
10
|
-
<% else %>
|
11
|
-
<p>Unable to generate the payment URL. Please try again.</p>
|
12
|
-
<% end %>
|
@@ -1,139 +0,0 @@
|
|
1
|
-
module Vpago
|
2
|
-
module TrueMoney
|
3
|
-
class Base
|
4
|
-
TOKEN_HEADERS = { 'Content-Type' => 'application/x-www-form-urlencoded' }.freeze
|
5
|
-
CONTENT_TYPE_JSON = 'application/json'.freeze
|
6
|
-
DEFAULT_ALGORITHM = 'rsa-sha256'.freeze
|
7
|
-
DEFAULT_KEY_VERSION = 1
|
8
|
-
|
9
|
-
def initialize(payment, options = {})
|
10
|
-
@payment = payment
|
11
|
-
@options = options
|
12
|
-
end
|
13
|
-
|
14
|
-
def client_id
|
15
|
-
payment_method.preferred_client_id
|
16
|
-
end
|
17
|
-
|
18
|
-
def client_secret
|
19
|
-
payment_method.preferred_client_secret
|
20
|
-
end
|
21
|
-
|
22
|
-
def private_key
|
23
|
-
payment_method.preferred_private_key
|
24
|
-
end
|
25
|
-
|
26
|
-
def external_ref_id
|
27
|
-
@payment.number
|
28
|
-
end
|
29
|
-
|
30
|
-
def service_type = '01'
|
31
|
-
def currency = 'USD'
|
32
|
-
def user_type = 'CUSTOMER'
|
33
|
-
|
34
|
-
def amount
|
35
|
-
@payment.amount
|
36
|
-
end
|
37
|
-
|
38
|
-
def timestamp
|
39
|
-
@timestamp ||= Time.now.to_i
|
40
|
-
end
|
41
|
-
|
42
|
-
def access_token
|
43
|
-
@access_token ||= fetch_access_token
|
44
|
-
end
|
45
|
-
|
46
|
-
def payload
|
47
|
-
{
|
48
|
-
service_type: service_type,
|
49
|
-
external_ref_id: external_ref_id,
|
50
|
-
amount: amount,
|
51
|
-
currency: currency,
|
52
|
-
user_type: user_type
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def signature
|
57
|
-
Vpago::RsaHandler
|
58
|
-
.new(private_key: private_key)
|
59
|
-
.generate_signature(signature_input)
|
60
|
-
end
|
61
|
-
|
62
|
-
def default_headers
|
63
|
-
{
|
64
|
-
'Client-Id' => client_id,
|
65
|
-
'Authorization' => "Bearer #{access_token}",
|
66
|
-
'Signature' => "algorithm=#{algorithm};keyVersion=#{key_version};signature=#{signature}",
|
67
|
-
'Timestamp' => timestamp.to_s,
|
68
|
-
'Content-Type' => CONTENT_TYPE_JSON
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
def redirection_type
|
73
|
-
payment_method.preferred_redirection_type
|
74
|
-
end
|
75
|
-
|
76
|
-
def check_transaction_url
|
77
|
-
"#{payment_method.preferred_check_transaction_url}/#{external_ref_id}"
|
78
|
-
end
|
79
|
-
|
80
|
-
def refund_url
|
81
|
-
payment_method.preferred_refund_url
|
82
|
-
end
|
83
|
-
|
84
|
-
def generate_payment_url
|
85
|
-
payment_method.preferred_generate_payment_url
|
86
|
-
end
|
87
|
-
|
88
|
-
def access_token_url
|
89
|
-
payment_method.preferred_access_token_url
|
90
|
-
end
|
91
|
-
|
92
|
-
def merchant_android_package_name
|
93
|
-
payment_method.preferred_merchant_android_package_name
|
94
|
-
end
|
95
|
-
|
96
|
-
def parse_json(body)
|
97
|
-
JSON.parse(body)
|
98
|
-
rescue JSON::ParserError
|
99
|
-
{}
|
100
|
-
end
|
101
|
-
|
102
|
-
def payment_method
|
103
|
-
@payment.payment_method
|
104
|
-
end
|
105
|
-
|
106
|
-
def fetch_access_token
|
107
|
-
response = Faraday.post(
|
108
|
-
access_token_url,
|
109
|
-
URI.encode_www_form(
|
110
|
-
grant_type: 'client_credentials',
|
111
|
-
client_id: client_id,
|
112
|
-
client_secret: client_secret
|
113
|
-
),
|
114
|
-
TOKEN_HEADERS
|
115
|
-
)
|
116
|
-
|
117
|
-
raise "Access Token Error: #{response.status} - #{response.body}" unless response.success?
|
118
|
-
|
119
|
-
JSON.parse(response.body).fetch('access_token')
|
120
|
-
end
|
121
|
-
|
122
|
-
def algorithm
|
123
|
-
DEFAULT_ALGORITHM
|
124
|
-
end
|
125
|
-
|
126
|
-
def key_version
|
127
|
-
DEFAULT_KEY_VERSION
|
128
|
-
end
|
129
|
-
|
130
|
-
def signature_input
|
131
|
-
"#{timestamp}#{payload.to_json}"
|
132
|
-
end
|
133
|
-
|
134
|
-
def processing_url
|
135
|
-
"#{@payment.processing_url}&offsite_payment=true"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Vpago
|
2
|
-
module TrueMoney
|
3
|
-
class Checkout < Base
|
4
|
-
def generate_payment_urls
|
5
|
-
request_body = {
|
6
|
-
payment_info: payload.to_json,
|
7
|
-
redirectionType: redirection_type
|
8
|
-
}
|
9
|
-
|
10
|
-
if redirection_type == 'mobileapp'
|
11
|
-
request_body[:merchantDeepLink] = @payment.processing_app_url
|
12
|
-
request_body[:merchantAndroidPackageName] = merchant_android_package_name
|
13
|
-
else
|
14
|
-
request_body[:refererLink] = @payment.processing_url
|
15
|
-
end
|
16
|
-
|
17
|
-
response = Faraday.post(generate_payment_url) do |req|
|
18
|
-
req.headers = default_headers
|
19
|
-
req.body = request_body.to_json
|
20
|
-
end
|
21
|
-
|
22
|
-
body = parse_json(response.body)
|
23
|
-
|
24
|
-
raise "Generate Payment Error: #{response.status} - #{body['message'] || response.body}" unless response.success? && body.dig('status', 'code') == '000001'
|
25
|
-
|
26
|
-
{
|
27
|
-
webview: body['data']['webview'],
|
28
|
-
deeplink: body['data']['deeplink']
|
29
|
-
}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Vpago
|
2
|
-
module TrueMoney
|
3
|
-
class RefundIssuer < Base
|
4
|
-
def call
|
5
|
-
@response = Faraday.post(refund_url, payload.to_json, default_headers)
|
6
|
-
end
|
7
|
-
|
8
|
-
def success?
|
9
|
-
parsed_response.dig('status', 'code') == '000001'
|
10
|
-
end
|
11
|
-
|
12
|
-
def payload
|
13
|
-
{ external_ref_id: external_ref_id }
|
14
|
-
end
|
15
|
-
|
16
|
-
def parsed_response
|
17
|
-
@parsed_response ||= parse_json(@response.body)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Vpago
|
2
|
-
module TrueMoney
|
3
|
-
class TransactionStatus < Base
|
4
|
-
def call
|
5
|
-
@response = Faraday.get(check_transaction_url, nil, default_headers)
|
6
|
-
end
|
7
|
-
|
8
|
-
def success?
|
9
|
-
response_code == '000001'
|
10
|
-
end
|
11
|
-
|
12
|
-
def response_code
|
13
|
-
json_response.dig('status', 'code')
|
14
|
-
end
|
15
|
-
|
16
|
-
def signature_input
|
17
|
-
timestamp.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
def json_response
|
21
|
-
@json_response ||= parse_json(@response.body)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|