diff --git a/src/Payment/Aggregates/Payments/AbstractPayment.php b/src/Payment/Aggregates/Payments/AbstractPayment.php index 6fc4de2..8aff275 100644 --- a/src/Payment/Aggregates/Payments/AbstractPayment.php +++ b/src/Payment/Aggregates/Payments/AbstractPayment.php @@ -81,22 +81,8 @@ protected function getSplitData() return null; } $percentageOfPayment = $this->getAmount() / $this->order->getAmount(); - $splitMainRecipient = new Split(); - - $marketplaceCommission = intval( - round( - $splitOrderData->getMarketplaceComission() * $percentageOfPayment - ) - ); - - $splitMainRecipient->setCommission( - $marketplaceCommission - ); - - $splitMainRecipient->setRecipientId($this->moduleConfig->getMarketplaceConfig()->getMainRecipientId()); - $splitMainRecipientRequest = $splitMainRecipient - ->convertMainToSDKRequest(); + $sellersTotalCommission = 0; foreach ($splitOrderData->getSellersData() as $seller) { $splitRecipient = new Split(); @@ -106,12 +92,24 @@ protected function getSplitData() ) ); + $sellersTotalCommission += $sellerCommission; + $splitRecipient->setCommission($sellerCommission); $splitRecipient->setRecipientId($seller['pagarmeId']); $splitRecipientRequests[] = $splitRecipient ->convertSecondaryToSDKRequest(); } + $splitMainRecipient = new Split(); + + $splitMainRecipient->setRecipientId($this->moduleConfig->getMarketplaceConfig()->getMainRecipientId()); + $splitMainRecipientRequest = $splitMainRecipient + ->convertMainToSDKRequest(); + + $splitMainRecipient->setCommission( + $this->getAmount() - $sellersTotalCommission + ); + return [$splitMainRecipientRequest, $splitRecipientRequests]; }