spree_vpago 2.2.2.pre.pre17 → 2.2.2.pre.pre18
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/controllers/spree/vpago_payments_controller.rb +16 -0
- data/app/helpers/vpago/vpago_payments_helper.rb +4 -2
- data/app/models/spree/gateway/payway_v2.rb +14 -2
- data/app/models/vpago/payment_decorator.rb +1 -0
- data/app/models/vpago/payment_method_decorator.rb +7 -0
- data/app/services/vpago/payment_url_constructor.rb +1 -0
- data/app/views/spree/vpago_payments/_payment_status_listener.html.erb +32 -27
- data/app/views/spree/vpago_payments/checkout.html.erb +1 -1
- data/config/routes.rb +1 -0
- data/lib/spree_vpago/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df57ee8f0d9491a0059e01819c47fd3620f9f9f0602f82c7e9ae4bd4f05fe01c
|
|
4
|
+
data.tar.gz: 90e49af5baece5e10f5f03f20d99f428e34c1ea50922992957a7f181da3d2e51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f642f68de641579f20895fa58497b1e6f65852a145aed4d32af5e62bf3dd376867cb71adc7545f3778e273e90610d0d66e201c4192cff713b81dff842986a82
|
|
7
|
+
data.tar.gz: 7047fb3b5e701621ef108c321c78e46ed8b5e9570b1af3879a6dd8e952e7679483a33640c994d1b19e52db61fc18e48e81150ec9a3f3cf32d64ae41b62a73403
|
data/Gemfile.lock
CHANGED
|
@@ -18,6 +18,22 @@ module Spree
|
|
|
18
18
|
@order = @payment.order
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# GET
|
|
22
|
+
def check_transaction
|
|
23
|
+
@payment = Vpago::PaymentFinder.new(params.permit!.to_h).find_and_verify
|
|
24
|
+
raise ActiveRecord::RecordNotFound unless @payment.present?
|
|
25
|
+
|
|
26
|
+
checker = @payment.payment_method.check_transaction(@payment)
|
|
27
|
+
|
|
28
|
+
if checker.success?
|
|
29
|
+
render json: { status: :success }, status: :ok
|
|
30
|
+
elsif checker.failed?
|
|
31
|
+
render json: { status: :failed }, status: :payment_required
|
|
32
|
+
else
|
|
33
|
+
render json: { status: :pending }, status: :accepted
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
21
37
|
# GET
|
|
22
38
|
def processing
|
|
23
39
|
@payment = Vpago::PaymentFinder.new(params.permit!.to_h).find_and_verify
|
|
@@ -9,8 +9,10 @@ module Vpago
|
|
|
9
9
|
render partial: "spree/vpago_payments/forms/#{@payment.payment_method.class.to_s.underscore}"
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def
|
|
13
|
-
|
|
12
|
+
def render_transaction_checker
|
|
13
|
+
if @payment.payment_method.support_check_transaction_api?
|
|
14
|
+
render partial: 'spree/vpago_payments/transaction_checker'
|
|
15
|
+
end
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
# when return nil, each payment method should use their default URL.
|
|
@@ -33,6 +33,11 @@ module Spree
|
|
|
33
33
|
preferred_abapay_khqr_deeplink_option.in?(%w[open_both open_checkout_url_only])
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# override
|
|
37
|
+
def support_check_transaction_api?
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
36
41
|
# override
|
|
37
42
|
def default_payout_profile
|
|
38
43
|
Spree::PayoutProfiles::PaywayV2.default
|
|
@@ -67,6 +72,12 @@ module Spree
|
|
|
67
72
|
!enable_pre_auth?
|
|
68
73
|
end
|
|
69
74
|
|
|
75
|
+
# override
|
|
76
|
+
def check_status(payment)
|
|
77
|
+
checker = check_transaction(payment)
|
|
78
|
+
checker.success?
|
|
79
|
+
end
|
|
80
|
+
|
|
70
81
|
# override
|
|
71
82
|
# authorize is used when pre auth enabled
|
|
72
83
|
def authorize(_amount, _source, gateway_options = {})
|
|
@@ -148,14 +159,15 @@ module Spree
|
|
|
148
159
|
ActiveMerchant::Billing::Response.new(true, 'Payway Gateway: Payment has been canceled.')
|
|
149
160
|
end
|
|
150
161
|
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
# override
|
|
153
163
|
def check_transaction(payment)
|
|
154
164
|
checker = Vpago::PaywayV2::TransactionStatus.new(payment)
|
|
155
165
|
checker.call
|
|
156
166
|
checker
|
|
157
167
|
end
|
|
158
168
|
|
|
169
|
+
private
|
|
170
|
+
|
|
159
171
|
def cancel_pre_auth(payment)
|
|
160
172
|
canceler = Vpago::PaywayV2::PreAuthCanceler.new(payment)
|
|
161
173
|
canceler.call
|
|
@@ -35,6 +35,13 @@ module Vpago
|
|
|
35
35
|
def support_payout? = false
|
|
36
36
|
def support_pre_auth? = false
|
|
37
37
|
|
|
38
|
+
# Must be explicitly overridden to true by each payment method.
|
|
39
|
+
# Payment method must implement check_transaction(payment), and its response
|
|
40
|
+
# must provide: success?, failed?, pending?.
|
|
41
|
+
def support_check_transaction_api?
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
|
|
38
45
|
# TODO: we have already implement purchase for payway_v2.
|
|
39
46
|
# make sure to implement this on other payment method as well.
|
|
40
47
|
def purchase(_amount, _source, _gateway_options = {})
|
|
@@ -12,6 +12,7 @@ module Vpago
|
|
|
12
12
|
def checkout_url = "#{base_url}/vpago_payments/checkout?#{query}&platform=app"
|
|
13
13
|
def web_checkout_url = "#{base_url}/vpago_payments/checkout?#{query}&platform=web"
|
|
14
14
|
|
|
15
|
+
def check_transaction_url = "#{base_url}/vpago_payments/check_transaction?#{query}"
|
|
15
16
|
def processing_url = "#{base_url}/vpago_payments/processing?#{query}"
|
|
16
17
|
|
|
17
18
|
def success_url = "#{base_url}/vpago_payments/success?#{query}"
|
|
@@ -1,35 +1,40 @@
|
|
|
1
|
-
<%# This partial listens to payment status changes and does not process the payment. %>
|
|
1
|
+
<%# This partial listens to payment status changes from bank and does not process the payment. %>
|
|
2
2
|
<%# When it detects a status change, it automatically redirects to the processing URL for actual processing. %>
|
|
3
3
|
<%# Designed to be used in checkout.html.erb %>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
6
|
document.addEventListener("DOMContentLoaded", function() {
|
|
7
|
-
|
|
7
|
+
var checkTransactionUrl = "<%= j @payment.check_transaction_url %>";
|
|
8
|
+
var processingUrl = "<%= j @payment.processing_url %>";
|
|
9
|
+
var pollIntervalMs = 5000;
|
|
10
|
+
var hasRedirected = false;
|
|
11
|
+
var intervalId;
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
var pollStatus = function() {
|
|
14
|
+
if (hasRedirected) return;
|
|
15
|
+
|
|
16
|
+
fetch(checkTransactionUrl, {
|
|
17
|
+
method: "GET",
|
|
18
|
+
headers: { "Accept": "application/json" },
|
|
19
|
+
credentials: "same-origin"
|
|
20
|
+
})
|
|
21
|
+
.then(function(response) {
|
|
22
|
+
return response.json().then(function(body) {
|
|
23
|
+
return { ok: response.ok, body: body };
|
|
24
|
+
});
|
|
25
|
+
})
|
|
26
|
+
.then(function(result) {
|
|
27
|
+
var status = result.body && result.body.status ? String(result.body.status) : "pending";
|
|
28
|
+
|
|
29
|
+
if (status === "success" || status === "failed") {
|
|
30
|
+
hasRedirected = true;
|
|
31
|
+
if (intervalId) clearInterval(intervalId);
|
|
32
|
+
window.location.replace(processingUrl);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch(function() {});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
intervalId = window.setInterval(pollStatus, pollIntervalMs);
|
|
34
39
|
});
|
|
35
40
|
</script>
|
data/config/routes.rb
CHANGED
data/lib/spree_vpago/version.rb
CHANGED