Przeglądaj źródła

feat: ajusta com a taxa do gateway

Gustavo Mantovani 1 tydzień temu
rodzic
commit
32a1f48f77
1 zmienionych plików z 15 dodań i 4 usunięć
  1. 15 4
      app/Services/Pagarme/PagarmePaymentService.php

+ 15 - 4
app/Services/Pagarme/PagarmePaymentService.php

@@ -340,13 +340,24 @@ class PagarmePaymentService
 
         $split = OrderRequestData::splitFromTransfers($transfers);
 
-        $platformFee = (float) ($payment->platform_fee_amount ?? 0);
+        $platformRecipientId = config('services.pagarme.platform_recipient_id');
 
-        if ($platformFee > 0) {
-            $platformRecipientId = config('services.pagarme.platform_recipient_id');
+        if (empty($platformRecipientId)) {
+            return $split;
+        }
+
+        $orderAmountCents = OrderRequestData::amountInCents((float) $payment->gross_amount);
+
+        $providerTotalCents = array_sum(array_map(
+            static fn (OrderSplitData $s) => $s->amount,
+            $split,
+        ));
+
+        $platformAmountCents = $orderAmountCents - $providerTotalCents;
 
+        if ($platformAmountCents > 0) {
             $split[] = new OrderSplitData(
-                amount:      OrderRequestData::amountInCents($platformFee),
+                amount:      $platformAmountCents,
                 recipientId: $platformRecipientId,
                 type:        'flat',