1

我目前正在为 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;

}

感谢您的每一次帮助。提前致谢!

4

1 回答 1

0

所以,问题是重定向网址。有一个动作叫plgVmOnPaymentResponseReceived()。当调用特定的 url 时会触发此事件。我只需要重写$_REQUEST重定向参数。

于 2015-03-10T09:06:00.700 回答