コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: paypal.php プロジェクト: sis-direct/CrowdFunding
 /**
  * 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;
 }
コード例 #4
0
ファイル: paypal.php プロジェクト: pashakiz/crowdf
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
ファイル: paypaladaptive.php プロジェクト: pashakiz/crowdf
 /**
  * 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;
 }