public function testCreatePartialPayouts() { $user = new User(); $referralUserLevel1 = new User(); $referralUserLevel2 = new User(); $referralUserLevel3 = new User(); // Setup referral hierarchy $user->setReferrer($referralUserLevel1); $referralUserLevel1->setReferrer($referralUserLevel2); $referralUserLevel2->setReferrer($referralUserLevel3); // Setup the account $account = new Account(); $account->setUser($user); $account->setPayoutPercentage(0.9); $account->setBroker(new Broker()); // Setup payment $payment = new Payment(); $payment->setAccount($account); $payment->setAmount(100); $this->paymentManager->createPartialPayouts($payment); $this->assertEquals(90, $user->getTotalPartialPayoutAmount()); $this->assertEquals(9, $referralUserLevel1->getTotalPartialPayoutAmount()); $this->assertEquals(5, $referralUserLevel2->getTotalPartialPayoutAmount()); $this->assertEquals(1, $referralUserLevel3->getTotalPartialPayoutAmount()); }
public function createPartialPayouts(Payment $payment) { $user = $payment->getAccount()->getUser(); $baseAmount = $payment->getAmount() * $payment->getAccount()->getPayoutPercentage(); // Check for referral payments if ($firstLevelReferrer = $user->getReferrer()) { // Payment for first level $amount = round($baseAmount * self::REFERRAL_PERCENT_LEVEL_1); $this->createPartialPayout($payment, $firstLevelReferrer, $amount); // Check for second level payment if ($secondLevelReferrer = $firstLevelReferrer->getReferrer()) { // Payment for second level $amount = round($baseAmount * self::REFERRAL_PERCENT_LEVEL_2); $this->createPartialPayout($payment, $secondLevelReferrer, $amount); // Check for the third level payment if ($thirdLevelReferrer = $secondLevelReferrer->getReferrer()) { // Payment for the third level $amount = round($baseAmount * self::REFERRAL_PERCENT_LEVEL_3); $this->createPartialPayout($payment, $thirdLevelReferrer, $amount); } } } $this->createPartialPayout($payment, $user, $baseAmount); }