瀏覽代碼

feat: ajusta com a taxa do gateway

Gustavo Mantovani 1 周之前
父節點
當前提交
32a1f48f77
共有 1 個文件被更改,包括 15 次插入4 次删除
  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',