Пример #1
0
 /**
  * Entry point for the script
  *
  * @return  void
  *
  * @since   2.5
  */
 public function doExecute()
 {
     JFactory::getApplication('site');
     JPluginHelper::importPlugin('redcore');
     JPluginHelper::importPlugin('redpayment');
     // Set up statuses that are in their final stage
     $this->finalStatuses = array(RApiPaymentStatus::getStatusCompleted(), RApiPaymentStatus::getStatusCanceled_Reversal(), RApiPaymentStatus::getStatusDenied(), RApiPaymentStatus::getStatusExpired(), RApiPaymentStatus::getStatusRefunded(), RApiPaymentStatus::getStatusReversed());
     $this->out('============================');
     $this->out('Check Payments status change');
     $this->out('============================');
     $payments = $this->getPaymentsForChecking();
     $this->out('Number of payments for checking:' . count($payments));
     $this->out('============================');
     if (!empty($payments)) {
         foreach ($payments as $payment) {
             // Print out payment info
             $this->out('============================');
             $this->out(sprintf('Check for order name "%s" for extension "%s" using "%s" payment plugin:', $payment->order_name, $payment->extension_name, $payment->payment_name));
             $this->out('============================');
             // Preform check
             $status = RApiPaymentHelper::checkPayment($payment->id);
             // Print out status result
             foreach ($status as $statusKey => $message) {
                 if (is_array($message)) {
                     foreach ($status as $key => $value) {
                         $this->out($key . ': ' . $value);
                     }
                 } else {
                     $this->out($statusKey . ': ' . $message);
                 }
             }
             // Subtract retry count or reset it
             $paymentNew = RApiPaymentHelper::getPaymentById($payment->id);
             if (!in_array($paymentNew->status, $this->finalStatuses)) {
                 // We are still not done, we will subtract retry counter for this payment
                 $paymentNew->retry_counter -= 1;
                 RApiPaymentHelper::updatePaymentCounter($paymentNew->id, $paymentNew->retry_counter);
                 $this->out('Retry checks left: ' . $paymentNew->retry_counter);
             }
             $this->out('============================');
         }
     }
     $this->out('============================');
     $this->out('Done !');
 }
Пример #2
0
 /**
  * Calls method from helper file if exists or method from this class,
  * Additionally it Triggers plugin call for specific function in a format RApiHalFunctionName
  *
  * @param   string  $functionName  Function name
  *
  * @return mixed Result from callback function
  */
 public function triggerFunction($functionName)
 {
     $apiHelperClass = RApiPaymentHelper::getExtensionHelperObject($this->extensionName);
     $args = func_get_args();
     // Remove function name from arguments
     array_shift($args);
     // PHP 5.3 workaround
     $temp = array();
     foreach ($args as &$arg) {
         $temp[] =& $arg;
     }
     // We will add this instance of the object as last argument for manipulation in plugin and helper
     $temp[] =& $this;
     JFactory::getApplication()->triggerEvent('RApiRedpaymentBefore' . $functionName, array($functionName, $temp));
     // Checks if that method exists in helper file and executes it
     if (method_exists($apiHelperClass, $functionName)) {
         call_user_func_array(array($apiHelperClass, $functionName), $temp);
     }
     $result = call_user_func_array(array($this, $functionName), $temp);
     JFactory::getApplication()->triggerEvent('RApiRedpaymentAfter' . $functionName, $temp);
     return $result;
 }
Пример #3
0
 /**
  * Sets plugin parameters specific to given extension name (if extension have its own configuration)
  *
  * @param   string  $extensionName  Name of the extension
  * @param   string  $ownerName      Name of the owner
  *
  * @return void
  */
 protected function setRedpaymentOptions($extensionName, $ownerName)
 {
     $pluginOptions = RApiPaymentHelper::getPaymentParams($this->paymentName, $extensionName, $ownerName);
     $this->paymentHelper->pluginEnabled = (bool) $pluginOptions->state;
     $this->paymentHelper->params = $pluginOptions->params;
 }
Пример #4
0
 /**
  * Delete payment
  *
  * @return  void
  */
 public function deletePayment()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $ids = $input->get('cid', array(), 'array');
     foreach ($ids as $id) {
         $status = RApiPaymentHelper::deletePayment($id);
         if ($status) {
             $app->enqueueMessage(JText::_('COM_REDCORE_PAYMENT_DELETE_PAYMENT_SUCCESS'));
         } else {
             $lastLog = RApiPaymentHelper::getLastPaymentLog($id);
             $app->enqueueMessage(JText::sprintf('COM_REDCORE_PAYMENT_DELETE_PAYMENT_FAILED', $lastLog->message_text), 'error');
         }
     }
     // Redirect to the list screen
     $this->setRedirect($this->getRedirectToListRoute($this->getRedirectToListAppend()));
 }
