希腊国家银行的 magento 自定义支付网关

magento custom payment gateway for National Bank Greece

我正在使用 KBariotis 模块将 magento 与希腊国家银行集成。
我什么都试过了,但还是不行。

起初,它不会识别该模块。
所以我在 /model/standard.php 上将 protected $_formBlockType = 'nbp/form_nbp'; 更改为
protected $_formBlockType = 'nbp/form_NBP';

现在它会将其识别为有效的付款选项。
但是在结帐时,它会将我重定向到 /checkout/onepage/failure

编辑:

在代码 model/NBP.php 中,我看到 getRedirectUrl() returns 错误而不是它应该的。这是代码

    <?php
class KBariotis_NBP_Model_NBP extends Mage_Core_Model_Abstract
{

private $proxyPayEndPoint = null;
private $merchantID = null;
private $merchantSecret = null;
private $newOrderStatus = null;
private $pageSetId = null;
private $enable3dSecure = null;


protected function _Construct()
{
    $this->merchantID       = Mage::getStoreConfig('payment/nbp/merchant_id');
    $this->proxyPayEndPoint = Mage::getStoreConfig('payment/nbp/proxy_pay_endpoint');
    $this->merchantSecret   = Mage::getStoreConfig('payment/nbp/merchant_confirmation_pwd');
    $this->pageSetId        = Mage::getStoreConfig('payment/nbp/page_set_id');
    $this->newOrderStatus   = Mage::getStoreConfig('payment/nbp/order_status');
    $this->enable3dSecure   = Mage::getStoreConfig('payment/nbp/enable_3d_secure');
}

public function getRedirectUrl()
{

    $order   = new Mage_Sales_Model_Order();
    $orderId = Mage::getSingleton('checkout/session')
                   ->getLastRealOrderId();
    $order->loadByIncrementId($orderId);
    $orderTotal = $order->getBaseGrandTotal();
    $successUrl = Mage::getUrl('nbp/payment/success/');

    $request = $this->createXMLRequestPreTransaction($orderId, $orderTotal, $successUrl);

    if ($response = $this->makeRequest($request))
        return $response->HpsTxn->hps_url . '?HPS_SessionID=' . $response->HpsTxn->session_id;
    else
        return false;
}

private function createXMLRequestPreTransaction($orderId, $orderTotal, $successUrl)
{
    $request = new SimpleXMLElement("<Request></Request>");
    $request->addAttribute("version", "2");

    $auth = $request->addChild("Authentication");
    $auth->addChild("password", $this->merchantSecret);
    $auth->addChild("client", $this->merchantID);

    $transaction = $request->addChild("Transaction");
    $txnDetails  = $transaction->addChild("TxnDetails");
    $txnDetails
        ->addChild("merchantreference", $orderId);

    if ($this->enable3dSecure) {
        $threeDSecure = $txnDetails->addChild("ThreeDSecure");
        $browser      = $threeDSecure->addChild("Browser");

        $browser->addChild("device_category", 0);
        $browser->addChild("accept_headers", "*/*");
        $browser->addChild("user_agent", "IE/6.0");

        $threeDSecure->addChild("purchase_datetime", date('Ymd H:i:s'));
        $threeDSecure->addChild("purchase_desc", $orderId);
        $threeDSecure->addChild("verify", "yes");

    }

    $txnDetails
        ->addChild("amount", $orderTotal)
        ->addAttribute("currency", "EUR");
    $txnDetails
        ->addChild("capturemethod", "ecomm");

    $hpsTxn = $transaction->addChild("HpsTxn");
    $hpsTxn
        ->addChild("method", "setup_full");
    $hpsTxn
        ->addChild("page_set_id", $this->pageSetId);
    $hpsTxn
        ->addChild("return_url", $successUrl);
    $hpsTxn
        ->addChild("expiry_url", Mage::getUrl(''));

    $cardTxn = $transaction->addChild('CardTxn');
    $cardTxn
        ->addChild("method", "auth");

    return $request;
}

public function queryRefTransaction($ref)
{

    $request = $this->createXMLRequestPostTransaction($ref);

    if ($response = $this->makeRequest($request))
        return $response->merchantreference;

    return false;

}

private function createXMLRequestPostTransaction($ref)
{

    $request = new SimpleXMLElement("<Request></Request>");
    $request->addAttribute("version", "2");

    $auth = $request->addChild("Authentication");
    $auth->addChild("password", $this->merchantSecret);
    $auth->addChild("client", $this->merchantID);

    $transaction = $request->addChild("Transaction");
    $historicTxn = $transaction->addChild("HistoricTxn");
    $historicTxn
        ->addChild("method", "query");
    $historicTxn
        ->addChild("reference", $ref);

    return $request;
}

private function makeRequest($request)
{
    $client = new Varien_Http_Client($this->proxyPayEndPoint);
    $client->setMethod(Zend_Http_Client::POST);
    $client->setRawData($request->asXML());

    $response = $client->request();
    if (!$response->isSuccessful())
        throw new Mage_Payment_Exception('Could not communicate to payment server');        

    $responseBody = $response->getBody();

    $response = simplexml_load_string($responseBody);

    $status = intval($response->status);

    if ($status != 1 && $status != 7)
        Mage::log('Error from the Bank : ' . $responseBody);

    if ($status == 7)
        Mage::log('Bank refused the payment : ' . $responseBody);

    if ($status == 1)
        return $response;

    return false;
}

public function getNewOrderStatus()
{
    return $this->newOrderStatus;
}
}

虽然,你发布这个问题已经 4 个月了,我正在回答。

  1. 检查您的 proxyPayEndPoint 是否正确有效 url。
  2. 应填写页面集 ID。 (您用于验证的现有页面的 ID)。
  3. 如果您启用了 3DSecure,则应该正确填写元素。

$browser->addChild("device_category", 0);

$headers = apache_request_headers(); $browser->addChild("accept_headers", ($headers['Accept']?(string)$headers['Accept']:"*/*")); $browser->addChild("user_agent", (string)$_SERVER['HTTP_USER_AGENT']);

您可以打印 xml 请求 (your_website_url/nbp/payment/redirect/) 并查看响应以及您的结构中可能缺少的内容。