spree_vpago 2.3.12 → 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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/app/assets/config/spree_vpago_manifest.js +1 -0
- data/app/assets/javascripts/vpago/vpago_payments/create_transaction.js +35 -0
- data/app/controllers/spree/vpago_payments_controller.rb +21 -0
- data/app/models/spree/gateway/payway_v2.rb +6 -0
- data/app/models/spree/gateway/true_money.rb +4 -0
- data/app/models/vpago/payment_decorator.rb +1 -0
- data/app/models/vpago/payment_method_decorator.rb +6 -0
- data/app/services/vpago/payment_url_constructor.rb +1 -0
- data/app/views/layouts/vpago_payments.html.erb +1 -0
- data/app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb +35 -42
- data/app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb +15 -15
- data/config/routes.rb +1 -0
- data/lib/spree_vpago/version.rb +1 -1
- data/lib/vpago/payway_v2/transaction_creator.rb +29 -0
- data/spree_vpago.gemspec +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a704b3b4c6172fcfac73d2b395be971f8706c137260c6d122e530160260f276
|
|
4
|
+
data.tar.gz: fc86b46f2cde8a9de6426b413196cc707b32dc141c78d756d17ae9de654893f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 229e3073db012f2f0a1ab6a9b47ea893eaf751b0d3937211490743d81a41800024e2263dd07269fdfdc3549449288bf13263df0737bf6a4dcda2a4a768acae53
|
|
7
|
+
data.tar.gz: a8ea4e06485c9bd95d6f6616379c6c8dee5e8b6090dddb1a30446ec16ea0697984db1480a027ad7150b68e801bf295c50e13998fcc8232eddeb2fe9e32605920
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
spree_vpago (2.3.
|
|
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
|
|
@@ -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;
|
|
@@ -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)
|
|
@@ -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 = {})
|
|
@@ -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>
|
|
@@ -43,55 +43,48 @@
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function submitFormViaJs(){
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
60
|
+
let deeplinkTriggered = false;
|
|
69
61
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
if (data.abapay_deeplink && shouldOpenAbaPayDeeplink) {
|
|
63
|
+
window.location.href = data.abapay_deeplink;
|
|
64
|
+
deeplinkTriggered = true;
|
|
65
|
+
}
|
|
74
66
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
window.location.href = data.checkout_qr_url;
|
|
77
|
+
}
|
|
85
78
|
}
|
|
86
|
-
}
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
<% @checkout = ::Vpago::TrueMoney::Checkout.new(@payment) %>
|
|
2
|
-
<% redirect_urls = @checkout.generate_payment_urls(params[:platform]) %>
|
|
3
|
-
|
|
4
1
|
<script>
|
|
5
2
|
function showRedirectContainer(buttonLabel, onClick) {
|
|
6
3
|
const loadingContainer = document.getElementById('vpago_loading_container');
|
|
@@ -16,19 +13,22 @@
|
|
|
16
13
|
|
|
17
14
|
document.addEventListener("DOMContentLoaded", () => {
|
|
18
15
|
const platform = "<%= params[:platform] %>";
|
|
19
|
-
const redirectUrls = <%= redirect_urls.to_json.html_safe %>;
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
window.location.href = redirectUrls.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
window.createTransaction({
|
|
18
|
+
url: "<%= raw @payment.create_transaction_url %>&platform=<%= params[:platform] %>",
|
|
19
|
+
onSuccess: function(redirectUrls) {
|
|
20
|
+
if (platform === "app") {
|
|
21
|
+
window.location.href = redirectUrls.deeplink;
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
window.location.href = redirectUrls.webview;
|
|
24
|
+
}, 1500);
|
|
25
|
+
} else {
|
|
26
|
+
window.open(redirectUrls.webview, '_blank');
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
onError: function() {
|
|
30
|
+
document.getElementById('vpago_loading_container').textContent = "We couldn't start your payment. Please go back and try again.";
|
|
29
31
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
setupConfirmPaymentButton();
|
|
32
|
+
});
|
|
33
33
|
});
|
|
34
34
|
</script>
|
data/config/routes.rb
CHANGED
data/lib/spree_vpago/version.rb
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
|
|
3
|
+
module Vpago
|
|
4
|
+
module PaywayV2
|
|
5
|
+
class TransactionCreator < Checkout
|
|
6
|
+
def call
|
|
7
|
+
@response = submit_transaction
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def json_response
|
|
11
|
+
@json_response ||= JSON.parse(@response.body)
|
|
12
|
+
rescue JSON::ParserError
|
|
13
|
+
{}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def submit_transaction
|
|
19
|
+
conn = Faraday::Connection.new do |faraday|
|
|
20
|
+
faraday.request :url_encoded
|
|
21
|
+
faraday.options.open_timeout = Vpago::HttpTimeouts::OPEN_TIMEOUT
|
|
22
|
+
faraday.options.timeout = Vpago::HttpTimeouts::TIMEOUT
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
conn.post(checkout_url, gateway_params)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/spree_vpago.gemspec
CHANGED
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.add_dependency 'spree_api', spree_version
|
|
27
27
|
s.add_dependency 'spree_backend', spree_version
|
|
28
28
|
s.add_dependency 'spree_core', spree_version
|
|
29
|
-
s.add_dependency 'spree_extension'
|
|
29
|
+
s.add_dependency 'spree_extension', '< 1.0'
|
|
30
30
|
s.add_dependency 'spree_multi_vendor', '>= 2.4.1'
|
|
31
31
|
|
|
32
32
|
s.metadata['rubygems_mfa_required'] = 'true'
|
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.
|
|
4
|
+
version: 2.3.13.pre.pre1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- You
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-09-
|
|
11
|
+
date: 2026-09-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -84,16 +84,16 @@ dependencies:
|
|
|
84
84
|
name: spree_extension
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - "<"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
89
|
+
version: '1.0'
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - "<"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
96
|
+
version: '1.0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: spree_multi_vendor
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -147,6 +147,7 @@ files:
|
|
|
147
147
|
- app/assets/images/vpago/payway/abapay.png
|
|
148
148
|
- app/assets/images/vpago/payway/cards.png
|
|
149
149
|
- app/assets/javascripts/vpago/vpago_payments/check_transaction_periodically.js
|
|
150
|
+
- app/assets/javascripts/vpago/vpago_payments/create_transaction.js
|
|
150
151
|
- app/assets/javascripts/vpago/vpago_payments/request_process_payment.js
|
|
151
152
|
- app/assets/javascripts/vpago/vpago_payments/user_informers/firebase.js
|
|
152
153
|
- app/controllers/.gitkeep
|
|
@@ -424,6 +425,7 @@ files:
|
|
|
424
425
|
- lib/vpago/payway_v2/payouts_params_constructor.rb
|
|
425
426
|
- lib/vpago/payway_v2/pre_auth_canceler.rb
|
|
426
427
|
- lib/vpago/payway_v2/pre_auth_completer.rb
|
|
428
|
+
- lib/vpago/payway_v2/transaction_creator.rb
|
|
427
429
|
- lib/vpago/payway_v2/transaction_status.rb
|
|
428
430
|
- lib/vpago/payway_v2/transaction_status_v2.rb
|
|
429
431
|
- lib/vpago/true_money/base.rb
|
|
@@ -465,9 +467,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
465
467
|
version: 3.2.0
|
|
466
468
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
467
469
|
requirements:
|
|
468
|
-
- - "
|
|
470
|
+
- - ">"
|
|
469
471
|
- !ruby/object:Gem::Version
|
|
470
|
-
version:
|
|
472
|
+
version: 1.3.1
|
|
471
473
|
requirements:
|
|
472
474
|
- none
|
|
473
475
|
rubygems_version: 3.4.1
|