Пример #5
0
 /**
  * Display method
  *
  * @param   string  $tpl  The template name
  *
  * @return  void
  */
 public function display($tpl = null)
 {
     $model = $this->getModel();
     $this->state = $model->getState();
     $this->activeFilters = $model->getActiveFilters();
     $this->filterForm = $model->getForm();
     $filters = array();
     $filters['status'] = RApiPaymentStatus::getStatusCompleted();
     if ($filter = $this->state->get('filter.payment_name')) {
         $filters['payment_name'] = $filter;
     }
     if ($filter = $this->state->get('filter.extension_name')) {
         $filters['extension_name'] = $filter;
     }
     if ($startDate = $this->state->get('filter.start_date')) {
         $filters['start_date'] = $startDate;
     }
     if ($endDate = $this->state->get('filter.end_date')) {
         $filters['end_date'] = $endDate;
     }
     $this->viewType = $this->state->get('filter.dashboard_view_type');
     $this->chartType = $this->state->get('filter.chart_type');
     if (empty($this->viewType)) {
         $this->viewType = RBootstrap::getConfig('payment_dashboard_view_type', 'payment_name');
         $this->state->set('filter.dashboard_view_type', $this->viewType);
     }
     if (empty($this->chartType)) {
         $this->chartType = RBootstrap::getConfig('payment_chart_type', 'Line');
         $this->state->set('filter.chart_type', $this->chartType);
     }
     if ($this->viewType == 'status') {
         unset($filters['status']);
     }
     $this->paymentData['chart'] = RApiPaymentHelper::getChartData($filters, 7, $this->viewType);
     $filters['start_date'] = date('Y-01-01', strtotime('today -1 year'));
     $filters['end_date'] = date('Y-m-d', strtotime('today'));
     $filters['status'] = RApiPaymentStatus::getStatusCompleted();
     $this->paymentData['overall'] = RApiPaymentHelper::getChartData($filters, 7, 'all');
     $this->chartData = RApiPaymentHelper::prepareChartData($this->paymentData['chart'], $this->chartType);
     parent::display($tpl);
 }
Пример #6
0
 /**
  * Handle the reception of notification from the payment gateway
  *
  * @param   string  $extensionName  Name of the extension
  * @param   string  $ownerName      Name of the owner
  * @param   array   $data           Data to fill out Payment form
  * @param   array   &$logData       Log data for payment api
  *
  * @return bool paid status
  */
 public function handleCallback($extensionName, $ownerName, $data, &$logData)
 {
     $post = JFactory::getApplication()->input->post->getArray();
     $postData = array();
     // Read the post from PayPal system and add 'cmd'
     $postData[] = 'cmd=_notify-validate';
     foreach ($post as $key => $value) {
         $value = urlencode(stripslashes($value));
         $postData[] = "{$key}={$value}";
     }
     $request = implode('&', $postData);
     $response = $this->getRequestFromGateway($request);
     if (strcmp($response, "VERIFIED") == 0) {
         /* Check the payment_status is Completed
            check that txn_id has not been previously processed
            check that receiver_email is your Primary PayPal email
            check that payment_amount/payment_currency are correct */
         $payment = $this->getPaymentByExtensionOrderData($extensionName, $data);
         if ($post['mc_gross'] != $payment->amount_total) {
             $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_PRICE_MISMATCH', $extensionName, $this->paymentName, $payment->amount_total, $post['mc_gross']);
             RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText);
             $logData['status'] = RApiPaymentStatus::getStatusCreated();
             $logData['message_text'] = $statusText;
             return false;
         } elseif ($post['mc_currency'] != $payment->currency) {
             $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_CURRENCY_MISMATCH', $extensionName, $this->paymentName, $payment->currency, $post['mc_currency']);
             RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText);
             $logData['status'] = RApiPaymentStatus::getStatusCreated();
             $logData['message_text'] = $statusText;
             return false;
         }
         // We are clear to log successful payment log now
         // Paypal have very similar structure of Status response so we can actually get them directly
         $logData['status'] = RApiPaymentStatus::getStatus($post['payment_status']);
         if ($logData['status'] == RApiPaymentStatus::getStatusCompleted()) {
             $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_SUCCESSFUL', $extensionName, $this->paymentName);
         } else {
             $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_CALLBACK_STATUS', $extensionName, $logData['status'], $this->paymentName);
         }
         RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = true, $statusText);
     } elseif (strcmp($response, "INVALID") == 0) {
         $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_IN_PAYMENT_GATEWAY', $extensionName, $this->paymentName, 'INVALID IPN');
         RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText);
         $logData['status'] = RApiPaymentStatus::getStatusCreated();
         $logData['message_text'] = $statusText;
         return false;
     } else {
         $statusText = JText::sprintf('LIB_REDCORE_PAYMENT_ERROR_IN_PAYMENT_GATEWAY', $extensionName, $this->paymentName, 'HTTP ERROR');
         RApiPaymentHelper::logToFile($this->paymentName, $extensionName, $data, $isValid = false, $statusText);
         $logData['status'] = RApiPaymentStatus::getStatusCreated();
         $logData['message_text'] = $statusText;
         return false;
     }
     $logData['message_text'] = $statusText;
     $logData['currency'] = $payment->currency;
     $logData['amount'] = $payment->amount_total;
     $logData['transaction_id'] = $data['txn_id'];
     return true;
 }
