spree_vpago 2.2.2.pre.pre9 → 2.2.2.pre.pre11
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 +3 -5
- data/app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb +76 -58
- data/app/views/spree/vpago_payments/forms/spree/gateway/_vattanac.html.erb +25 -43
- data/lib/spree_vpago/version.rb +1 -1
- data/lib/vpago/payway_v2/base.rb +25 -2
- 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: 89703ddc763dbab601246e10a41a1dd0bb4ca443ad6fd1f763fa1d4f120f74b5
|
|
4
|
+
data.tar.gz: 97e93bf3bcd95e7538b9472a96c86dc7cb6bad11165b100f698781ff53ec6d06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 49a3f98690cff2d62d2168b4f08c1a15dcd44f318b8c83a69e658d1900068145ac564c076cd8d6aab8a73f6f84bb4a3d962e276492d03ecd99e5eff61b6ff738
|
|
7
|
+
data.tar.gz: 8050e93e978e43a0134d6e79d1d760aad60baf493032a514b72b2904466e9b76470a2a0a0279bcf6b894eaa5e36594a539c84ccf52c4f4457c57068358e4a784
|
data/Gemfile.lock
CHANGED
|
@@ -88,12 +88,10 @@ module Spree
|
|
|
88
88
|
private
|
|
89
89
|
|
|
90
90
|
def in_app_browser?
|
|
91
|
+
in_app_browsers = %w[FBAN FBAV Telegram FB_Messenger Messenger]
|
|
91
92
|
user_agent = request.user_agent.to_s
|
|
92
|
-
|
|
93
|
-
user_agent.include?(
|
|
94
|
-
user_agent.include?('MicroMessenger') || # WeChat
|
|
95
|
-
user_agent.include?('Line') || # Line
|
|
96
|
-
user_agent.include?('WhatsApp') # WhatsApp
|
|
93
|
+
|
|
94
|
+
in_app_browsers.any? { |browser| user_agent.include?(browser) }
|
|
97
95
|
end
|
|
98
96
|
|
|
99
97
|
def render_not_found
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<% @checkout = ::Vpago::PaywayV2::Checkout.new(@payment) %>
|
|
1
|
+
<% @checkout = ::Vpago::PaywayV2::Checkout.new(@payment, request.user_agent) %>
|
|
2
2
|
<% payment_option = @payment.payment_method.preferences[:payment_option] %>
|
|
3
3
|
|
|
4
4
|
<form method="POST"
|
|
@@ -12,64 +12,82 @@
|
|
|
12
12
|
<% end %>
|
|
13
13
|
</form>
|
|
14
14
|
|
|
15
|
+
<!-- WebView Container -->
|
|
16
|
+
<div id="webViewContainer" style="display:none;"></div>
|
|
17
|
+
|
|
15
18
|
<script>
|
|
16
|
-
document.addEventListener("DOMContentLoaded", function () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
19
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
20
|
+
const form = document.getElementById("aba_merchant_request");
|
|
21
|
+
const paymentOption = form.dataset.paymentOption;
|
|
22
|
+
const webViewContainer = document.getElementById("webViewContainer");
|
|
23
|
+
|
|
24
|
+
// CASE 1: ABA KHQR Deeplink → fetch JSON then redirect
|
|
25
|
+
if (paymentOption === "abapay_khqr_deeplink") {
|
|
26
|
+
|
|
27
|
+
fetch(form.action, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
body: new FormData(form)
|
|
30
|
+
})
|
|
31
|
+
.then(res => res.json())
|
|
32
|
+
.then(data => {
|
|
33
|
+
|
|
34
|
+
if (!data.checkout_qr_url) {
|
|
35
|
+
console.error("Missing checkout_qr_url", data);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Setup container
|
|
40
|
+
webViewContainer.style.display = "block";
|
|
41
|
+
webViewContainer.style.position = "fixed";
|
|
42
|
+
webViewContainer.style.top = "0";
|
|
43
|
+
webViewContainer.style.left = "0";
|
|
44
|
+
webViewContainer.style.width = "100%";
|
|
45
|
+
webViewContainer.style.height = "100%";
|
|
46
|
+
webViewContainer.style.zIndex = "9999";
|
|
47
|
+
|
|
48
|
+
const checkoutIframe = document.createElement("iframe");
|
|
49
|
+
checkoutIframe.src = data.checkout_qr_url;
|
|
50
|
+
checkoutIframe.style.width = "100%";
|
|
51
|
+
checkoutIframe.style.height = "100%";
|
|
52
|
+
checkoutIframe.style.border = "none";
|
|
53
|
+
|
|
54
|
+
webViewContainer.appendChild(checkoutIframe);
|
|
55
|
+
|
|
56
|
+
// WAIT until checkout fully loads
|
|
57
|
+
checkoutIframe.onload = function () {
|
|
58
|
+
|
|
59
|
+
if (!data.abapay_deeplink) return;
|
|
60
|
+
|
|
61
|
+
console.log("Checkout loaded, attempting ABA deeplink...");
|
|
62
|
+
|
|
63
|
+
const deeplinkFrame = document.createElement("iframe");
|
|
64
|
+
deeplinkFrame.style.display = "none";
|
|
65
|
+
deeplinkFrame.src = data.abapay_deeplink;
|
|
66
|
+
document.body.appendChild(deeplinkFrame);
|
|
67
|
+
|
|
68
|
+
// Detect if user leaves browser (app opened)
|
|
69
|
+
let appOpened = false;
|
|
70
|
+
|
|
71
|
+
const visibilityHandler = () => {
|
|
72
|
+
appOpened = true;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
document.addEventListener("visibilitychange", visibilityHandler);
|
|
76
|
+
|
|
56
77
|
setTimeout(() => {
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
document.removeEventListener("visibilitychange", visibilityHandler);
|
|
79
|
+
|
|
80
|
+
if (!appOpened) {
|
|
81
|
+
console.log("ABA app not installed, staying on checkout page.");
|
|
59
82
|
}
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// 🔹 CASE 2: Normal ABA KHQR → regular redirect form post
|
|
71
|
-
} else {
|
|
72
|
-
form.submit();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
83
|
+
}, 2000);
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
.catch(err => console.error("ABA Deeplink Error:", err));
|
|
87
|
+
|
|
88
|
+
// CASE 2: Normal ABA KHQR → regular redirect form post
|
|
89
|
+
} else {
|
|
90
|
+
form.submit();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
75
93
|
</script>
|
|
@@ -8,50 +8,32 @@ rescue => e
|
|
|
8
8
|
Rails.logger.error("Vattanac checkout.create failed: #{e.message}")
|
|
9
9
|
{ deeplink_url: nil, web_url: nil }
|
|
10
10
|
end
|
|
11
|
-
|
|
12
|
-
@payment.user_informer.payment_is_processing(processing: true)
|
|
13
11
|
%>
|
|
14
12
|
|
|
15
13
|
<script>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
case "deeplink":
|
|
42
|
-
redirectTo(deeplinkUrl);
|
|
43
|
-
break;
|
|
44
|
-
|
|
45
|
-
case "all":
|
|
46
|
-
if (platform === "app") redirectTo(deeplinkUrl);
|
|
47
|
-
else if (platform === "web") redirectTo(webUrl);
|
|
48
|
-
else console.error("Unknown platform:", platform);
|
|
49
|
-
break;
|
|
50
|
-
|
|
51
|
-
default:
|
|
52
|
-
console.error("Invalid payment option:", paymentOption);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
setupPaymentProcessingListener();
|
|
56
|
-
});
|
|
14
|
+
const platform = "<%= params[:platform] %>";
|
|
15
|
+
const deeplinkUrl = "<%= raw(result[:deeplink_url]) %>";
|
|
16
|
+
const webUrl = "<%= raw(result[:web_url]) %>";
|
|
17
|
+
const paymentOption = "<%= payment_option %>";
|
|
18
|
+
|
|
19
|
+
const redirectTo = (url) => { if (url) window.location.href = url; };
|
|
20
|
+
|
|
21
|
+
switch (paymentOption) {
|
|
22
|
+
case "khqr":
|
|
23
|
+
redirectTo(webUrl);
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
case "deeplink":
|
|
27
|
+
redirectTo(deeplinkUrl);
|
|
28
|
+
break;
|
|
29
|
+
|
|
30
|
+
case "all":
|
|
31
|
+
if (platform === "app") redirectTo(deeplinkUrl);
|
|
32
|
+
else if (platform === "web") redirectTo(webUrl);
|
|
33
|
+
else console.error("Unknown platform:", platform);
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
default:
|
|
37
|
+
console.error("Invalid payment option:", paymentOption);
|
|
38
|
+
}
|
|
57
39
|
</script>
|
data/lib/spree_vpago/version.rb
CHANGED
data/lib/vpago/payway_v2/base.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
module Vpago
|
|
2
2
|
module PaywayV2
|
|
3
3
|
class Base
|
|
4
|
-
def initialize(payment, options = {})
|
|
4
|
+
def initialize(payment, user_agent = nil, options = {})
|
|
5
5
|
@options = options
|
|
6
6
|
@payment = payment
|
|
7
|
+
@user_agent = user_agent
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def req_time
|
|
@@ -112,10 +113,32 @@ module Vpago
|
|
|
112
113
|
uri.scheme = app_scheme
|
|
113
114
|
uri.to_s
|
|
114
115
|
else
|
|
115
|
-
|
|
116
|
+
# For in-app browsers, use appropriate deeplink scheme
|
|
117
|
+
if in_app_browser_payment?
|
|
118
|
+
case @user_agent
|
|
119
|
+
when /FBAN|FBAV/
|
|
120
|
+
'fb://'
|
|
121
|
+
when /Telegram/
|
|
122
|
+
'tg://'
|
|
123
|
+
when /FB_Messenger|Messenger/
|
|
124
|
+
'fb-messenger://'
|
|
125
|
+
else
|
|
126
|
+
continue_success_url
|
|
127
|
+
end
|
|
128
|
+
else
|
|
129
|
+
continue_success_url
|
|
130
|
+
end
|
|
116
131
|
end
|
|
117
132
|
end
|
|
118
133
|
|
|
134
|
+
# Check if payment is from in-app browser
|
|
135
|
+
def in_app_browser_payment?
|
|
136
|
+
return false unless @user_agent.present?
|
|
137
|
+
|
|
138
|
+
in_app_browsers = %w[FBAN FBAV Telegram FB_Messenger Messenger]
|
|
139
|
+
in_app_browsers.any? { |browser| @user_agent.include?(browser) }
|
|
140
|
+
end
|
|
141
|
+
|
|
119
142
|
def return_deeplink
|
|
120
143
|
return nil unless return_deeplink_url.present?
|
|
121
144
|
|