2015-03-03 41 views
1

我目前正在爲VirtueMart開發一個付款插件。我以前從未使用過它。我們的目標是:VirtueMart重複訂單

  • 當用戶點擊確認訂單按鈕,他被重定向到銀行接口(管理它,沒有工作需要)
  • 隨後,他被從一個答案重定向到網絡商店銀行(也完成)
  • 如果交易成功,訂單將被存儲爲已確認,或者如果交易失敗,訂單將被取消。

我管理的是在上面的列表中標記的。出於某種原因,訂單被存儲了兩次,一次是用戶點擊按鈕,一次是用戶重定向到商店。另外,如果交易失敗,訂單將被存儲兩次,也是未決的。我重複使用了VirtueMart aio軟件包提供的標準付款插件。以上所有內容均寫在plgVmConfirmedOrder函數中。我會張貼在這裏:

function plgVmConfirmedOrder ($cart, $order) { 

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

    VmConfig::loadJLang('com_virtuemart',true); 
    VmConfig::loadJLang('com_virtuemart_orders', TRUE); 

    if (!class_exists ('VirtueMartModelOrders')) { 
     require(VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'); 
    } 

    $this->getPaymentCurrency($method); 
    $currency_code_3 = shopFunctions::getCurrencyByID($method->payment_currency, 'currency_code_3'); 
    $email_currency = $this->getEmailCurrency($method); 

    $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total,$method->payment_currency); 

    $dbValues['payment_name'] = $this->renderPluginName ($method) . '<br />' . $method->payment_info; 
    $dbValues['order_number'] = $order['details']['BT']->order_number; 
    $dbValues['virtuemart_paymentmethod_id'] = $order['details']['BT']->virtuemart_paymentmethod_id; 
    $dbValues['cost_per_transaction'] = $method->cost_per_transaction; 
    $dbValues['cost_percent_total'] = $method->cost_percent_total; 
    $dbValues['payment_currency'] = $currency_code_3; 
    $dbValues['email_currency'] = $email_currency; 

    $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; 
    $dbValues['tax_id'] = $method->tax_id; 

    $payment_info=''; 
    if (!empty($method->payment_info)) { 
     $lang = JFactory::getLanguage(); 
     if ($lang->hasKey ($method->payment_info)) { 
      $payment_info = vmText::_ ($method->payment_info); 
     } else { 
      $payment_info = $method->payment_info; 
     } 
    } 
    if (!class_exists ('VirtueMartModelCurrency')) { 
     require(VMPATH_ADMIN . DS . 'models' . DS . 'currency.php'); 
    } 
    $currency = CurrencyDisplay::getInstance ('', $order['details']['BT']->virtuemart_vendor_id); 
      if(!array_key_exists("fizetesValasz", $_REQUEST)){ 
       $transaction_id = $this->getTransactionID(); 
       $_REQUEST['tranzakcioAzonosito'] = $transaction_id; 
       $price = $cart->cartPrices['billTotal']; 
       $_REQUEST['osszeg'] = round($price); 
       $_REQUEST['devizanem'] = 'HUF'; 
       $_REQUEST['backURL'] = "http://" . $_SERVER['SERVER_NAME'] . '/component/virtuemart/cart/confirm.html?Itemid=' . $_REQUEST['Itemid']; 
       $_REQUEST['nyelvkod'] = 'hu'; 
       $dbValues['transaction_id'] = $transaction_id; 
       //this is where I redirect to the bank interface 
       process(); 
      } 
      else{ 
       //this is where I get the data about transaction 
       $transaction_datas = processDirectedToBackUrl(false); 
       $status_code = $transaction_datas->getStatuszKod(); 
       $dbValues['otp_response'] = $status_code; 
       $this->storePSPluginInternalData ($dbValues); 
       $modelOrder = VmModel::getModel ('orders'); 
       switch ($status_code) { 
        case 'FELDOLGOZVA': 
         if($transaction_datas->isSuccessful()){ 
          $message = 'Sikeres Tranzakció!'; 

          $new_status = $this->getNewStatus($method); 
          $order['customer_notified'] = 1; 
          $order['comments'] = ''; 
          $modelOrder->updateStatusForOneOrder ($order['details']['BT']->virtuemart_order_id, $order, TRUE); 
          $message = getMessageText(($transaction_datas->getPosValaszkod())); 

          $cart->emptyCart(); 
          $html = $this->renderByLayout('post_payment_success', array(
           'message' =>$message, 
           'order_number' =>$order['details']['BT']->order_number, 
           'order_pass' =>$order['details']['BT']->order_pass, 
           'payment_name' => $dbValues['payment_name'], 
           'displayTotalInPaymentCurrency' => round($totalInPaymentCurrency['display']) 
          )); 

          vRequest::setVar ('html', $html); 
          return TRUE; 
         } 
         else{ 
          $new_status = $method->status_cancelled; 
          $modelOrder->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); 
          $message = 'Sajnos a bank visszautasította a tranzakciót.'; 
          $html = $this->renderByLayout('post_payment_failure', array(
           'message' => $message 

          )); 
          vRequest::setVar('html', $html); 
          return FALSE; 
         } 
         break; 
        case 'VEVOOLDAL_VISSZAVONT': 

         return FALSE; 
         break; 
        case 'VEVOOLDAL_TIMEOUT': 

         return FALSE; 
         break; 
       } 


      } 

      return FALSE; 

} 

每一個幫助表示讚賞。提前致謝!

回答

0

所以,問題是重定向url。有一項行動叫做plgVmOnPaymentResponseReceived()。這是在調用特定網址時觸發的。我只需重寫重定向的$_REQUEST參數。