Пример #7
0
 /**
  * Returns details about the payment
  *
  * @param   string  $extensionName  Extension name (ex: com_content)
  * @param   array   $orderData      Extension Order data
  *
  * @return object
  */
 protected function getPaymentByExtensionOrderData($extensionName, $orderData)
 {
     $orderId = empty($orderData['order_id']) ? $orderData['id'] : $orderData['order_id'];
     $payment = RApiPaymentHelper::getPaymentByExtensionId($extensionName, $orderId);
     $restrictedData = array('id', 'extension_name', 'payment_name', 'sandbox', 'created_date', 'modified_date', 'confirmed_date', 'transaction_id', 'amount_total', 'amount_paid', 'coupon_code', 'customer_note', 'status');
     if (!$payment) {
         $ownerName = !empty($orderData['owner_name']) ? $orderData['owner_name'] : '';
         $createData = array();
         foreach ($orderData as $key => $value) {
             if (!in_array($key, $restrictedData)) {
                 $createData[$key] = $orderData[$key];
             }
         }
         // Create new payment based on order data
         $this->createPayment($extensionName, $ownerName, $createData);
         $payment = RApiPaymentHelper::getPaymentByExtensionId($extensionName, $orderId);
     } else {
         // We will update payment with provided data if it is different than originally provided
         $ownerName = !empty($orderData['owner_name']) ? $orderData['owner_name'] : $payment->owner_name;
         $updateData = JArrayHelper::fromObject($payment);
         foreach ($orderData as $key => $value) {
             if (!in_array($key, $restrictedData)) {
                 $updateData[$key] = $orderData[$key];
             }
         }
         // Create new payment based on order data
         $this->createPayment($extensionName, $ownerName, $updateData);
     }
     return $payment;
 }
Пример #8
0
<?php

/**
 * @package     Redcore.Admin
 * @subpackage  Templates
 *
 * @copyright   Copyright (C) 2008 - 2015 redCOMPONENT.com. All rights reserved.
 * @license     GNU General Public License version 2 or later, see LICENSE.
 */
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('rdropdown.init');
JHtml::_('rbootstrap.tooltip');
JHtml::_('rjquery.chosen', 'select');
// Check for request forgeries.
JPluginHelper::importPlugin('redpayment');
$app = JFactory::getApplication();
$input = $app->input;
$paymentName = $input->getString('payment_name');
$paymentConfigurationId = $input->getInt('payment_id', 0);
$randomId = rand(1, 10000);
$data = array('payment_name' => $paymentName, 'extension_name' => 'com_redcore', 'owner_name' => '', 'order_name' => 'Order ' . $randomId, 'order_id' => 'test' . $randomId, 'client_email' => '*****@*****.**', 'amount_original' => '10', 'amount_order_tax' => '2', 'order_tax_details' => '20% tax', 'amount_shipping' => '1', 'shipping_details' => '1 shipping', 'customer_note' => 'Testing', 'currency' => 'USD', 'sandbox' => true, 'url_cancel' => JUri::root() . 'administrator/index.php?option=com_redcore&view=payments', 'url_accept' => JUri::root() . 'administrator/index.php?option=com_redcore&view=payments');
if (!empty($paymentConfigurationId)) {
    $model = RModelAdmin::getAdminInstance('Payment_Configuration', array(), 'com_redcore');
    if ($item = $model->getItem($paymentConfigurationId)) {
        $data['extension_name'] = $item->extension_name;
        $data['owner_name'] = $item->owner_name;
    }
}
echo RApiPaymentHelper::displayPayment($paymentName, $data['extension_name'], $data['owner_name'], $data);