/**
  * Validate PayPal transaction.
  *
  * @param array  $data
  * @param string $currencyCode
  * @param Crowdfunding\Payment\Session  $paymentSessionRemote
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return array
  */
 protected function validateData($data, $currencyCode, $paymentSessionRemote)
 {
     $txnDate = ArrayHelper::getValue($data, 'payment_date');
     $date = new JDate($txnDate);
     // Prepare transaction data
     $transactionData = array('investor_id' => $paymentSessionRemote->getUserId(), 'project_id' => $paymentSessionRemote->getProjectId(), 'reward_id' => $paymentSessionRemote->isAnonymous() ? 0 : $paymentSessionRemote->getRewardId(), 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'txn_id' => ArrayHelper::getValue($data, 'txn_id', null, 'string'), 'txn_amount' => ArrayHelper::getValue($data, 'mc_gross', null, 'float'), 'txn_currency' => ArrayHelper::getValue($data, 'mc_currency', null, 'string'), 'txn_status' => strtolower(ArrayHelper::getValue($data, 'payment_status', '', 'string')), 'txn_date' => $date->toSql(), 'extra_data' => $this->prepareExtraData($data));
     // Check Project ID and Transaction ID
     if (!$transactionData['project_id'] or !$transactionData['txn_id']) {
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->errorType, $transactionData);
         return null;
     }
     // Check if project record exists in database.
     $projectRecord = new Crowdfunding\Validator\Project\Record(JFactory::getDbo(), $transactionData['project_id']);
     if (!$projectRecord->isValid()) {
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_PROJECT'), $this->errorType, $transactionData);
         return null;
     }
     // Check if reward record exists in database.
     if ($transactionData['reward_id'] > 0) {
         $rewardRecord = new Crowdfunding\Validator\Reward\Record(JFactory::getDbo(), $transactionData['reward_id'], array('state' => Prism\Constants::PUBLISHED));
         if (!$rewardRecord->isValid()) {
             $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_REWARD'), $this->errorType, $transactionData);
             return null;
         }
     }
     // Check currency
     if (strcmp($transactionData['txn_currency'], $currencyCode) !== 0) {
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_CURRENCY'), $this->errorType, array('TRANSACTION DATA' => $transactionData, 'CURRENCY' => $currencyCode));
         return null;
     }
     // Check payment receiver.
     $allowedReceivers = array(strtolower(ArrayHelper::getValue($data, 'business')), strtolower(ArrayHelper::getValue($data, 'receiver_email')), strtolower(ArrayHelper::getValue($data, 'receiver_id')));
     // Get payment receiver.
     $paymentReceiverOption = $this->params->get('paypal_payment_receiver', 'site_owner');
     $paymentReceiver = $this->getPaymentReceiver($paymentReceiverOption, $transactionData['project_id']);
     if (!in_array($paymentReceiver, $allowedReceivers, true)) {
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_RECEIVER'), $this->errorType, array('TRANSACTION DATA' => $transactionData, 'RECEIVER' => $paymentReceiver, 'ALLOWED RECEIVERS' => $allowedReceivers));
         return null;
     }
     return $transactionData;
 }
