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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9955a0a95b06aa963cef321fffefdf9f129dccb2366887604a4e15958b87371a
4
- data.tar.gz: 86ace8169e398c8ddcb3d40b17531d2403e5838157e94829c4ecd72686e362e5
3
+ metadata.gz: 89703ddc763dbab601246e10a41a1dd0bb4ca443ad6fd1f763fa1d4f120f74b5
4
+ data.tar.gz: 97e93bf3bcd95e7538b9472a96c86dc7cb6bad11165b100f698781ff53ec6d06
5
5
  SHA512:
6
- metadata.gz: 7f15eb56fc4239f9cd4b476f700dc3bc7f2b94db0f100f200b5ea5861d64a1f7ba75a46da2362428cd83c51f7aca522351d17d2d6d34bfe2af39f124aafce1e9
7
- data.tar.gz: 959f42a629dc7167c027755bd29b2cd3ae79563f91bc62bf0fe0835527beb2e002158f402f39d8375d1b89b2e5f795aab6381fdf7fecafa62815b0599f6bddc1
6
+ metadata.gz: 49a3f98690cff2d62d2168b4f08c1a15dcd44f318b8c83a69e658d1900068145ac564c076cd8d6aab8a73f6f84bb4a3d962e276492d03ecd99e5eff61b6ff738
7
+ data.tar.gz: 8050e93e978e43a0134d6e79d1d760aad60baf493032a514b72b2904466e9b76470a2a0a0279bcf6b894eaa5e36594a539c84ccf52c4f4457c57068358e4a784
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.2.2.pre.pre9)
4
+ spree_vpago (2.2.2.pre.pre11)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -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
- user_agent.include?('FBAN') || user_agent.include?('FBAV') || # Facebook
93
- user_agent.include?('Telegram') || # Telegram
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
- const form = document.getElementById("aba_merchant_request");
18
- const paymentOption = form.dataset.paymentOption;
19
-
20
- // 🔹 CASE 1: ABA KHQR Deeplink → fetch JSON then redirect
21
- if (paymentOption === "abapay_khqr_deeplink") {
22
- fetch(form.action, {
23
- method: "POST",
24
- body: new FormData(form)
25
- })
26
- .then(res => res.json())
27
- .then(data => {
28
- // 🔹 Create webview container for better control
29
- const webviewContainer = document.createElement('div');
30
- webviewContainer.style.position = 'fixed';
31
- webviewContainer.style.top = '0';
32
- webviewContainer.style.left = '0';
33
- webviewContainer.style.width = '100%';
34
- webviewContainer.style.height = '100%';
35
- webviewContainer.style.zIndex = '9999';
36
- webviewContainer.style.backgroundColor = 'white';
37
-
38
- // 🔹 Load QR page in webview
39
- if (data.checkout_qr_url) {
40
- const qrFrame = document.createElement('iframe');
41
- qrFrame.src = data.checkout_qr_url;
42
- qrFrame.style.width = '100%';
43
- qrFrame.style.height = '100%';
44
- qrFrame.style.border = 'none';
45
- webviewContainer.appendChild(qrFrame);
46
- document.body.appendChild(webviewContainer);
47
- }
48
-
49
- // 🔹 Attempt ABA deeplink after QR page loads
50
- if (data.abapay_deeplink) {
51
- setTimeout(() => {
52
- // Try direct navigation first (more reliable for deeplinks)
53
- window.location.href = data.abapay_deeplink;
54
-
55
- // Fallback: try opening in new tab if direct fails
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
- if (document.body.contains(webviewContainer)) {
58
- window.open(data.abapay_deeplink, '_blank');
78
+ document.removeEventListener("visibilitychange", visibilityHandler);
79
+
80
+ if (!appOpened) {
81
+ console.log("ABA app not installed, staying on checkout page.");
59
82
  }
60
- }, 500);
61
- }, 2000);
62
- }
63
-
64
- if (!data.checkout_qr_url && !data.abapay_deeplink) {
65
- console.error("checkout_qr_url and abapay_deeplink both missing", data);
66
- }
67
- })
68
- .catch(err => console.error("ABA Deeplink Error:", err));
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
- document.addEventListener("DOMContentLoaded", () => {
17
- const platform = "<%= params[:platform] %>";
18
- const deeplinkUrl = "<%= raw(result[:deeplink_url]) %>";
19
- const webUrl = "<%= raw(result[:web_url]) %>";
20
- const paymentOption = "<%= payment_option %>";
21
-
22
- const redirectTo = (url) => { if (url) window.location.href = url; };
23
-
24
- const setupPaymentProcessingListener = () => {
25
- const firebaseConfigs = <%= Rails.application.credentials.firebase_web_config.to_json.html_safe %>;
26
- const documentReferencePath = "<%= @payment.user_informer.document_reference_path %>";
27
- const successUrl = "<%= @payment.success_url %>";
28
-
29
- if (window.initPaymentProcessingListener) {
30
- window.initPaymentProcessingListener(firebaseConfigs, documentReferencePath, successUrl);
31
- } else {
32
- console.log("initPaymentProcessingListener is not defined");
33
- }
34
- };
35
-
36
- switch (paymentOption) {
37
- case "khqr":
38
- redirectTo(webUrl);
39
- break;
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>
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.2.2-pre9'.freeze
4
+ VERSION = '2.2.2-pre11'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -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
- continue_success_url
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_vpago
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2.pre.pre9
4
+ version: 2.2.2.pre.pre11
5
5
  platform: ruby
6
6
  authors:
7
7
  - You