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

时间:2016-06-06 18:50:01

标签: php magento payment-gateway payment

我正在使用KBariotis模块将magento与希腊国家银行整合 我尝试了一切,但它没有工作
首先,它不会识别该模块 所以我将/model/standard.php上的protected $_formBlockType = 'nbp/form_nbp';更改为
protected $_formBlockType = 'nbp/form_NBP';

现在它将其视为有效的付款选项 但在结账时,它会将我重定向到/ checkout / onepage / failure

编辑:

在代码模型/ NBP.php中,我看到getRedirectUrl()返回false而不是它应该返回的内容。这是代码

    <?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;
}
}

1 个答案:

答案 0 :(得分:0)

虽然,自从你发表这个问题以来,我已经回答了4个月。

  1. 检查您的proxyPayEndPoint是否是正确的有效网址。
  2. 应填写页面集ID。 (您用于验证的现有页面的ID)。
  3. 如果您启用了3DSecure,则应正确填充元素。
  4. $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/)并查看响应以及结构中可能缺少的内容。