spree_vpago 2.0.9.pre.beta5 → 2.0.9.pre.beta7

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: 7af7ed97c69c8a8263697826295b12b59d8eabcd50fc6ec83a8be08f474e024e
4
- data.tar.gz: 58bc7620d3cf994a1302f6c972cef6ff6c3611d58f59667235e7c473f8808769
3
+ metadata.gz: d007281b3eac7e38e9f8f9ebd48c2a71cb7d7bc1e5c6675c99c19492171f31ef
4
+ data.tar.gz: fed43008f20b2757ea22b6334cb2c3cd380b21d518e17fe2e790cd56cd704e2f
5
5
  SHA512:
6
- metadata.gz: d3b9a0bc94d9b0baf78a87632c227eca2237928805255e815dcd0afa9919115191755ac7741173d821fc46703b8529186f6eeb3a8dfee1f79235394e20e66929
7
- data.tar.gz: 6f930577991ff8830593fc48d64ec9c6be8b894c73648987caf6f08a103ef2e800e7355a1a57f09f41d6cf2c56a92c818b6e1d5cc64e5e78537484b3e55a227c
6
+ metadata.gz: 2d8bae5d999a97f83e2465e20963e2d88b1b5035afc78fdd23552c3e4a86b7cc0bab16ec069ac4eb06862d942b917c1101b07afff98c7e2381c2e154c643979a
7
+ data.tar.gz: d953058e8a545453014b90e6251f7b55db9784a9be8be2e98fbd1795c9443fbd82f843ecd6086f671a8a681a67fe83dd5f456420db38937c6eccf5b0a7028c17
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spree_vpago (2.0.9.pre.beta5)
4
+ spree_vpago (2.0.9.pre.beta7)
5
5
  faraday
6
6
  google-cloud-firestore
7
7
  spree_api (>= 4.5)
@@ -26,7 +26,9 @@ module Spree
26
26
  end
27
27
 
28
28
  # override
29
- def support_payout? = true
29
+ def support_payout?
30
+ preferred_payment_option.in?(%w[abapay_khqr abapay_khqr_deeplink])
31
+ end
30
32
 
31
33
  # override
32
34
  def support_pre_auth? = true
@@ -57,7 +57,7 @@ module Vpago
57
57
  end
58
58
 
59
59
  @available_payment_methods ||= if required_payway_payout?
60
- payment_methods.select(&:type_payway_v2?)
60
+ payment_methods.select(&:support_payout?)
61
61
  else
62
62
  payment_methods
63
63
  end
@@ -26,6 +26,10 @@ module Vpago
26
26
 
27
27
  def call
28
28
  payouts = vendor_payouts + vendor_shipment_payouts + store_payouts
29
+ payouts = payouts.map do |payout|
30
+ payout.amount = round_up(payout.amount)
31
+ payout
32
+ end
29
33
 
30
34
  return [] if payouts.all?(&:default?)
31
35
  return [] unless payouts.all? { |payout| validated?(payout) }
@@ -55,7 +59,7 @@ module Vpago
55
59
  total_confirmed_payouts = line_item.confirmed_payouts_for_vendor.sum(:amount)
56
60
  next if total_confirmed_payouts >= line_item.pre_commission_amount
57
61
 
58
- amount_owed_to_vendor = round_up(line_item.pre_commission_amount - total_confirmed_payouts)
62
+ amount_owed_to_vendor = line_item.pre_commission_amount - total_confirmed_payouts
59
63
  payout_amount = [amount_owed_to_vendor, remaining_amount].min
60
64
  outstanding_amount = [amount_owed_to_vendor - payout_amount, 0].max
61
65
 
@@ -88,7 +92,7 @@ module Vpago
88
92
  total_confirmed_payouts = shipment.confirmed_payouts_for_vendor.sum(:amount)
89
93
  next if total_confirmed_payouts >= shipment.cost_with_vendor_adjustment_total
90
94
 
91
- amount_owed_to_shipping_vendor = round_up(shipment.cost_with_vendor_adjustment_total - total_confirmed_payouts)
95
+ amount_owed_to_shipping_vendor = shipment.cost_with_vendor_adjustment_total - total_confirmed_payouts
92
96
  payout_amount = [amount_owed_to_shipping_vendor, remaining_amount].min
93
97
  outstanding_amount = [amount_owed_to_shipping_vendor - payout_amount, 0].max
94
98
 
@@ -125,7 +129,7 @@ module Vpago
125
129
  state: :created,
126
130
  payment: payment,
127
131
  payout_profile: Spree::PayoutProfiles::PaywayV2.default,
128
- amount: round_up(self.remaining_amount)
132
+ amount: self.remaining_amount
129
133
  )
130
134
  ]
131
135
  end
@@ -133,23 +137,14 @@ module Vpago
133
137
  # ABA does not support amounts with more than 2 decimal places.
134
138
  # Therefore, we must round all 3-decimal payouts to 2 decimals beforehand.
135
139
  #
136
- # Our rounding strategy:
137
- # - We round up for vendors & shipment payouts (to favor external parties).
138
- # - The remaining amount is adjusted in the platform's share (may be slightly less).
139
- #
140
140
  # Example:
141
- # Total amount: $5.00
141
+ # Total amount: $2.5
142
142
  #
143
- # Vendor payouts:
144
143
  # - Vendor 1: $0.625 → $0.63
145
144
  # - Vendor 2: $0.625 → $0.63
145
+ # - Platform: $1.25
146
146
  #
