/** * Return payment receiver. * * @param $paymentReceiverOption * @param $itemId * * @return null|string */ protected function getPaymentReceiver($paymentReceiverOption, $itemId) { if ($this->params->get('paypal_sandbox', 1)) { return Joomla\String\String::strtolower(Joomla\String\String::trim($this->params->get('paypal_sandbox_business_name'))); } else { if (strcmp("site_owner", $paymentReceiverOption) == 0) { // Site owner return Joomla\String\String::strtolower(Joomla\String\String::trim($this->params->get('paypal_business_name'))); } else { if (!JComponentHelper::isEnabled("com_crowdfundingfinance")) { return null; } else { $payout = new CrowdfundingFinance\Payout(JFactory::getDbo()); $payout->load($itemId); if (!$payout->getPaypalEmail()) { return null; } return Joomla\String\String::strtolower(Joomla\String\String::trim($payout->getPaypalEmail())); } } } }
/** * This method prepares the list with amount receivers. * * @param object $item * @param float $fee * * @return array * @throws RuntimeException */ public function getReceiverList($item, $fee) { $receiverList = array(); $siteOwnerAmount = $item->txn_amount; // Payment types that must be used with fees. $feesPaymentTypes = array("parallel", "chained"); // Get payment types. $paymentType = $this->params->get("paypal_payment_type", "simple"); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_TYPE"), $this->debugType, $paymentType) : null; // If there is NO fees and it is not SIMPLE payment type, // return empty receiver list, because there is no logic to // process parallel or chained transaction without amount (a fee) for receiving. if (in_array($paymentType, $feesPaymentTypes) and !$fee) { throw new RuntimeException(JText::_($this->textPrefix . "_ERROR_FEES_NOT_SET")); } // If it is parallel or chained payment type, // the user must provide us his PayPal account. // He must provide us an email using Crowdfunding Finance. if (in_array($paymentType, $feesPaymentTypes)) { jimport("CrowdfundingFinance.Payout"); $payout = new CrowdfundingFinance\Payout(JFactory::getDbo()); $payout->load($item->project_id); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYOUT_DATA"), $this->debugType, $payout->getProperties()) : null; $receiverEmail = $payout->getPaypalEmail(); if (!empty($receiverEmail)) { switch ($paymentType) { case "chained": // Set the amount that the project owner will receive. $projectOwnerAmount = $siteOwnerAmount; // Set the amount that the site owner will receive. $siteOwnerAmount = $fee; // Prepare primary receiver. $receiverList["receiver"][] = array("email" => $receiverEmail, "amount" => round($projectOwnerAmount, 2), "primary" => true); break; case "parallel": // Set the amount that the project owner will receive. $projectOwnerAmount = $siteOwnerAmount - $fee; // Set the amount that the site owner will receive. $siteOwnerAmount = $fee; $receiverList["receiver"][] = array("email" => $receiverEmail, "amount" => round($projectOwnerAmount, 2), "primary" => false); break; } } } // If the payment type is parallel or chained, // the user must provide himself as receiver. // If receiver missing, return an empty array. if (in_array($paymentType, $feesPaymentTypes) and empty($receiverList)) { throw new RuntimeException(JText::_($this->textPrefix . "_ERROR_INVALID_FIRST_RECEIVER")); } // If the payment type is parallel or chained, // and there is a receiver but there is no fee ( the result of the calculation of fees is 0 ), // I will not continue. I will not set the site owner as receiver of fee, because the fee is 0. // There is no logic to set more receivers which have to receive amount 0. if (in_array($paymentType, $feesPaymentTypes) and !$fee) { return $receiverList; } if ($this->params->get("paypal_sandbox", 1)) { // Simple $receiverList["receiver"][] = array("email" => Joomla\String\String::trim($this->params->get("paypal_sandbox_receiver_email")), "amount" => round($siteOwnerAmount, 2), "primary" => false); } else { $receiverList["receiver"][] = array("email" => Joomla\String\String::trim($this->params->get("paypal_receiver_email")), "amount" => round($siteOwnerAmount, 2), "primary" => false); } return $receiverList; }