【问题标题】:Barclaycard ePDQ MPI using PHP & CURL just doesn't want to work, no repsonse, not sure CURL is working?使用 PHP 和 CURL 的 Barclaycard ePDQ API 只是不想工作,没有响应,不确定 CURL 是否工作?
【发布时间】:2011-05-03 19:47:59
【问题描述】:

我已经推迟了一段时间,因为我似乎不知道我在做什么。我正在尝试使用 PHP 和 Curl 与 Barclaycard ePDQ MPI 对话。我在使用 HSBC XML API 之前已经这样做了,但是 Barclaycard ePDQ MPI 似乎让我有些头疼。我有一个表单,其中发布卡详细信息/地址详细信息以及包含以下功能的页面 请注意,我在域上设置了 SSL,在服务器上安装了 CURL,我让 HSBC XML API 工作得很好相同的框/URL。

<?php
    function process_card($users_ip, $Temp_Order_ID, $User_NameX, $First_Name, $Surname, $Address_Line1, $Address_Line2, $Town, $Country, $Postcode, $CardNumber, $CardExpiryDate, $issue_node, $CardCVV, $totalCost ) {

    if ($CardCVV == "")
        $cvvindicator = 0;
    else
        $cvvindicator=1;

    global $status;
    //$amount = $amount * 100;

        $xml = '
    <?XML version="1.0" encoding="UTF-8"?>
    <EngineDocList>
        <DocVersion>1.0</DocVersion>
        <EngineDoc>
        <IPAddress>' . $users_ip . '</IPAddress>
            <ContentType>OrderFormDoc</ContentType>
            <User>
                <Name>XXXXX</Name>
                <Password>XXXXXXX</Password>
                <ClientId DataType="S32">12345</ClientId>
            </User>
            <Instructions>
                <Pipeline>Payment</Pipeline>
            </Instructions>
            <OrderFormDoc>
                <Mode>T</Mode>
                <Id>' . $Temp_Order_ID. '</Id>
                <Consumer>
                    <Email>' . $User_NameX . '</Email>
                    <BillTo>
                        <Location>
                            <Address>
                                <FirstName>' . $First_Name . '</FirstName>
                                <LastName>' . $Surname .'</LastName>
                                <Street1>' . $Address_Line1 . '</Street1>
                                <Street2>' . $Address_Line2 . '</Street2>
                                <Street3></Street3>
                                <City>' . $Town . '</City>
                                <StateProv>' . $Country . '</StateProv>
                                <PostalCode>' . $Postcode . '</PostalCode>
                                <Country>' . getCuntCode($Country) . '</Country>
                            </Address>
                        </Location>
                    </BillTo>
                    <ShipTo>
                        <Location>
                            <Address>
                                <FirstName>' . $First_Name . '</FirstName>
                                <LastName>' . $Surname .'</LastName>
                                <Street1>' . $Address_Line1 . '</Street1>
                                <Street2>' . $Address_Line2 . '</Street2>
                                <Street3></Street3>
                                <City>' . $Town . '</City>
                                <StateProv>' . $Country . '</StateProv>
                                <PostalCode>' . $Postcode . '</PostalCode>
                                <Country>' . getCuntCode($Country) . '</Country>
                            </Address>
                        </Location>
                    </ShipTo>
                    <PaymentMech>
                        <CreditCard>
                            <Type DataType="S32">1</Type>
                            <Number>' . $CardNumber . '</Number>
                            <Expires DataType="ExpirationDate" Locale="826">' . $CardExpiryDate . '</Expires>
                            ' . $issue_node . ' 
                            <Cvv2Indicator>' . $cvvindicator . '</Cvv2Indicator>
                            <Cvv2Val>' . $CardCVV . '</Cvv2Val>
                        </CreditCard>
                    </PaymentMech>
                </Consumer>
                <Transaction>
                    <Type>Auth</Type>
                    <CurrentTotals>
                        <Totals>
                            <Total DataType="Money" Currency="826">' . $totalCost . '</Total>
                        </Totals>
                    </CurrentTotals>
                    <CardholderPresentCode DataType="S32"></CardholderPresentCode>
                    <PayerSecurityLevel DataType="S32"></PayerSecurityLevel>
                    <PayerAuthenticationCode></PayerAuthenticationCode>
                    <PayerTxnId></PayerTxnId>
                </Transaction>
            </OrderFormDoc>
        </EngineDoc>
    </EngineDocList>';

        $url = "https://secure2.epdq.co.uk:11500";

        $params = array("CLRCMRC_XML" => $xml);
        $params = formatData($params);

        $response = post_to_epdq($url, $xml);   
        $auth_code = strstr($response, "<AuthCode>");

        echo "auth_code=" . $auth_code;

        if ($auth_code <> "") {

            $splt = split("</AuthCode>", $auth_code);
            $status = strip_tags($splt[0]);
            return $xml . "<hr/>" . $response . "Good";
        } else {

            $error = strstr($response, "<Text>");
            $splt = split("</Text>", $error);
            $status = strip_tags($splt[0]);
            return $xml . "<hr/>" . $response . "Bad";

        }
    }

    function post_to_epdq($url, $data) {


        set_time_limit(120);
        $output = array();
        $curlSession = curl_init();
        curl_setopt($curlSession, CURLOPT_URL, $url);
        curl_setopt($curlSession, CURLOPT_PORT, 443);
        curl_setopt($curlSession, CURLOPT_HEADER, 0);
        curl_setopt($curlSession, CURLOPT_POST, 1);
        curl_setopt($curlSession, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curlSession, CURLOPT_TIMEOUT, 60);
        #$response = split(chr(10),curl_exec ($curlSession));

        $response = curl_exec($curlSession);

        if (curl_error($curlSession)) {
            $this->error = curl_error($curlSession);
            return "ERROR";
        }

        curl_close($curlSession);
        return $response;
    }

    function formatData($data) {

        $output = "";
        foreach ($data as $key => $value)
            $output .= "&" . $key . "=" . urlencode($value);
            $output = substr($output, 1);
            return $output;
    }

