Esempio n. 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 !');
 }
Esempio n. 2
0
 /**
  * Execute the Api Callback operation.
  *
  * @return  mixed  RApi object with information on success, boolean false on failure.
  */
 public function apiCallback()
 {
     $app = JFactory::getApplication();
     $this->getPayment();
     $logData = array();
     $logData['status'] = RApiPaymentStatus::getStatusUndefined();
     // This method can process data from payment request more if needed
     $app->triggerEvent('onRedpaymentRequestCallback', array($this->paymentName, $this->extensionName, $this->ownerName, $this->requestData, &$logData));
     $this->outputData = $logData;
     return $this;
 }
Esempio n. 3
0
 /**
  * This method handles payment process for creating payments in Payment Gateway
  *
  * @param   string  $paymentName    Payment name
  * @param   string  $extensionName  Name of the extension
  * @param   string  $ownerName      Name of the owner
  * @param   array   $data           Request data
  * @param   array   &$logData       Log data
  * @param   bool    &$isAccepted    If process is successful then this flag should be true
  *
  * @return void
  */
 public function onRedpaymentRequestProcess($paymentName, $extensionName, $ownerName, $data, &$logData, &$isAccepted)
 {
     if (!$this->isPaymentEnabled($paymentName, $extensionName, $ownerName)) {
         return;
     }
     $logData = RApiPaymentHelper::generatePaymentLog(RApiPaymentStatus::getStatusCreated(), $data, JText::sprintf('LIB_REDCORE_PAYMENT_LOG_PROCESS_MESSAGE', $this->paymentName));
     // Handle process
     $this->paymentHelper->handleProcess($extensionName, $ownerName, $data, $logData, $isAccepted);
     // If plugin did not set the message text we will set it
     if (empty($logData['message_text'])) {
         if ($isAccepted === true) {
             $logData['message_text'] = JText::sprintf('LIB_REDCORE_PAYMENT_LOG_ACCEPT_MESSAGE', $extensionName, $this->paymentName);
         } elseif ($isAccepted === false) {
             $logData['message_text'] = JText::sprintf('LIB_REDCORE_PAYMENT_LOG_CANCEL_MESSAGE', $extensionName, $this->paymentName);
         } else {
             $logData['message_text'] = JText::sprintf('LIB_REDCORE_PAYMENT_LOG_DEFAULT_MESSAGE', $extensionName, $this->paymentName);
         }
     }
     // Save payment log and update change for payment
     RApiPaymentHelper::saveNewPaymentLog($logData);
     // We call extension helper file to trigger afterHandleProcess method if needed
     RApiPaymentHelper::triggerExtensionHelperMethod($extensionName, 'afterHandleProcess', $ownerName, $paymentName, $data, $isAccepted);
 }
Esempio n. 4
0
?>
					</td>
				</tr>
				<tr>
					<th>
						<?php 
echo JText::_('COM_REDCORE_PAYMENT_STATUS');
?>
					</th>
					<td>
						<label class="label label-<?php 
echo RApiPaymentStatus::getStatusLabelClass($this->item->status);
?>
">
							<?php 
echo RApiPaymentStatus::getStatusLabel($this->item->status);
?>
						</label>
					</td>
				</tr>
			</table>
		</div>

		<div class="col-md-6">
			<table class="table table-condensed table-striped">
				<tr>
					<th>
						<?php 
echo JText::_('COM_REDCORE_PAYMENT_CREATED');
?>
					</th>
Esempio n. 5
0
 /**
  * Generate Payment Log depending on the status
  *
  * @param   array  $paymentLog           Data for payment log storage
  * @param   bool   $updatePaymentStatus  Update Payment Status
  *
  * @return bool
  */
 public static function saveNewPaymentLog($paymentLog, $updatePaymentStatus = true)
 {
     if (empty($paymentLog['payment_id'])) {
         return false;
     }
     // Forcing default set of statuses
     $paymentLog['status'] = RApiPaymentStatus::getStatus($paymentLog['status']);
     // Currency should not be numeric
     if (!empty($paymentLog['currency']) && is_numeric($paymentLog['currency'])) {
         $paymentLog['currency'] = RHelperCurrency::getIsoCode($paymentLog['currency']);
     }
     /** @var RedcoreModelPayment_Log $logModel */
     $logModel = RModelAdmin::getAdminInstance('Payment_Log', array(), 'com_redcore');
     if ($logModel->save($paymentLog)) {
         if ($updatePaymentStatus) {
             self::updatePaymentStatus($paymentLog['payment_id']);
         }
     }
     return true;
 }
Esempio n. 6
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);
 }
Esempio n. 7
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;
 }
Esempio n. 8
0
 /**
  * Create new payment
  *
  * @param   string  $extensionName  Extension name
  * @param   string  $ownerName      Owner name
  * @param   array   $data           Data for the payment
  *
  * @return int|boolean Id of the payment or false
  */
 public function createPayment($extensionName, $ownerName, $data)
 {
     // Is payment new
     $isNew = empty($data['id']);
     // Calculate price
     $data['amount_total'] = (double) $data['amount_original'];
     // Add tax
     if (!empty($data['amount_order_tax'])) {
         $data['amount_total'] += (double) $data['amount_order_tax'];
     }
     // Add shipping
     if (!empty($data['amount_shipping'])) {
         $data['amount_total'] += (double) $data['amount_shipping'];
     }
     // Calculate payment fee
     $paymentFee = $this->getPaymentFee($data['amount_total'], $data['currency']);
     $data['amount_payment_fee'] = $paymentFee;
     $data['amount_total'] += $data['amount_payment_fee'];
     // Set cancel URL
     if (empty($data['url_cancel'])) {
         $data['url_cancel'] = JUri::root() . 'index.php?option=' . $data['extension_name'];
     }
     // Set accept URL
     if (empty($data['url_accept'])) {
         $data['url_accept'] = JUri::root() . 'index.php?option=' . $data['extension_name'];
     }
     // Set sandbox flag
     if (empty($data['sandbox'])) {
         $data['sandbox'] = $this->params->get('sandbox', 0);
     }
     // Set order name
     if (empty($data['order_name'])) {
         $data['order_name'] = $data['order_id'];
     }
     // Set payment name
     if (empty($data['payment_name'])) {
         $data['payment_name'] = $this->paymentName;
     }
     // Set extension name
     if (empty($data['extension_name'])) {
         $data['extension_name'] = $extensionName;
     }
     // Set owner name
     if (empty($data['owner_name'])) {
         $data['owner_name'] = $ownerName;
     }
     // This field sets how many times does the plugin try to get response from Payment Gateway for the transaction status.
     if (!isset($data['retry_counter'])) {
         $data['retry_counter'] = $this->params->get('retry_counter', RBootstrap::getConfig('payment_number_of_payment_check_retries', 30));
     }
     $paymentId = RApiPaymentHelper::updatePaymentData($data);
     if (empty($paymentId)) {
         return false;
     }
     $data['id'] = $paymentId;
     if (empty($data['payment_log'])) {
         $data['payment_log'] = RApiPaymentHelper::generatePaymentLog(RApiPaymentStatus::getStatusCreated(), $data, JText::sprintf('LIB_REDCORE_PAYMENT_LOG_' . ($isNew ? 'CREATE' : 'UPDATE') . '_MESSAGE', $data['extension_name'], $this->paymentName));
     }
     RApiPaymentHelper::saveNewPaymentLog($data['payment_log']);
     return $paymentId;
 }