Example #2
0
 public function process()
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Check for request forgeries.
     $requestMethod = $app->input->getMethod();
     if (strcmp("POST", $requestMethod) == 0) {
         JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     } else {
         JSession::checkToken("get") or jexit(JText::_('JINVALID_TOKEN'));
     }
     // Get params
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     // Get the data from the form
     $itemId = $this->input->getInt('id', 0);
     $rewardId = $this->input->getInt('rid', 0);
     // Get amount
     $amount = CrowdfundingHelper::parseAmount($this->input->getString("amount"));
     // Get user ID
     $user = JFactory::getUser();
     $userId = (int) $user->get("id");
     // Anonymous user ID
     $aUserId = "";
     $model = $this->getModel();
     /** @var $model CrowdfundingModelBacking */
     // Get the item
     $item = $model->getItem($itemId);
     $returnUrl = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug);
     // Authorise the user
     if (!$user->authorise("crowdfunding.donate", "com_crowdfunding")) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_('COM_CROWDFUNDING_ERROR_NO_PERMISSIONS'), "notice");
         return;
     }
     // Check for valid project
     if (empty($item->id)) {
         $this->setRedirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()), JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), "notice");
         return;
     }
     // Check for maintenance (debug) state.
     if ($params->get("debug_payment_disabled", 0)) {
         $msg = Joomla\String\String::trim($params->get("debug_disabled_functionality_msg"));
         if (!$msg) {
             $msg = JText::_("COM_CROWDFUNDING_DEBUG_MODE_DEFAULT_MSG");
         }
         $this->setRedirect(JRoute::_($returnUrl, false), $msg, "notice");
         return;
     }
     // Check for agreed conditions from the user.
     if ($params->get("backing_terms", 0)) {
         $terms = $this->input->get("terms", 0, "int");
         if (!$terms) {
             $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_TERMS_NOT_ACCEPTED"), "notice");
             return;
         }
     }
     // Check for valid amount.
     if (!$amount) {
         $this->setRedirect(JRoute::_($returnUrl, false), JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT"), "notice");
         return;
     }
     // Store payment process data
     // Get the payment process object and
     // store the selected data from the user.
     $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $item->id;
     $paymentSessionLocal = $app->getUserState($paymentSessionContext);
     $paymentSessionLocal->step1 = true;
     $paymentSessionLocal->amount = $amount;
     $paymentSessionLocal->rewardId = $rewardId;
     $app->setUserState($paymentSessionContext, $paymentSessionLocal);
     // Generate hash user ID used for anonymous payment.
     if (!$userId) {
         $aUserId = $app->getUserState("auser_id");
         if (!$aUserId) {
             // Generate a hash ID for anonymous user.
             $anonymousUserId = new Prism\String();
             $anonymousUserId->generateRandomString(32);
             $aUserId = (string) $anonymousUserId;
             $app->setUserState("auser_id", $aUserId);
         }
     }
     $date = new JDate();
     // Create an intention record.
     $intentionId = 0;
     if (!empty($userId)) {
         $intentionKeys = array("user_id" => $userId, "project_id" => $item->id);
         $intention = new Crowdfunding\Intention(JFactory::getDbo());
         $intention->load($intentionKeys);
         $intentionData = array("user_id" => $userId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql());
         $intention->bind($intentionData);
         $intention->store();
         $intentionId = $intention->getId();
     }
     // Create a payment session.
     $paymentSessionDatabase = new Crowdfunding\Payment\Session(JFactory::getDbo());
     $paymentSessionData = array("user_id" => $userId, "auser_id" => $aUserId, "project_id" => $item->id, "reward_id" => $rewardId, "record_date" => $date->toSql(), "session_id" => $paymentSessionLocal->session_id, "intention_id" => $intentionId);
     $paymentSessionDatabase->bind($paymentSessionData);
     $paymentSessionDatabase->store();
     // Redirect to next page
     $link = CrowdfundingHelperRoute::getBackingRoute($item->slug, $item->catslug, "payment");
     $this->setRedirect(JRoute::_($link, false));
 }
 /**
  * Validate PayPal transaction
  *
  * @param array  $data
  * @param string $currency
  * @param Crowdfunding\Payment\Session  $paymentSession
  *
  * @return array|null
  */
 protected function validateData($data, $currency, $paymentSession)
 {
     $parentId = Joomla\Utilities\ArrayHelper::getValue($data, 'parent_txn_id', '', 'string');
     if ($parentId !== '') {
         $transaction = new Crowdfunding\Transaction(JFactory::getDbo());
         $transaction->load(array('txn_id' => $parentId));
         $investorId = (int) $transaction->getInvestorId();
         $projectId = (int) $transaction->getProjectId();
         $rewardId = (int) $transaction->getRewardId();
     } else {
         $investorId = (int) $paymentSession->getUserId();
         $projectId = (int) $paymentSession->getProjectId();
         $rewardId = $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId();
     }
     $txnDate = Joomla\Utilities\ArrayHelper::getValue($data, 'payment_date');
     $date = new JDate($txnDate);
     // Get additional information from transaction.
     $extraData = $this->prepareExtraData($data);
     // Prepare transaction data
     $transaction = array('investor_id' => $investorId, 'project_id' => $projectId, 'reward_id' => $rewardId, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'txn_id' => Joomla\Utilities\ArrayHelper::getValue($data, 'txn_id', '', 'string'), 'parent_txn_id' => $parentId, 'txn_amount' => Joomla\Utilities\ArrayHelper::getValue($data, 'mc_gross', 0, 'float'), 'txn_currency' => Joomla\Utilities\ArrayHelper::getValue($data, 'mc_currency', '', 'string'), 'txn_status' => JString::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'payment_status', '', 'string')), 'txn_date' => $date->toSql(), 'status_reason' => $this->getStatusReason($data), 'extra_data' => $extraData);
     // Check Project ID and Transaction ID
     if (!$transaction['project_id'] or !$transaction['txn_id']) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->debugType, $transaction);
         return null;
     }
     // Check currency
     if (strcmp($transaction['txn_currency'], $currency) !== 0) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_CURRENCY'), $this->debugType, array('TRANSACTION DATA' => $transaction, 'CURRENCY' => $currency));
         return null;
     }
     // Check receiver
     $allowedReceivers = array(JString::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'business')), JString::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'receiver_email')), JString::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'receiver_id')));
     if ($this->params->get('paypal_sandbox', 1)) {
         $receiver = JString::strtolower(JString::trim($this->params->get('paypal_sandbox_business_name')));
     } else {
         $receiver = JString::strtolower(JString::trim($this->params->get('paypal_business_name')));
     }
     if (!in_array($receiver, $allowedReceivers, true)) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_RECEIVER'), $this->debugType, array('TRANSACTION DATA' => $data, 'RECEIVER' => $receiver, 'RECEIVER DATA' => $allowedReceivers));
         return null;
     }
     return $transaction;
 }
