/** * Method to get the field input markup. * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { // Initialize some field attributes. $size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : ''; $readonly = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $disabled = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $class = !empty($this->element['class']) ? ' class="' . (string) $this->element['class'] . '"' : ""; // Initialize JavaScript field attributes. $onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; $params = JComponentHelper::getParams("com_virtualcurrency"); /** @var $params Joomla\Registry\Registry */ $currencyId = $params->get("payments_currency_id"); jimport("virtualcurrency.realcurrency"); $currency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); if ($currency->getSymbol()) { // Prepended $html = '<div class="input-prepend input-append"><span class="add-on">' . $currency->getSymbol() . '</span>'; } else { // Append $html = '<div class="input-append">'; } $html .= '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . '/>'; // Appended $html .= '<span class="add-on">' . $currency->getAbbr() . '</span></div>'; return $html; }
/** * @param JApplicationSite $app */ protected function prepareInformation($app) { if ($this->params->get("debug_payment_disabled", 0)) { $app->redirect(JRoute::_('index.php?option=com_virtualcurrency&view=payment', false)); } $paymentSessionData = $app->getUserState("payment.data"); $itemId = $paymentSessionData["item_id"]; $this->amount = $paymentSessionData["amount"]; jimport("virtualcurrency.currency"); $this->item = new VirtualCurrencyCurrency(JFactory::getDbo()); $this->item->load($itemId); // Calculate total amount that should be paid. jimport("itprism.math"); $total = new ITPrismMath(); $total->calculateTotal(array($this->amount, $this->item->getParam("amount"))); $this->total = (string) $total; // Get real currency $realCurrencyId = $this->params->get("payments_currency_id"); jimport("virtualcurrency.realcurrency"); $this->realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $realCurrencyId, $this->params); }
/** * This method processes transaction data that comes from PayPal instant notifier. * * @param string $context * @param Joomla\Registry\Registry $params The parameters of the component * * @return null|object */ public function onPaymenNotify($context, &$params) { if (strcmp("com_virtualcurrency.notify.paypal", $context) != 0) { return null; } $app = JFactory::getApplication(); /** @var $app JApplicationSite */ if ($app->isAdmin()) { return null; } $doc = JFactory::getDocument(); /** @var $doc JDocumentRaw */ // Check document type $docType = $doc->getType(); if (strcmp("raw", $docType) != 0) { return null; } // Validate request method $requestMethod = $app->input->getMethod(); if (strcmp("POST", $requestMethod) != 0) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_REQUEST_METHOD"), $this->debugType, JText::sprintf($this->textPrefix . "_ERROR_INVALID_TRANSACTION_REQUEST_METHOD", $requestMethod)); return null; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESPONSE"), $this->debugType, $_POST) : null; // Decode custom data $custom = JArrayHelper::getValue($_POST, "custom"); $custom = json_decode(base64_decode($custom), true); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CUSTOM"), $this->debugType, $custom) : null; // Verify gateway. Is it PayPal? if (!$this->isPayPalGateway($custom)) { $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_GATEWAY"), $this->debugType, array("custom" => $custom, "_POST" => $_POST)); return null; } // Get PayPal URL $sandbox = $this->params->get('paypal_sandbox', 0); if (!$sandbox) { $url = JString::trim($this->params->get('paypal_url', "https://www.paypal.com/cgi-bin/webscr")); } else { $url = JString::trim($this->params->get('paypal_sandbox_url', "https://www.sandbox.paypal.com/cgi-bin/webscr")); } jimport("itprism.payment.paypal.ipn"); $paypalIpn = new ITPrismPayPalIpn($url, $_POST); $loadCertificate = (bool) $this->params->get("paypal_load_certificate", 0); $paypalIpn->verify($loadCertificate); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VERIFY_OBJECT"), $this->debugType, $paypalIpn) : null; // Prepare the array that will be returned by this method $result = array("currency" => null, "transaction" => null, "payment_service" => "PayPal"); if ($paypalIpn->isVerified()) { // Get currency jimport("virtualcurrency.realcurrency"); $realCurrencyId = $params->get("payments_currency_id"); $realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $realCurrencyId); // Get intention data $paymentId = JArrayHelper::getValue($custom, "payment_id", 0, "int"); jimport("virtualcurrency.payment.session"); $paymentSession = new VirtualCurrencyPaymentSession(JFactory::getDbo()); $paymentSession->load($paymentId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties()) : null; // Validate transaction data $validData = $this->validateData($_POST, $realCurrency->getAbbr(), $paymentSession, $params); if (is_null($validData)) { return $result; } // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_VALID_DATA"), $this->debugType, $validData) : null; // Get project. jimport("virtualcurrency.currency"); $currencyId = JArrayHelper::getValue($validData, "currency_id"); $currency = VirtualCurrencyCurrency::getInstance(JFactory::getDbo(), $currencyId); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_CURRENCY_OBJECT"), $this->debugType, $currency->getProperties()) : null; // Check for valid project if (!$currency->getId()) { // Log data in the database $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_CURRENCY"), $this->debugType, $validData); return $result; } // Save transaction data. // If it is not completed, return empty results. // If it is complete, continue with process transaction data if (!$this->storeTransaction($validData, $currency)) { return $result; } // Prepare the data that will be returned $result["transaction"] = JArrayHelper::toObject($validData); // Generate object of data based on the project properties $properties = $currency->getProperties(); $result["currency"] = JArrayHelper::toObject($properties); // DEBUG DATA JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null; // Remove intention $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null; $this->removePaymentSession($paymentSession, $txnStatus); unset($paymentSession); } else { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_TRANSACTION_DATA"), $this->debugType, array("error message" => $paypalIpn->getError(), "paypalVerify" => $paypalIpn, "_POST" => $_POST)); } return $result; }
/** * Send emails to the administrator and buyer of units. * * @param object $currency * @param object $transaction * @param Joomla\Registry\Registry $params */ protected function sendMails($currency, $transaction, $params) { $app = JFactory::getApplication(); /** @var $app JApplicationSite */ // Get website $uri = JUri::getInstance(); $website = $uri->toString(array("scheme", "host")); $emailMode = $this->params->get("email_mode", "plain"); jimport("virtualcurrency.currency"); $units = VirtualCurrencyCurrency::getInstance(JFactory::getDbo(), $currency->id); jimport("virtualcurrency.realcurrency"); $currencyId = $params->get("payments_currency_id"); $realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $currencyId, $params); // Prepare data for parsing $data = array("site_name" => $app->get("sitename"), "site_url" => JUri::root(), "item_title" => $currency->title, "order_url" => $website . JRoute::_(VirtualCurrencyHelperRoute::getAccountsRoute()), "units" => $units->getAmountString($transaction->units), "units_title" => $units->getTitle(), "amount" => $realCurrency->getAmountString($transaction->txn_amount), "transaction_id" => $transaction->txn_id); // DEBUG DATA JDEBUG ? $this->log->add($this->textPrefix . "_DEBUG_MAIL_DATA", $this->debugType, var_export($data, true)) : null; // Send mail to the administrator $emailId = $this->params->get("admin_mail_id", 0); if (!empty($emailId)) { jimport("virtualcurrency.email"); $email = new VirtualCurrencyEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $recipientName = $email->getSenderName(); $recipientMail = $email->getSenderEmail(); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_PLAIN_TEXT); } // Check for an error. if ($return !== true) { $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_ADMIN"), $this->debugType); } } // Send mail to buyer $emailId = $this->params->get("user_mail_id", 0); $userId = $transaction->receiver_id; if (!empty($emailId) and !empty($userId)) { $email = new VirtualCurrencyEmail(); $email->setDb(JFactory::getDbo()); $email->load($emailId); if (!$email->getSenderName()) { $email->setSenderName($app->get("fromname")); } if (!$email->getSenderEmail()) { $email->setSenderEmail($app->get("mailfrom")); } $user = JFactory::getUser($userId); $recipientName = $user->get("name"); $recipientMail = $user->get("email"); // Prepare data for parsing $data["sender_name"] = $email->getSenderName(); $data["sender_email"] = $email->getSenderEmail(); $data["recipient_name"] = $recipientName; $data["recipient_email"] = $recipientMail; $email->parse($data); $subject = $email->getSubject(); $body = $email->getBody($emailMode); $mailer = JFactory::getMailer(); if (strcmp("html", $emailMode) == 0) { // Send as HTML message $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_HTML); } else { // Send as plain text. $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, VirtualCurrencyConstants::MAIL_MODE_PLAIN_TEXT); } // Check for an error. if ($return !== true) { // Log error $this->log->add(JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_USER"), $this->debugType); } } }