|
|
@@ -73,7 +73,7 @@
|
|
|
class="btn-withdraw"
|
|
|
:label="$t('provider.payments.btn_withdraw')"
|
|
|
:loading="withdrawLoading"
|
|
|
- :disable="saldoDisponivel <= 0 || withdrawLoading"
|
|
|
+ :disable="!canWithdraw"
|
|
|
@click="onSacar"
|
|
|
/>
|
|
|
</div>
|
|
|
@@ -166,12 +166,12 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, onMounted } from 'vue';
|
|
|
+import { computed, ref, onMounted } from 'vue';
|
|
|
import { useQuasar } from 'quasar';
|
|
|
import { useI18n } from 'vue-i18n';
|
|
|
import { formatCurrency } from 'src/helpers/utils';
|
|
|
import { labelsPeriodTypes } from 'src/helpers/arraysOptions/labelsPeriodTypes.js';
|
|
|
-import { getBalance, requestWithdrawal } from 'src/api/providerWithdrawal';
|
|
|
+import { getBalance, getWithdrawalFees, requestWithdrawal } from 'src/api/providerWithdrawal';
|
|
|
import { getPaymentSplits } from 'src/api/paymentSplit';
|
|
|
import MovimentacoesDialog from 'src/components/payments/MovimentacoesDialog.vue';
|
|
|
import WithdrawConfirmDialog from 'src/components/payments/WithdrawConfirmDialog.vue';
|
|
|
@@ -206,6 +206,7 @@ const earningsByPeriod = ref({
|
|
|
|
|
|
const saldoDisponivel = ref(0);
|
|
|
const saldoALiberar = ref(0);
|
|
|
+const paymentTransferFeeAmount = ref(3.67);
|
|
|
const services = ref([]);
|
|
|
|
|
|
const parseAmount = (value) => {
|
|
|
@@ -213,6 +214,18 @@ const parseAmount = (value) => {
|
|
|
return Number.isFinite(amount) ? amount : 0;
|
|
|
};
|
|
|
|
|
|
+const roundMoney = (value) => Math.round((parseAmount(value) + Number.EPSILON) * 100) / 100;
|
|
|
+
|
|
|
+const withdrawalNetAmount = computed(() => (
|
|
|
+ Math.max(0, roundMoney(saldoDisponivel.value - paymentTransferFeeAmount.value))
|
|
|
+));
|
|
|
+
|
|
|
+const canWithdraw = computed(() => (
|
|
|
+ saldoDisponivel.value > 0
|
|
|
+ && withdrawalNetAmount.value > 0
|
|
|
+ && !withdrawLoading.value
|
|
|
+));
|
|
|
+
|
|
|
const splitAmount = (split) => (
|
|
|
parseAmount(split.provider_amount ?? split.net_amount ?? split.gross_amount)
|
|
|
);
|
|
|
@@ -264,9 +277,10 @@ const sumSplits = (splits, predicate) => (
|
|
|
const loadData = async () => {
|
|
|
servicesLoading.value = true;
|
|
|
try {
|
|
|
- const [balance, splits] = await Promise.all([
|
|
|
+ const [balance, splits, fees] = await Promise.all([
|
|
|
getBalance(),
|
|
|
getPaymentSplits(),
|
|
|
+ loadWithdrawalFees(),
|
|
|
]);
|
|
|
const paymentSplits = splits || [];
|
|
|
const availableFromSplits = sumSplits(paymentSplits, isSplitAvailable);
|
|
|
@@ -277,6 +291,12 @@ const loadData = async () => {
|
|
|
|
|
|
saldoDisponivel.value = parseAmount(balance?.available) || availableFromSplits;
|
|
|
saldoALiberar.value = parseAmount(balance?.pending) || pendingFromSplits;
|
|
|
+ paymentTransferFeeAmount.value = parseAmount(
|
|
|
+ fees?.payment_transfer_fee_amount
|
|
|
+ ?? fees?.gateway_fee_amount
|
|
|
+ ?? fees?.fee_amount
|
|
|
+ ?? fees?.amount
|
|
|
+ ) || paymentTransferFeeAmount.value;
|
|
|
|
|
|
services.value = paymentSplits.map((s) => ({
|
|
|
id: s.id,
|
|
|
@@ -298,14 +318,34 @@ const loadData = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const loadWithdrawalFees = async () => {
|
|
|
+ try {
|
|
|
+ return await getWithdrawalFees();
|
|
|
+ } catch {
|
|
|
+ return { payment_transfer_fee_amount: paymentTransferFeeAmount.value };
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const onSacar = () => {
|
|
|
+ const grossAmount = roundMoney(saldoDisponivel.value);
|
|
|
+ const gatewayFeeAmount = roundMoney(paymentTransferFeeAmount.value);
|
|
|
+ const netAmount = roundMoney(withdrawalNetAmount.value);
|
|
|
+
|
|
|
$q.dialog({
|
|
|
component: WithdrawConfirmDialog,
|
|
|
- componentProps: { amount: saldoDisponivel.value },
|
|
|
+ componentProps: {
|
|
|
+ grossAmount,
|
|
|
+ gatewayFeeAmount,
|
|
|
+ netAmount,
|
|
|
+ },
|
|
|
}).onOk(async () => {
|
|
|
withdrawLoading.value = true;
|
|
|
try {
|
|
|
- await requestWithdrawal();
|
|
|
+ await requestWithdrawal({
|
|
|
+ gross_amount: grossAmount,
|
|
|
+ gateway_fee_amount: gatewayFeeAmount,
|
|
|
+ net_amount: netAmount,
|
|
|
+ });
|
|
|
saldoDisponivel.value = 0;
|
|
|
// notification handled by axios interceptor
|
|
|
} catch (error) {
|