Example #4
0
 /**
  * Validate PayPal transaction.
  *
  * @param array  $data
  * @param string $currency
  * @param Crowdfunding\Payment\Session  $paymentSession
  *
  * @return array
  */
 protected function validateData($data, $currency, $paymentSession)
 {
     $txnDate = Joomla\Utilities\ArrayHelper::getValue($data, 'payment_date');
     $date = new JDate($txnDate);
     // Prepare transaction data
     $transaction = array('investor_id' => (int) $paymentSession->getUserId(), 'project_id' => (int) $paymentSession->getProjectId(), 'reward_id' => $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId(), 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'txn_id' => Joomla\Utilities\ArrayHelper::getValue($data, 'txn_id', null, 'string'), 'txn_amount' => Joomla\Utilities\ArrayHelper::getValue($data, 'mc_gross', null, 'float'), 'txn_currency' => Joomla\Utilities\ArrayHelper::getValue($data, 'mc_currency', null, 'string'), 'txn_status' => strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'payment_status', '', 'string')), 'txn_date' => $date->toSql(), 'extra_data' => $this->prepareExtraData($data));
     // Check Project ID and Transaction ID
     if (!$transaction['project_id'] or !$transaction['txn_id']) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->debugType, $transaction);
         return null;
     }
     // Check currency
     if (strcmp($transaction['txn_currency'], $currency) !== 0) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_CURRENCY'), $this->debugType, array('TRANSACTION DATA' => $transaction, 'CURRENCY' => $currency));
         return null;
     }
     // Check payment receiver.
     $allowedReceivers = array(strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'business')), strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'receiver_email')), strtolower(Joomla\Utilities\ArrayHelper::getValue($data, 'receiver_id')));
     // Get payment receiver.
     $paymentReceiverOption = $this->params->get('paypal_payment_receiver', 'site_owner');
     $paymentReceiver = $this->getPaymentReceiver($paymentReceiverOption, $transaction['project_id']);
     if (!in_array($paymentReceiver, $allowedReceivers, true)) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_RECEIVER'), $this->debugType, array('TRANSACTION DATA' => $transaction, 'RECEIVER' => $paymentReceiver, 'RECEIVER DATA' => $allowedReceivers));
         return null;
     }
     return $transaction;
 }