不用说我验证用户输入,生成他们的 IP 并确定一个国家代码,然后我调用上面的函数:

process_card($users_ip,$Temp_Order_ID,$User_NameX,$First_Name,$Surname,$Address_Line1,$Address_Line2,$Town,$Country,$Postcode,$CardNumber, $CardExpiryDate, $issue_node, $CardCVV, $totalCost );

我没有得到回应?我不确定端口和 url 项目是否不正确,或者整个 CURL 请求是否错误。请求没有返回任何内容。

很抱歉这篇文章很长,但这真的让我很头疼!

以前有人做过吗?

【问题讨论】:

  • 你得到什么状态码? (200、404、500)?
  • 什么都没有,绝对什么都不会回来!我还没有查看 HTTP 标头...

标签: php curl


【解决方案1】:

我现在已经设法解决了我的问题。事实证明,与 Barclays 网站的 CURL 连接被服务器上的防火墙阻止,这就是我没有收到任何错误消息的原因。

我稍微修改了 CURL 代码以检查错误:

$data = curl_exec($ch); 

if(curl_errno($ch)) {
    print curl_error($ch);  
}

curl_close ($ch); 

然后说:无法连接到主机,此时我在另一台服务器上尝试了它,它克服了这个错误。

我现在得到的错误是:“权限不足,无法执行请求的操作。”我已经尝试了我获得的所有帐户,但如果我登录 EPDQ 控制面板,我似乎只能分配 EPDQ 级别 4 和 CPI 访问权限,而没有提及 MPI,即使它说技术支持可从早上 8 点到晚上 12 点,不是。除了最基本的查询之外,这实际上只是办公时间。

与 SagePay 相比,使用它有什么优势吗? SagePay 允许您发送个人交易详细信息,而 Barclays 只允许您发送应付总金额,而且他们确实提供非办公时间的支持。

我将网站更改为 MPI 的唯一原因是,使用 CPI,客户可以在返回网站之前关闭浏览器,因此不会发送订单详细信息和发票,因此无法知道购买了什么.

谢谢 罗宾

【讨论】:

    【解决方案2】:

    你好,在玩了一些之后,这里是你必须做的正确 CURL 设置......

    我意识到变量可能会更好,我应该把它作为一个对象,但我只是想在那里得到一个快速的答案。该脚本还需要筛选不同的接受和错误消息,但这是我到目前为止所得到的......

    $ch = curl_init();
    $url = "https://secure2.epdq.co.uk:11500"; // Don't need to add curl_setopt($curlSession, CURLOPT_PORT, 443); as port is included
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); // $vars is your XML 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    
    $data = curl_exec($ch);
    curl_close ($ch);
    
    $xml = new domDocument;
    $xml->loadXML($data);
    
    if (!$xml) {
        echo 'Error while parsing the document - Please Contact to determine if payment has gone though';
        exit;
    }
    
    $x = $xml->getElementsByTagName( "CcErrCode" );
    $approved = $x->item(0)->nodeValue;
    
    $xx = $xml->getElementsByTagName( "CcReturnMsg" );
    $CcReturnMsg = $xx->item(0)->nodeValue;
    
    if($approved) {
    
    // the card is valid.
        $y = $xml->getElementsByTagName( "Id" );
        $BCardId = $y->item(1)->nodeValue;
    
        $z = $xml->getElementsByTagName( "MessageList" );
        $MessageList = $z->item(0)->nodeValue;
    
        $zz = $xml->getElementsByTagName( "AvsRespCode" );
        $AvsRespCode = $zz->item(0)->nodeValue;
    
        $zzz = $xml->getElementsByTagName( "AvsDisplay" );
        $AvsDisplay = $zzz->item(0)->nodeValue;
    
        $zzzz = $xml->getElementsByTagName( "ProcReturnMsg" );
        $ProcReturnMsg = $zzzz->item(0)->nodeValue;
    
         if($approved == "1"){
           echo "approved!<br />";
           echo "BCardId: " . $BCardId . ", MessageList=" . $MessageList . ", " . $AvsRespCode . ", " . $AvsDisplay . ", " . $ProcReturnMsg;
           die();
         }else{
           // raise that it's been partially accepted, 
           echo "partially approved";
           echo "BCardId: " . $BCardId . ", MessageList=" . $MessageList . ", " . $AvsRespCode . ", " . $AvsDisplay . ", " . $ProcReturnMsg;
           die();
         }
    
    }else{
       echo "you have been completely knocked back";
       $zzzzz = $xml->getElementsByTagName( "Text" );
       $BCard_Text = $zzzzz->item(0)->nodeValue;
       echo "The reason:" . $BCard_Text;    
       die();
    }
    

    希望这可以帮助其他需要设置的人!

    【讨论】:

      猜你喜欢
      • 2011-08-12
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 1970-01-01
      相关资源
      最近更新 更多