|
|
@@ -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',
|
|
|
|