Example #5
0
 /**
  * Validate PayPal transaction.
  *
  * @param array  $data
  * @param string $currency
  * @param Crowdfunding\Payment\Session  $paymentSession
  *
  * @return array
  */
 protected function validateData($data, $currency, $paymentSession)
 {
     $txnDate = Joomla\Utilities\ArrayHelper::getValue($data, "payment_date");
     $date = new JDate($txnDate);
     // Prepare transaction data
     $transaction = array("investor_id" => (int) $paymentSession->getUserId(), "project_id" => (int) $paymentSession->getProjectId(), "reward_id" => $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId(), "service_provider" => "PayPal", "txn_id" => Joomla\Utilities\ArrayHelper::getValue($data, "txn_id", null, "string"), "txn_amount" => Joomla\Utilities\ArrayHelper::getValue($data, "mc_gross", null, "float"), "txn_currency" => Joomla\Utilities\ArrayHelper::getValue($data, "mc_currency", null, "string"), "txn_status" => Joomla\String\String::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, "payment_status", null, "string")), "txn_date" => $date->toSql(), "extra_data" => $this->prepareExtraData($data));
     // Check Project ID and Transaction ID
     if (!$transaction["project_id"] or !$transaction["txn_id"]) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, $transaction);
         return null;
     }
     // Check currency
     if (strcmp($transaction["txn_currency"], $currency) != 0) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_CURRENCY"), $this->debugType, array("TRANSACTION DATA" => $transaction, "CURRENCY" => $currency));
         return null;
     }
     // Check payment receiver.
     $allowedReceivers = array(Joomla\String\String::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, "business")), Joomla\String\String::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, "receiver_email")), Joomla\String\String::strtolower(Joomla\Utilities\ArrayHelper::getValue($data, "receiver_id")));
     // Get payment receiver.
     $paymentReceiverOption = $this->params->get("paypal_payment_receiver", "site_owner");
     $paymentReceiver = $this->getPaymentReceiver($paymentReceiverOption, $transaction["project_id"]);
     if (!in_array($paymentReceiver, $allowedReceivers)) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_RECEIVER"), $this->debugType, array("TRANSACTION DATA" => $transaction, "RECEIVER" => $paymentReceiver, "RECEIVER DATA" => $allowedReceivers));
         return null;
     }
     return $transaction;
 }
 /**
  * Validate transaction data.
  *
  * @param array                 $data
  * @param string                $currency
  * @param Crowdfunding\Payment\Session $paymentSession
  *
  * @return null|array
  */
 protected function validateData($data, $currency, $paymentSession)
 {
     // Get transaction ID.
     $txnId = Joomla\Utilities\ArrayHelper::getValue($data, 'txn_id');
     // Prepare transaction amount.
     $amount = Joomla\Utilities\ArrayHelper::getValue($data, 'value', 0.0, 'float');
     $amount /= 100000000;
     // Transaction date.
     $date = new JDate();
     // Get transaction status
     $status = 'pending';
     $confirmations = Joomla\Utilities\ArrayHelper::getValue($data, 'confirmations', 0, 'int');
     if ($confirmations >= 6) {
         $status = 'completed';
     }
     // If the transaction has been made by anonymous user, reset reward. Anonymous users cannot select rewards.
     $rewardId = $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId();
     // Get additional information from transaction.
     $extraData = $this->prepareExtraData($data);
     // Prepare transaction data
     $transaction = array('investor_id' => (int) $paymentSession->getUserId(), 'project_id' => (int) $paymentSession->getProjectId(), 'reward_id' => (int) $rewardId, 'service_provider' => $this->serviceProvider, 'service_alias' => $this->serviceAlias, 'txn_id' => $txnId, 'txn_amount' => (double) $amount, 'txn_currency' => $currency, 'txn_status' => $status, 'txn_date' => $date->toSql(), 'extra_data' => $extraData);
     // Check User Id, Project ID and Transaction ID
     if (!$transaction['txn_amount']) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . '_ERROR_INVALID_TRANSACTION_DATA'), $this->debugType, $transaction);
         return null;
     }
     return $transaction;
 }
Example #7
0
 /**
  * Validate PayPal transaction
  *
  * @param array  $data
  * @param string $currency
  * @param Crowdfunding\Payment\Session $paymentSession
  *
  * @return array|null
  */
 protected function validateData($data, $currency, $paymentSession)
 {
     $date = new JDate();
     // Get additional information from transaction.
     $extraData = $this->prepareNotificationExtraData($data, JText::_("PLG_CROWDFUNDINGPAYMENT_PAYPALADAPTIVE_RESPONSE_NOTE_NOTIFICATION"));
     // Prepare transaction data
     $transaction = array("investor_id" => (int) $paymentSession->getUserId(), "project_id" => (int) $paymentSession->getProjectId(), "reward_id" => $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId(), "service_provider" => "PayPal", "txn_id" => Joomla\Utilities\ArrayHelper::getValue($data, "preapproval_key"), "parent_txn_id" => "", "txn_amount" => Joomla\Utilities\ArrayHelper::getValue($data, "max_total_amount_of_all_payments", 0, "float"), "txn_currency" => Joomla\Utilities\ArrayHelper::getValue($data, "currency_code", "", "string"), "txn_status" => $this->getPaymentStatus($data), "txn_date" => $date->toSql(), "status_reason" => $this->getStatusReason($data), "extra_data" => $extraData);
     // Check Project ID and Transaction ID
     if (!$transaction["project_id"] or !$transaction["txn_id"]) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, $transaction);
         return null;
     }
     // Check currency
     if (strcmp($transaction["txn_currency"], $currency) != 0) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_CURRENCY"), $this->debugType, array("TRANSACTION DATA" => $transaction, "CURRENCY" => $currency));
         return null;
     }
     return $transaction;
 }