spree_vpago 2.2.2.pre.pre10 → 2.2.2.pre.pre12

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: bd56e9a7ecb7d8d5ca0abaf1232b9d92233bd025043e06b763dbb89d675e0412
4
- data.tar.gz: 757343200d1e61cbe263a684d24ce2fa1fdd112c87b0d696bf27842132066378
3
+ metadata.gz: 0d5ee57baf6e2451847466adba567cf8922799e54575e0aa690758416ad14ed1
4
+ data.tar.gz: 2998d1e7883e8c1bd041bc2eb9abc4c8f3dcb45ee21a3c8d6958c838ffa57bfa
5
5
  SHA512:
6
- metadata.gz: 6ef89ccf97395357c1f766648af7fc48891494fc9b2b14d159edfd01c6e7a88f456bb8865bae8a76cde9821122badd3932d6516c6dc78c0c6903c7f25684591e
7
- data.tar.gz: 97718367ab37d76e0d9898278df202752167c2b4056954e6bb37534a23e6b57d60a5b200c6395e98f3c332e5e5eb94a74e4c771c9887155a448f385716adf316
6
+ metadata.gz: f4fac23a6529811d3fc71c6ac9128a2c2c93fad05cc3bab1e09878d7d9ccc67ecb4482075893162ce1568524ab364dc6c7bc763c2c56615122083c74dc4d21d3
7
+ data.tar.gz: 75f328a206a6a6deeb0a62d3bc41286188ebc931c36299ac35b07bc9e0a087d6631fb1c6615d9ef8f5b50fda2c187c4fdcae63fd6a30c0358b9bc7d20f3d292e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.2.2.pre.pre10)
4
+ spree_vpago (2.2.2.pre.pre12)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -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.78.0)
262
+ grpc (1.78.1)
263
263
  google-protobuf (>= 3.25, < 5.0)
264
264
  googleapis-common-protos-types (~> 1.0)
265
265
  hashdiff (1.1.0)
@@ -16,12 +16,6 @@ module Spree
16
16
  return redirect_to @payment.processing_url, allow_other_host: true unless @payment.checkout?
17
17
 
18
18
  @order = @payment.order
19
-
20
- # Set offsite_payment flag based on payment method and browser
21
- # True Money: always true (from params)
22
- # ABA KHQR: only true when in in-app browsers
23
- @offsite_payment = params[:offsite_payment] == 'true' ||
24
- (params[:check_in_app_browser] == 'true' && in_app_browser?)
25
19
  end
26
20
 
27
21
  # GET
@@ -85,17 +79,6 @@ module Spree
85
79
  sanitized_params
86
80
  end
87
81
 
88
- private
89
-
90
- def in_app_browser?
91
- 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
97
- end
98
-
99
82
  def render_not_found
100
83
  respond_to do |format|
101
84
  format.html { render file: Rails.public_path.join('404.html'), status: :not_found, layout: false }
@@ -8,9 +8,5 @@ module Vpago
8
8
  def render_form
9
9
  render partial: "spree/vpago_payments/forms/#{@payment.payment_method.class.to_s.underscore}"
10
10
  end
11
-
12
- def offsite_payment?
13
- @offsite_payment || false
14
- end
15
11
  end
16
12
  end
@@ -24,8 +24,7 @@ module Vpago
24
24
  payment_number: payment.number,
25
25
  order_number: order.number,
26
26
  order_jwt_token: order_jwt_token,
27
- offsite_payment: offsite_payment? ? true : nil,
28
- check_in_app_browser: aba_khqr_payment? ? true : nil
27
+ offsite_payment: offsite_payment? ? true : nil
29
28
  }.compact.to_query
30
29
  end
31
30
 
@@ -34,13 +33,6 @@ module Vpago
34
33
  payment.payment_method.type_true_money?
35
34
  end
36
35
 
37
- def aba_khqr_payment?
38
- return false unless payment.payment_method.is_a?(Spree::Gateway::PaywayV2)
39
-
40
- payment_option = payment.payment_method.preferred_payment_option
41
- payment_option.in?(%w[abapay_khqr abapay_khqr_deeplink])
42
- end
43
-
44
36
  private
45
37
 
46
38
  def app_scheme
@@ -1,11 +1,11 @@
1
1
  <% @checkout = ::Vpago::PaywayV2::Checkout.new(@payment) %>
2
- <% payment_option = @payment.payment_method.preferences[:payment_option] %>
2
+ <% @payment_option = @payment.payment_method.preferences[:payment_option] %>
3
3
 
4
4
  <form method="POST"
5
5
  action="<%= @checkout.checkout_url %>"
6
6
  id="aba_merchant_request"
7
- data-payment-option="<%= payment_option %>"
8
- style="<%= 'display:none;' if payment_option == 'abapay_khqr_deeplink' %>">
7
+ data-payment-option="<%= @payment_option %>"
8
+ style="<%= 'display:none;' if @payment_option == 'abapay_khqr_deeplink' %>">
9
9
 
10
10
  <% @checkout.gateway_params.each do |key, value| %>
11
11
  <input type="hidden" name="<%= key %>" value="<%= value %>">
