Paypal emails before payment not sent

If you are runnig Joomla 3.x and Virtuemart 3.x please post to this forum your questions or support tickets about One Page Checkout

Paypal emails before payment not sent

Postby admin » Wed Jan 03, 2018 4:05 pm

in the latest VM there is no "pending" status for user emails and thus every payment plugin should include it's defualt status update from within plgVmConfirmedOrder function.

to update paypal core plugin in vm3.2.12 to send emails before the redirect you may want to adjust it's core file in:

\plugins\vmpayment\paypal\paypal.php

whole updated function in vm3.2.12 should look like this
Code: Select all
/**
    *
    * @param $cart
    * @param $order
    * @return bool|null|void
    */
   function plgVmConfirmedOrder($cart, $order) {

      if (!($this->_currentMethod = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
         return NULL; // Another method was selected, do nothing
      }
      if (!$this->selectedThisElement($this->_currentMethod->payment_element)) {
         return FALSE;
      }

      if (!class_exists('VirtueMartModelOrders')) {
         require(VMPATH_ADMIN . DS . 'models' . DS . 'orders.php');
      }
      if (!class_exists('VirtueMartModelCurrency')) {
         require(VMPATH_ADMIN . DS . 'models' . DS . 'currency.php');
      }
      $html='';
      $this->_currentMethod->payment_currency = $this->getPaymentCurrency($this->_currentMethod,$order['details']['BT']->payment_currency_id);
      //$this->_currentMethod->payment_currency=$order['details']['BT']->user_currency_id;
      $email_currency = $this->getEmailCurrency($this->_currentMethod);

      $payment_name = $this->renderPluginName($this->_currentMethod, $order);

      $paypalInterface = $this->_loadPayPalInterface();

      $paypalInterface->debugLog('order number: ' . $order['details']['BT']->order_number, 'plgVmConfirmedOrder', 'debug');
      $paypalInterface->setCart($cart);
      $paypalInterface->setOrder($order);

      $paypalInterface->setTotal($order['details']['BT']->order_total);
      $paypalInterface->loadCustomerData();


      // Prepare data that should be stored in the database
      $dbValues['order_number'] = $order['details']['BT']->order_number;
      $dbValues['payment_name'] = $payment_name;
      $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id;
      $dbValues['paypal_custom'] = $paypalInterface->getContext();
      $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction;
      $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total;
      $dbValues['payment_currency'] = $this->_currentMethod->payment_currency;
      $dbValues['email_currency'] = $email_currency;
      $dbValues['payment_order_total'] = $paypalInterface->getTotal();
      $dbValues['tax_id'] = $this->_currentMethod->tax_id;
      $this->storePSPluginInternalData($dbValues);
      vmLanguage::loadJLang('com_virtuemart_orders', TRUE);

      $paypalInterface->debugLog('Amount/Currency stored ' . $dbValues['payment_order_total'].' paymentcurrency '.$dbValues['payment_currency'].' orderusercurrency'.$order['details']['BT']->user_currency_id, 'plgVmConfirmedOrder', 'message');

      
      /*stAn - if our status is configured to send emails we must use it before the redirect*/
      $order['order_status'] = $this->_currentMethod->status_pending;
      $order['customer_notified'] = 1;
      $orderModel = VmModel::getModel('orders');
      $orderModel->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, FALSE);
      
      
      if ($this->_currentMethod->paypalproduct == 'std') {
         $html = $paypalInterface->ManageCheckout();
         //    2 = don't delete the cart, don't send email and don't redirect
         $cart->_confirmDone = FALSE;
         $cart->_dataValidated = FALSE;
         $cart->setCartIntoSession();
         vRequest::setVar('html', $html);

      } else {
         if ($this->_currentMethod->paypalproduct == 'exp') {
            $success = $paypalInterface->ManageCheckout();
            $response = $paypalInterface->getResponse();

         $payment = $this->_storePaypalInternalData(  $response, $order['details']['BT']->virtuemart_order_id, $cart->virtuemart_paymentmethod_id, $order['details']['BT']->order_number);

            if ($success) {
               $new_status = $paypalInterface->getNewOrderStatus();

               if ($this->_currentMethod->payment_type == '_xclick-subscriptions' || $this->_currentMethod->payment_type == '_xclick-payment-plan') {
                  $profilesuccess = $paypalInterface->GetRecurringPaymentsProfileDetails($response['PROFILEID']);
                  $response = $paypalInterface->getResponse();
               $this->_storePaypalInternalData(  $response, $order['details']['BT']->virtuemart_order_id, $cart->virtuemart_paymentmethod_id, $order['details']['BT']->order_number);
               }
               $this->customerData->clear();
               $returnValue = 1;
               $html = $this->renderByLayout('expresponse',
                  array("method" => $this->_currentMethod,
                     "success" => $success,
                     "payment_name" => $payment_name,
                     "response" => $response,
                     "order" => $order));
               $cart->BT=0;
               $cart->ST=0;
               $cart->setCartIntoSession();
               return $this->processConfirmedOrderPaymentResponse($returnValue, $cart, $order, $html, $payment_name, $new_status);
            } else {
               $new_status = $this->_currentMethod->status_canceled;
               $returnValue = 2;
               $cart->virtuemart_paymentmethod_id = 0;
               $cart->setCartIntoSession();
               $this->customerData->clear();
               VmInfo('VMPAYMENT_PAYPAL_PAYMENT_NOT_VALID');
               $paypalInterface->debugLog($response, 'plgVmConfirmedOrder, response:', 'error');

               $app = JFactory::getApplication();
               $app->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&Itemid=' . vRequest::getInt('Itemid'), false));
            }


         } else {
            if ($this->_currentMethod->paypalproduct == 'api') {
               $this->setInConfirmOrder($cart);

               $success = $paypalInterface->ManageCheckout();
               $response = $paypalInterface->getResponse();
         $payment = $this->_storePaypalInternalData(  $response, $order['details']['BT']->virtuemart_order_id, $cart->virtuemart_paymentmethod_id, $order['details']['BT']->order_number);
               if ($success) {
                  if ($this->_currentMethod->payment_action == 'Authorization' || $this->_currentMethod->payment_type == '_xclick-payment-plan') {
                     $new_status = $this->_currentMethod->status_pending;
                  } else {
                     $new_status = $this->_currentMethod->status_success;
                  }
                  if ($this->_currentMethod->payment_type == '_xclick-subscriptions' || $this->_currentMethod->payment_type == '_xclick-payment-plan') {
                     $profilesuccess = $paypalInterface->GetRecurringPaymentsProfileDetails($response['PROFILEID']);
                     $response = $paypalInterface->getResponse();
               $this->_storePaypalInternalData(  $response, $order['details']['BT']->virtuemart_order_id, $cart->virtuemart_paymentmethod_id, $order['details']['BT']->order_number);
                  }
                  $this->customerData->clear();
                  $returnValue = 1;
               } else {
                  $cart->virtuemart_paymentmethod_id = 0;
                  $cart->setCartIntoSession();
                  $this->redirectToCart();
                  return;
               }
//         $this->customerData->clear();
               $html = $this->renderByLayout('apiresponse', array('method' => $this->_currentMethod, 'success' => $success, 'payment_name' => $payment_name, 'responseData' => $response, "order" => $order));
               return $this->processConfirmedOrderPaymentResponse($returnValue, $cart, $order, $html, $payment_name, $new_status);
            } else {
               if ($this->_currentMethod->paypalproduct == 'hosted') {
                  $paypalInterface->ManageCheckout();
                  if ($this->_currentMethod->template == 'templateD') {
                     jimport('joomla.environment.browser');
                     $browser = JBrowser::getInstance();


                     // this code is only called incase of iframe (templateD), in all other cases redirecttopayapl has been done
                     $html = $this->renderByLayout('hostediframe', array("url" => $paypalInterface->response['EMAILLINK'],
                        "isMobile" => $browser->isMobile()
                     ));
                  }
                  //    2 = don't delete the cart, don't send email and don't redirect
                  $cart->_confirmDone = FALSE;
                  $cart->_dataValidated = FALSE;
                  $cart->setCartIntoSession();
                  vRequest::setVar('html', $html);
               } else {
                  vmError('Unknown Paypal mode');
               }
            }
         }
      }
   }



the above function got this new lines:

Code: Select all

/*stAn - if our status is configured to send emails we must use it before the redirect*/
      $order['order_status'] = $this->_currentMethod->status_pending;
      $order['customer_notified'] = 1;
      $orderModel = VmModel::getModel('orders');
      $orderModel->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, FALSE);



which should be used by other plugins as well to set the default order status before any payment action.

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 3 on Joomla 3.x

cron