147
- # Shipment payouts:
148
- # - Shipment 1: $0.625 → $0.63
149
- # - Shipment 2: $0.625 → $0.63
150
- #
151
- # Platform payout:
152
- # - $2.50 → $2.48 (adjusted to ensure total remains $5.00)
147
+ # Final amount: 2.51$
153
148
  def round_up(amount)
154
149
  (amount * 100).ceil / 100.0
155
150
  end
@@ -7,6 +7,7 @@ module Vpago
7
7
  end
8
8
 
9
9
  def find_and_verify
10
+
10
11
  find_and_verify!
11
12
  rescue StandardError, ActiveRecord::RecordNotFound => e
12
13
  Rails.logger.error("PaymentJwtVerifier#find_and_verify error: #{e.class} - #{e.message}")
@@ -14,15 +15,16 @@ module Vpago
14
15
  end
15
16
 
16
17
  def find_and_verify!
18
+
17
19
  if vattanac_mini_app_payload?
18
- payload = Vpago::VattanacMiniAppDataHandler.new.decrypt_data(@params_hash[:data])
20
+ payload = Vpago::VattanacMiniAppDataHandler.new.decrypt_data(@params_hash[:data])
19
21
  payment = Spree::Payment.find_by!(number: payload['paymentId'])
20
22
  payment.update(transaction_response: payload)
21
23
  payment
22
- else
24
+ else
23
25
  order = Spree::Order.find_by!(number: params_hash[:order_number])
24
26
  verify_jwt!(order)
25
-
27
+
26
28
  Spree::Payment.find_by!(number: params_hash[:payment_number])
27
29
  end
28
30
  end
@@ -34,5 +36,8 @@ module Vpago
34
36
  def vattanac_mini_app_payload?
35
37
  params_hash[:data].present?
36
38
  end
39
+
37
40
  end
38
41
  end
42
+
43
+
@@ -1,15 +1,7 @@
1
1
  <% @checkout = ::Vpago::TrueMoney::Checkout.new(@payment) %>
2
2
  <% redirect_urls = @checkout.generate_payment_urls(params[:platform]) %>
3
- <h1><%= params[:platform] %></h1>
4
- <%= redirect_urls %>
5
3
  <% @payment.user_informer.payment_is_processing(processing: true) %>
6
4
 
7
- <dialog id="custom-dialog" style="padding: 1.5em; border-radius: 8px; border: 1px solid #ccc; max-width: 300px;">
8
- <p style="margin-bottom: 1em;">Do you want to open the app?</p>
9
- <button id="dialog-confirm" style="margin-right: 1em; padding: 0.5em 1em;">Yes</button>
10
- <button id="dialog-cancel" style="padding: 0.5em 1em;">No</button>
11
- </dialog>
12
-
13
5
  <script>
14
6
  document.addEventListener("DOMContentLoaded", () => {
15
7
  const platform = "<%= params[:platform] %>";
@@ -19,52 +11,15 @@
19
11
  const docRefPath = "<%= @payment.user_informer.document_reference_path %>";
20
12
  const successUrl = "<%= @payment.success_url %>";
21
13
 
22
- function showDialog(onConfirm) {
23
- const dialog = document.getElementById('custom-dialog');
24
- const confirmAction = document.getElementById('dialog-confirm');
25
- const cancelAction = document.getElementById('dialog-cancel');
26
-
27
- // Clean up old listeners to avoid duplicates
28
- confirmAction.onclick = null;
29
- cancelAction.onclick = null;
30
-
31
- confirmAction.onclick = () => {
32
- dialog.close();
33
- onConfirm(true);
34
- };
35
- cancelAction.onclick = () => {
36
- dialog.close();
37
- onConfirm(false);
38
- };
39
-
40
- dialog.showModal();
41
- }
42
-
43
14
  function setupConfirmPaymentButton() {
44
15
  if (platform === "app") {
45
- showDialog((proceed) => {
46
- if (proceed) {
47
- window.location.href = redirectUrls.deeplink;
48
- setTimeout(() => {
49
- window.location.href = redirectUrls.webview;
50
- }, 1500);
51
- } else {
52
- window.location.href = redirectUrls.webview;
53
- }
54
- });
55
-
16
+ window.location.href = redirectUrls.deeplink;
17
+ setTimeout(() => {
18
+ window.location.href = redirectUrls.webview;
19
+ }, 1500);
56
20
  } else if (confirmButton) {
57
21
  confirmButton.addEventListener("click", () => {
58
- showDialog((proceed) => {
59
- if (proceed) {
60
- window.location.href = redirectUrls.deeplink;
61
- setTimeout(() => {
62
- window.location.href = redirectUrls.webview;
63
- }, 1500); // wait 1.5 seconds before redirecting to webview
64
- } else {
65
- window.location.href = redirectUrls.webview;
66
- }
67
- });
22
+ window.open(redirectUrls.webview, '_blank');
68
23
  });
69
24
  }
70
25
  }
@@ -76,7 +31,6 @@
76
31
  console.warn("initPaymentProcessingListener is not defined");
77
32
  }
78
33
  }
79
-
80
34
  setupConfirmPaymentButton();
81
35
  setupPaymentProcessingListener();
82
36
  });
@@ -1,7 +1,7 @@
1
1
  module SpreeVpago
2
2
  module_function
3
3
 
4
- VERSION = '2.0.9-beta5'.freeze
4
+ VERSION = '2.0.9-beta7'.freeze
5
5
 
6
6
  def version
7
7
  Gem::Version.new VERSION
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.0.9.pre.beta5
4
+ version: 2.0.9.pre.beta7
5
5
  platform: ruby
6
6
  authors:
7
7
  - You