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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/models/spree/gateway/payway_v2.rb +3 -1
- data/app/models/vpago/order_decorator.rb +1 -1
- data/app/models/vpago/payouts_generator.rb +10 -15
- data/app/services/vpago/payment_finder.rb +8 -3
- data/app/views/spree/vpago_payments/forms/spree/gateway/_true_money.html.erb +5 -51
- data/lib/spree_vpago/version.rb +1 -1
- 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: d007281b3eac7e38e9f8f9ebd48c2a71cb7d7bc1e5c6675c99c19492171f31ef
|
4
|
+
data.tar.gz: fed43008f20b2757ea22b6334cb2c3cd380b21d518e17fe2e790cd56cd704e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d8bae5d999a97f83e2465e20963e2d88b1b5035afc78fdd23552c3e4a86b7cc0bab16ec069ac4eb06862d942b917c1101b07afff98c7e2381c2e154c643979a
|
7
|
+
data.tar.gz: d953058e8a545453014b90e6251f7b55db9784a9be8be2e98fbd1795c9443fbd82f843ecd6086f671a8a681a67fe83dd5f456420db38937c6eccf5b0a7028c17
|
data/Gemfile.lock
CHANGED
@@ -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 =
|
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 =
|
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:
|
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
|
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
|
-
#
|
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 =
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
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
|
});
|
data/lib/spree_vpago/version.rb
CHANGED