Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 /**
  * Execute the Api Cancel operation.
  *
  * @return  mixed  RApi object with information on success, boolean false on failure.
  */
 public function apiCancel()
 {
     $app = JFactory::getApplication();
     $payment = $this->getPayment();
     $logData = RApiPaymentHelper::generatePaymentLog(RApiPaymentStatus::getStatusCreated(), $this->requestData, JText::sprintf('LIB_REDCORE_PAYMENT_LOG_CANCEL_MESSAGE', $this->extensionName, $this->paymentName));
     // This method can process data from payment request more if needed
     $app->triggerEvent('onRedpaymentRequestCancel', array($this->paymentName, $this->extensionName, $this->ownerName, $this->requestData, &$logData));
     // Save payment log and do not update change for payment
     RApiPaymentHelper::saveNewPaymentLog($logData);
     $redirect = !empty($payment->url_cancel) ? $payment->url_cancel : JUri::root() . 'index.php?option=' . $payment->extension_name;
     // Redirect to extension Cancel URL
     $app->redirect($redirect);
     $app->close();
 }
Ejemplo n.º 3
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;
 }