2011-05-03 85 views
1

我一直把這一段時間,因爲我似乎沒有線索我在做什麼。我正嘗試使用PHP和Curl與Barclaycard ePDQ MPI進行交談。在使用HSBC XML API之前,我已經完成了這個工作,但Barclaycard ePDQ MPI似乎給我帶來了一些麻煩。我有一張表格,可以顯示卡片詳細信息/地址詳細信息以及包含以下功能的頁面請注意,我在域上設置了SSL,服務器上安裝了CURL,我的匯豐XML API工作得很好相同的框/網址。使用PHP和CURL的Barclaycard ePDQ MPI只是不想工作,沒有repsonse,不確定CURL在工作嗎?

<?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請求是錯誤的。請求中沒有返回任何內容。

對不起,這是一個很長的帖子,但這真的是我的頭!

有沒有人做過這個?

+0

你得到什麼狀態碼?(200,404,500)? – Julian 2011-05-04 13:57:46

+0

什麼都不回來!我還沒有看過HTTP頭...... – 2011-05-04 14:58:09

回答

0

你好,經過一番打在這裏是正確的捲曲設置你必須做的......

我意識到變量可以更好地和我應該以此爲對象,但我只想得到一個快速回答那裏。該腳本還需要通過篩選不同的接受和錯誤消息,但是這是我這麼遠......

$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(); 
} 

希望這有助於誰必須設置此別人!

1

我已經設法解決我的問題了。事實證明,到巴克萊網站的CURL連接被服務器上的防火牆阻止,這就是爲什麼我沒有收到錯誤消息。

我修改捲曲碼有點檢查錯誤:

$data = curl_exec($ch); 

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

curl_close ($ch); 

這接着說:無法連接到主機在這一點我試了另一臺服務器上,它經過了這個錯誤。

我現在得到的錯誤是:「沒有足夠的權限來執行請求的操作。」我已經嘗試了所有的賬戶,但是如果我登錄到EPDQ控制面板,我似乎只能分配到EPDQ Level 4和CPI訪問權限,而不提及MPI,即使它說技術支持可以從早上8點到12點,它不是。對於除了最基本的查詢之外的任何事情來說,這只是辦公時間。

使用SagePay有什麼好處? SagePay允許您通過單個交易詳細信息進行發送,而巴克萊銀行只允許您發送應付總金額,而且他們確實在非辦公時間提供支持。

我將網站更改爲MPI的唯一原因是,使用CPI時,客戶可以在返回網站之前關閉瀏覽器,因此訂單詳細信息和發票不會發送,因此無法知道已經發生了什麼購買。

謝謝 羅賓