Beispiel #1
0
 /**
  * This method prepares a code that will be included to step "Extras" on project wizard.
  *
  * @param string    $context This string gives information about that where it has been executed the trigger.
  * @param object    $item    A project data.
  * @param Joomla\Registry\Registry $params  The parameters of the component
  *
  * @return null|string
  */
 public function onExtrasDisplay($context, &$item, &$params)
 {
     if (strcmp("com_crowdfunding.project.extras", $context) != 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     if (empty($item->user_id)) {
         return null;
     }
     // A flag that shows the options are active.
     if (!$this->params->get("display_paypal", 0) and !$this->params->get("display_banktransfer", 0)) {
         return "";
     }
     $activeTab = "";
     if ($this->params->get("display_paypal", 0)) {
         $activeTab = "paypal";
     } elseif ($this->params->get("display_banktransfer", 0)) {
         $activeTab = "banktransfer";
     }
     $payout = new CrowdfundingFinance\Payout(JFactory::getDbo());
     $payout->load($item->id);
     // Load jQuery
     JHtml::_("jquery.framework");
     JHtml::_("prism.ui.pnotify");
     JHtml::_('prism.ui.joomlaHelper');
     // Get the path for the layout file
     $path = JPath::clean(JPluginHelper::getLayoutPath('crowdfunding', 'payoutoptions'));
     // Render the login form.
     ob_start();
     include $path;
     $html = ob_get_clean();
     return $html;
 }
 /**
  * Disconnect user from payment gateway.
  *
  * @param string                   $context
  * @param Joomla\Registry\Registry $params
  *
  * @return null|array
  */
 public function onPayoutsDeauthorize($context, &$params)
 {
     if (strcmp('com_crowdfundingfinance.payouts.deauthorize.stripeconnect', $context) !== 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp('html', $docType) !== 0) {
         return null;
     }
     // Prepare output data.
     $output = array('redirect_url' => '', 'message' => '');
     $errorOutput = array('redirect_url' => JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), 'message' => '');
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . '_DEBUG_GET_RESPONSE_AUTHORIZE'), $this->debugType, $_GET) : null;
     $userId = JFactory::getUser()->get('id');
     if (!$userId) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_REGISTERED_USER');
         return $errorOutput;
     }
     // Get token
     $state = $this->app->input->get('state');
     if (!$state) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA');
         return $errorOutput;
     }
     // Get project ID and redirect URL from the session.
     $stateData = $this->app->getUserState($state);
     if (count($stateData) === 0 or (!$stateData['redirect_url'] or !$stateData['project_id'])) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_AUTHORIZATION_DATA');
         return $errorOutput;
     }
     $cfFinanceParams = JComponentHelper::getParams('com_crowdfundingfinance');
     $apiKeys = CrowdfundingFinance\Stripe\Helper::getKeys($cfFinanceParams);
     if (!$apiKeys['client_id'] or !$apiKeys['secret_key']) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_CONFIGURATION');
         return $errorOutput;
     }
     $payout = new CrowdfundingFinance\Payout(JFactory::getDbo());
     $payout->setSecretKey($this->app->get('secret'));
     $payout->load(array('project_id' => (int) $stateData['project_id']));
     if (!$payout->getId()) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_INVALID_PAYOUT');
         return $errorOutput;
     }
     $alias = !$apiKeys['test'] ? 'production' : 'test';
     $stripeData = $payout->getStripe();
     if (!$stripeData->get('stripeconnect.' . $alias . '.account_id')) {
         $errorOutput['message'] = JText::_($this->textPrefix . '_ERROR_NOT_CONNECTED');
         return $errorOutput;
     }
     CrowdfundingFinance\Stripe\Helper::deauthorize($apiKeys, $stripeData->get('stripeconnect.' . $alias . '.account_id'));
     $stripeData->set('stripeconnect.' . $alias . '.access_token', '');
     $stripeData->set('stripeconnect.' . $alias . '.refresh_token', '');
     $stripeData->set('stripeconnect.' . $alias . '.account_id', '');
     $stripeData->set('stripeconnect.' . $alias . '.expires', 0);
     $payout->setStripe($stripeData);
     $payout->storeStripe();
     // Get next URL.
     $output['redirect_url'] = base64_decode($stateData['redirect_url']);
     return $output;
 }
Beispiel #3
0
 /**
  * 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()));
             }
         }
     }
 }
Beispiel #4
0
 /**
  * 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;
 }