@@ -21,18 +21,37 @@
21
21
  const paymentOption = form.dataset.paymentOption;
22
22
  const webViewContainer = document.getElementById("webViewContainer");
23
23
 
24
- // CASE 1: ABA KHQR Deeplink → fetch JSON then redirect
25
- if (paymentOption === "abapay_khqr_deeplink") {
24
+ // CASE 1: ABA KHQR Deeplink → fetch JSON then render checkout + optional deeplink
25
+ // 1. Check if response is OK and has JSON content
26
+ // 2. Validate required fields
27
+ // 3. WAIT until checkout fully loads before attempting deeplink
28
+ // 4. Detect if user leaves browser (app opened)
29
+ // 5. Fallback: show form and submit normally
26
30
 
31
+ if (paymentOption === "abapay_khqr_deeplink") {
27
32
  fetch(form.action, {
28
33
  method: "POST",
29
34
  body: new FormData(form)
30
35
  })
31
- .then(res => res.json())
32
- .then(data => {
33
-
34
- // Load QR page inside webViewContainer
35
- if (data.checkout_qr_url) {
36
+ .then(res => {
37
+ if (!res.ok) {
38
+ throw new Error(`HTTP ${res.status}: ${res.statusText}`);
39
+ }
40
+
41
+ const contentType = res.headers.get("content-type");
42
+ if (!contentType || !contentType.includes("application/json")) {
43
+ throw new Error("Response is not JSON");
44
+ }
45
+
46
+ return res.json();
47
+ })
48
+ .then(data => {
49
+ // Validate required fields
50
+ if (!data.checkout_qr_url && !data.abapay_deeplink) {
51
+ throw new Error("Missing checkout_qr_url and abapay_deeplink");
52
+ }
53
+
54
+ // Setup container as full-screen overlay
36
55
  webViewContainer.style.display = "block";
37
56
  webViewContainer.style.position = "fixed";
38
57
  webViewContainer.style.top = "0";
@@ -40,6 +59,7 @@
40
59
  webViewContainer.style.width = "100%";
41
60
  webViewContainer.style.height = "100%";
42
61
  webViewContainer.style.zIndex = "9999";
62
+ webViewContainer.style.backgroundColor = "#fff";
43
63
 
44
64
  const checkoutIframe = document.createElement("iframe");
45
65
  checkoutIframe.src = data.checkout_qr_url;
@@ -48,40 +68,41 @@
48
68
  checkoutIframe.style.border = "none";
49
69
 
50
70
  webViewContainer.appendChild(checkoutIframe);
51
- }
52
71
 
53
- // Attempt ABA Deeplink (hidden iframe)
54
- if (data.abapay_deeplink) {
72
+ checkoutIframe.onload = function () {
73
+ if (!data.abapay_deeplink) return;
55
74
 
56
- const deeplinkFrame = document.createElement("iframe");
57
- deeplinkFrame.style.display = "none";
58
- deeplinkFrame.src = data.abapay_deeplink;
59
- document.body.appendChild(deeplinkFrame);
75
+ console.log("Checkout loaded, attempting ABA deeplink...");
60
76
 
61
- // Detect if app opened
62
- let appOpened = false;
77
+ const deeplinkFrame = document.createElement("iframe");
78
+ deeplinkFrame.style.display = "none";
79
+ deeplinkFrame.src = data.abapay_deeplink;
80
+ document.body.appendChild(deeplinkFrame);
63
81
 
64
- const visibilityHandler = () => {
65
- appOpened = true;
66
- };
82
+ let appOpened = false;
67
83
 
68
- document.addEventListener("visibilitychange", visibilityHandler);
84
+ const visibilityHandler = () => {
85
+ appOpened = true;
86
+ };
69
87
 
70
- setTimeout(() => {
71
- document.removeEventListener("visibilitychange", visibilityHandler);
88
+ document.addEventListener("visibilitychange", visibilityHandler);
72
89
 
73
- if (!appOpened) {
74
- console.log("ABA app not installed, staying inside webViewContainer");
75
- }
76
- }, 2000);
77
- }
90
+ setTimeout(() => {
91
+ document.removeEventListener("visibilitychange", visibilityHandler);
78
92
 
79
- if (!data.checkout_qr_url && !data.abapay_deeplink) {
80
- console.error("Missing checkout_qr_url and abapay_deeplink", data);
81
- }
82
-
83
- })
84
- .catch(err => console.error("ABA Deeplink Error:", err));
93
+ if (!appOpened) {
94
+ console.log("ABA app not installed, staying on checkout page.");
95
+ }
96
+ }, 2000);
97
+ };
98
+ })
99
+ .catch(err => {
100
+ console.error("ABA Deeplink Error:", err);
101
+ console.log("Falling back to regular form submission...");
102
+
103
+ form.style.display = "block";
104
+ form.submit();
105
+ });
85
106
 
86
107
  // CASE 2: Normal ABA KHQR → regular redirect form post
87
108
  } else {
@@ -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-pre10'.freeze
4
+ VERSION = '2.2.2-pre12'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
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.2.2.pre.pre10
4
+ version: 2.2.2.pre.pre12
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-18 00:00:00.000000000 Z
11
+ date: 2026-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday