spree_vpago 2.2.2.pre.pre14 → 2.2.2.pre.pre16

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: e94689187876e623541aaec9dcb455c5115764ac821e267e459481946d3aa7c7
4
- data.tar.gz: e7770a4ce6e8917a30cc4f6fa48c35c84092dbdf57eea16dbfd2841c6a0cb04a
3
+ metadata.gz: c069c6d08d71cab3036cd97f94c053b4b633219c8a9919646bc2782dfa2fde03
4
+ data.tar.gz: 5ae430280310306aa6622d08161730d00d5058456b934602893684d5670167a9
5
5
  SHA512:
6
- metadata.gz: b640e0a537b543c96218267cce0d700904acf92e8bb20f0f2a86f56371ad10c17a596b54d560165ce957f0703e6893b867cc099f26a2b117d4db219bf9af1605
7
- data.tar.gz: e148c061234a0bdba0f8bb0423d02e6e9a6ad0f0c10357f1aab1703785e644b7dccddc8cdce9acd84e550e916d21ec576a4394d01dfc98ed37892d2a18fbf92f
6
+ metadata.gz: 4c500caadeaf75c7d1eb2f50a6d39e0b78cb28f11a3c5fc4d28e2f9da4acd2e03b7a8296cbb506069edcdde2a42b64a208c74ac038101d3297329bbbb29c3dd4
7
+ data.tar.gz: 0c955a9832cb835c05cd9da3fea7271fb9991eb7ef8f784954a6e20173feb188d23449b62c6fea60bc2a796c9de52a0065237cd0a7cadd52c5634aba2b340e1f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.2.2.pre.pre14)
4
+ spree_vpago (2.2.2.pre.pre16)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -37,6 +37,12 @@ module Vpago
37
37
  class: 'fullwidth select2')
38
38
  when 'preferred_icon_name'
39
39
  return form.select(:preferred_icon_name, available_payment_icons, {}, class: 'fullwidth select2')
40
+ when 'preferred_payment_option'
41
+ return form.select(:preferred_payment_option, Spree::Gateway::PaywayV2::PAYMENT_OPTIONS, {}, class: 'fullwidth select2')
42
+ when 'preferred_abapay_khqr_deeplink_option'
43
+ return ''.html_safe unless form.object.abapay_khqr_deeplink?
44
+
45
+ return form.select(:preferred_abapay_khqr_deeplink_option, Spree::Gateway::PaywayV2::ABAPAY_KHQR_DEEPLINK_OPTIONS, {}, class: 'fullwidth select2')
40
46
  when 'preferred_vattanac_payment_option'
41
47
  return form.select(:preferred_vattanac_payment_option, available_vattanac_payment_options, {}, class: 'fullwidth select2')
42
48
  end
@@ -8,5 +8,23 @@ 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 render_payment_status_listener
13
+ render partial: 'spree/vpago_payments/payment_status_listener'
14
+ end
15
+
16
+ # when return nil, each payment method should use their default URL.
17
+ # eg. PayWayV2 will use the continue_success_url as deeplink back URL.
18
+ def custom_return_deeplink_url
19
+ user_agent = request.user_agent.to_s.downcase
20
+
21
+ if user_agent.include?('telegram')
22
+ 'tg://'
23
+ elsif user_agent.include?('fban') || user_agent.include?('facebook')
24
+ 'fb://'
25
+ elsif user_agent.include?('messenger')
26
+ 'fb-messenger://'
27
+ end
28
+ end
11
29
  end
12
30
  end
@@ -1,20 +1,38 @@
1
1
  module Spree
2
2
  class Gateway::PaywayV2 < PaymentMethod
3
+ ABAPAY_KHQR_DEEPLINK_OPTIONS = %w[open_both open_deeplink_only open_checkout_url_only].freeze
4
+ PAYMENT_OPTIONS = %w[abapay_khqr_deeplink abapay_khqr cards wechat alipay].freeze
5
+
3
6
  preference :host, :string
4
7
  preference :api_key, :string
5
8
  preference :merchant_id, :string
6
- preference :payment_option, :string # 'abapay', 'cards', 'abapay_deeplink'
9
+ preference :payment_option, :string
7
10
  preference :transaction_fee_fix, :string
8
11
  preference :transaction_fee_percentage, :string
9
12
  preference :public_key, :text
13
+ preference :abapay_khqr_deeplink_option, :string, default: 'open_both'
10
14
 
11
15
  validates :preferred_public_key, presence: true, if: :enable_pre_auth?
16
+ validates :preferred_abapay_khqr_deeplink_option, inclusion: { in: ABAPAY_KHQR_DEEPLINK_OPTIONS }, if: :abapay_khqr_deeplink?
17
+ validates :preferred_payment_option, inclusion: { in: PAYMENT_OPTIONS }
12
18
 
13
19
  # override: partial to render in admin
14
20
  def method_type
15
21
  'payway_v2'
16
22
  end
17
23
 
24
+ def abapay_khqr_deeplink?
25
+ preferred_payment_option == 'abapay_khqr_deeplink'
26
+ end
27
+
28
+ def open_abapay_deeplink?
29
+ preferred_abapay_khqr_deeplink_option.in?(%w[open_both open_deeplink_only])
30
+ end
31
+
32
+ def open_checkout_url?
33
+ preferred_abapay_khqr_deeplink_option.in?(%w[open_both open_checkout_url_only])
34
+ end
35
+
18
36
  # override
19
37
  def default_payout_profile
20
38
  Spree::PayoutProfiles::PaywayV2.default
@@ -0,0 +1,35 @@
1
+ <%# This partial listens to payment status changes and does not process the payment. %>
2
+ <%# When it detects a status change, it automatically redirects to the processing URL for actual processing. %>
3
+ <%# Designed to be used in checkout.html.erb %>
4
+
5
+ <script>
6
+ document.addEventListener("DOMContentLoaded", function() {
7
+ let firebaseConfigs = <%= Rails.application.credentials.firebase_web_config.to_json.html_safe %>;
8
+
9
+ window.listenToProcessingState({
10
+ firebaseConfigs: firebaseConfigs,
11
+ documentReferencePath: "<%= @payment.user_informer.document_reference_path %>",
12
+ onPaymentIsProcessing: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
13
+ window.location.href = "<%= @payment.processing_url %>";
14
+ },
15
+ onPaymentIsRetrying: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
16
+ window.location.href = "<%= @payment.processing_url %>";
17
+ },
18
+ onOrderIsProcessing: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
19
+ window.location.href = "<%= @payment.processing_url %>";
20
+ },
21
+ onOrderIsCompleted: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
22
+ window.location.href = "<%= @payment.processing_url %>";
23
+ },
24
+ onOrderProcessFailed: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
25
+ window.location.href = "<%= @payment.processing_url %>";
26
+ },
27
+ onPaymentProcessFailed: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
28
+ window.location.href = "<%= @payment.processing_url %>";
29
+ },
30
+ onCompleted: function (orderState, paymentState, processing, reasonCode, reasonMessage) {
31
+ window.location.href = "<%= @payment.success_url %>";
32
+ },
33
+ });
34
+ });
35
+ </script>
@@ -1,3 +1,9 @@
1
1
  <h1>Checkout...</h1>
2
2
 
3
- <%= render_form %>
3
+ <%# Primary action button fixed at bottom of screen %>
4
+ <%# Each payment method can customize this button (title, onclick) for their specific action. %>
5
+ <%# See: app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb for example %>
6
+ <button id="vpago_primary_button" style="display: none;"></button>
7
+
8
+ <%= render_payment_status_listener %>
9
+ <%= render_form %>
@@ -1,52 +1,70 @@
1
- <% @checkout = ::Vpago::PaywayV2::Checkout.new(@payment) %>
2
- <% @payment_option = @payment.payment_method.preferences[:payment_option] %>
3
-
4
- <form method="POST"
5
- action="<%= @checkout.checkout_url %>"
6
- id="aba_merchant_request"
7
- data-payment-option="<%= @payment_option %>"
8
- style="<%= 'display:none;' if @payment_option == 'abapay_khqr_deeplink' %>">
1
+ <% @checkout_options = { custom_return_deeplink_url: custom_return_deeplink_url } %>
2
+ <% @checkout = ::Vpago::PaywayV2::Checkout.new(@payment, @checkout_options) %>
9
3
 
4
+ <form method="POST" action="<%= @checkout.checkout_url %>" id="aba_merchant_request">
10
5
  <% @checkout.gateway_params.each do |key, value| %>
11
6
  <input type="hidden" name="<%= key %>" value="<%= value %>">
12
7
  <% end %>
13
8
  </form>
14
9
 
15
10
  <script>
16
- document.addEventListener("DOMContentLoaded", function () {
17
- const form = document.getElementById("aba_merchant_request");
18
- const paymentOption = form.dataset.paymentOption;
19
-
20
- if (paymentOption === "abapay_khqr_deeplink") {
21
-
22
- fetch(form.action, {
23
- method: "POST",
24
- body: new FormData(form)
25
- })
26
- .then(res => res.json())
27
- .then(data => {
28
- if (data.checkout_qr_url && data.abapay_deeplink) {
29
- // 1) Open checkout first (new tab)
30
- window.open(data.checkout_qr_url, "_blank");
31
-
32
- // 2) Then redirect this tab to deeplink
33
- setTimeout(() => {
34
- window.location.href = data.abapay_deeplink;
35
- }, 1000);
36
- } else if (data.checkout_qr_url) {
37
- // Only checkout URL available
38
- window.location.href = data.checkout_qr_url;
39
- } else if (data.abapay_deeplink) {
40
- // Only deeplink available
41
- window.location.href = data.abapay_deeplink;
42
- }
43
- })
44
- .catch(err => {
45
- console.error("Error:", err);
11
+ const abapayKhqrDeeplink = "<%= @payment.payment_method.abapay_khqr_deeplink? %>";
12
+ const shouldOpenAbaPayDeeplink = <%= @payment.payment_method.open_abapay_deeplink? %>;
13
+ const shouldOpenCheckoutUrl = <%= @payment.payment_method.open_checkout_url? %>;
14
+
15
+ function isMobile() {
16
+ return /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
17
+ }
18
+
19
+ function openAbapayDeeplink(abapay_deeplink) {
20
+ document.getElementById("vpago_primary_button").style.display = "block";
21
+ document.getElementById("vpago_primary_button").innerText = "Open ABA Pay";
22
+ document.getElementById("vpago_primary_button").addEventListener("click", function() {
23
+ window.open(abapay_deeplink, "_blank");
46
24
  });
47
25
 
48
- } else {
49
- form.submit();
26
+ window.open(abapay_deeplink, "_blank");
27
+ }
28
+
29
+ function openCheckoutUrl(checkout_qr_url, delay = 0) {
30
+ if(delay > 0) {
31
+ setTimeout(function() {
32
+ window.location.href = checkout_qr_url;
33
+ }, delay);
34
+ } else {
35
+ window.location.href = checkout_qr_url;
36
+ }
50
37
  }
51
- });
52
- </script>
38
+
39
+ document.addEventListener("DOMContentLoaded", function () {
40
+ if (abapayKhqrDeeplink) {
41
+ var formData = new FormData(document.getElementById("aba_merchant_request"));
42
+ var checkoutUrl = document.getElementById("aba_merchant_request").action;
43
+
44
+ fetch(checkoutUrl, {
45
+ method: "POST",
46
+ body: formData
47
+ })
48
+ .then(function(response) {
49
+ return response.json();
50
+ })
51
+ .then(function(data) {
52
+ var shouldDelayBeforeOpenCheckoutUrl = false;
53
+
54
+ if (data.abapay_deeplink && shouldOpenAbaPayDeeplink) {
55
+ openAbapayDeeplink(data.abapay_deeplink);
56
+ shouldDelayBeforeOpenCheckoutUrl = true;
57
+ }
58
+
59
+ if (data.checkout_qr_url && shouldOpenCheckoutUrl) {
60
+ openCheckoutUrl(data.checkout_qr_url, shouldDelayBeforeOpenCheckoutUrl ? 3000 : 0);
61
+ }
62
+ })
63
+ .catch(function(error) {
64
+ console.error("Payment request failed:", error);
65
+ });
66
+ } else {
67
+ document.getElementById("aba_merchant_request").submit();
68
+ }
69
+ })
70
+ </script>
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.2.2-pre14'.freeze
4
+ VERSION = '2.2.2-pre16'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
@@ -4,6 +4,7 @@ module Vpago
4
4
  def initialize(payment, options = {})
5
5
  @options = options
6
6
  @payment = payment
7
+ @custom_return_deeplink_url = options[:custom_return_deeplink_url]
7
8
  end
8
9
 
9
10
  def req_time
@@ -76,8 +77,7 @@ module Vpago
76
77
  end
77
78
 
78
79
  def payment_option
79
- card_option = @payment.payment_method.preferences[:payment_option]
80
- Vpago::Payway::CARD_TYPES.index(card_option).nil? ? Vpago::Payway::CARD_TYPE_ABAPAY : card_option
80
+ @payment.payment_method.preferences[:payment_option]
81
81
  end
82
82
 
83
83
  # optional
@@ -105,6 +105,8 @@ module Vpago
105
105
  # redirect to continue URL, let it handle redirecting to app.
106
106
  # allowed override to specific app eg. from tg://t.me
107
107
  def return_deeplink_url
108
+ return @custom_return_deeplink_url if @custom_return_deeplink_url.present?
109
+
108
110
  app_scheme = @payment.payment_method.preferences[:app_scheme]
109
111
 
110
112
  if app_scheme.present?
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.pre14
4
+ version: 2.2.2.pre.pre16
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
@@ -329,6 +329,7 @@ files:
329
329
  - app/views/spree/payway_results/success.html.erb
330
330
  - app/views/spree/payway_v2_card_popups/_form.html.erb
331
331
  - app/views/spree/payway_v2_card_popups/show.html.erb
332
+ - app/views/spree/vpago_payments/_payment_status_listener.html.erb
332
333
  - app/views/spree/vpago_payments/checkout.html.erb
333
334
  - app/views/spree/vpago_payments/forms/spree/gateway/_payway_v2.html.erb
334
335
  - app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb