【问题标题】:First data payment gateway integration soap fault error第一个数据支付网关集成soap故障错误
【发布时间】:2013-04-19 00:41:28
【问题描述】:

您好,我正在尝试使用 php 将 First 数据支付网关集成集成到 soap 请求方法中。我已经从第一个数据中下载了工作示例代码,但是当我尝试使用他们提供的示例代码提交付款时,我会报错。

整个php代码是

<?php


class SoapClientHMAC extends SoapClient {
  public function __doRequest($request, $location, $action, $version, $one_way = NULL) {
    global $context;
    $hmackey = "***********************"; // <-- Insert your HMAC key here
    $keyid = "*****"; // <-- Insert the Key ID here
    $hashtime = date("c");
    $hashstr = "POST\ntext/xml; charset=utf-8\n" . sha1($request) . "\n" . $hashtime . "\n" . parse_url($location,PHP_URL_PATH);
    $authstr = base64_encode(hash_hmac("sha1",$hashstr,$hmackey,TRUE));
    if (version_compare(PHP_VERSION, '5.3.11') == -1) {
        ini_set("user_agent", "PHP-SOAP/" . PHP_VERSION . "\r\nAuthorization: GGE4_API " . $keyid . ":" . $authstr . "\r\nx-gge4-date: " . $hashtime . "\r\nx-gge4-content-sha1: " . sha1($request));
    } else {
        stream_context_set_option($context,array("http" => array("header" => "authorization: GGE4_API " . $keyid . ":" . $authstr . "\r\nx-gge4-date: " . $hashtime . "\r\nx-gge4-content-sha1: " . sha1($request))));
    }
    return parent::__doRequest($request, $location, $action, $version, $one_way);
  }

  public function SoapClientHMAC($wsdl, $options = NULL) {
    global $context;
    $context = stream_context_create();
    $options['stream_context'] = $context;
    return parent::SoapClient($wsdl, $options);
  }
}

$trxnProperties = array(
  "User_Name"=>"",
  "Secure_AuthResult"=>"",
  "Ecommerce_Flag"=>"",
  "XID"=>"",
  "ExactID"=>$_POST["ddlPOS_ExactID"],                  //Payment Gateway
  "CAVV"=>"",
  "Password"=>"********",                                   //Gateway Password
  "CAVV_Algorithm"=>"",
  "Transaction_Type"=>$_POST["ddlPOS_Transaction_Type"],//Transaction Code I.E. Purchase="00" Pre-Authorization="01" etc.
  "Reference_No"=>$_POST["tbPOS_Reference_No"],
  "Customer_Ref"=>$_POST["tbPOS_Customer_Ref"],
  "Reference_3"=>$_POST["tbPOS_Reference_3"],
  "Client_IP"=>"",                                      //This value is only used for fraud investigation.
  "Client_Email"=>$_POST["tb_Client_Email"],            //This value is only used for fraud investigation.
  "Language"=>$_POST["ddlPOS_Language"],                //English="en" French="fr"
  "Card_Number"=>$_POST["tbPOS_Card_Number"],           //For Testing, Use Test#s VISA="4111111111111111" MasterCard="5500000000000004" etc.
  "Expiry_Date"=>$_POST["ddlPOS_Expiry_Date_Month"] . $_POST["ddlPOS_Expiry_Date_Year"],//This value should be in the format MM/YY.
  "CardHoldersName"=>$_POST["tbPOS_CardHoldersName"],
  "Track1"=>"",
  "Track2"=>"",
  "Authorization_Num"=>$_POST["tbPOS_Authorization_Num"],
  "Transaction_Tag"=>$_POST["tbPOS_Transaction_Tag"],
  "DollarAmount"=>$_POST["tbPOS_DollarAmount"],
  "VerificationStr1"=>$_POST["tbPOS_VerificationStr1"],
  "VerificationStr2"=>"",
  "CVD_Presence_Ind"=>"",
  "Secure_AuthRequired"=>"",
  "Currency"=>"",
  "PartialRedemption"=>"",

  // Level 2 fields 
  "ZipCode"=>$_POST["tbPOS_ZipCode"],
  "Tax1Amount"=>$_POST["tbPOS_Tax1Amount"],
  "Tax1Number"=>$_POST["tbPOS_Tax1Number"],
  "Tax2Amount"=>$_POST["tbPOS_Tax2Amount"],
  "Tax2Number"=>$_POST["tbPOS_Tax2Number"],

  //"SurchargeAmount"=>$_POST["tbPOS_SurchargeAmount"], //Used for debit transactions only
  //"PAN"=>$_POST["tbPOS_PAN"]                          //Used for debit transactions only
  );


$client = new SoapClientHMAC("https://api.demo.globalgatewaye4.firstdata.com/transaction/v12/wsdl");
$trxnResult = $client->SendAndCommit($trxnProperties);


if(@$client->fault){
    // there was a fault, inform
    print "<B>FAULT:  Code: {$client->faultcode} <BR />";
    print "String: {$client->faultstring} </B>";
    $trxnResult["CTR"] = "There was an error while processing. No TRANSACTION DATA IN CTR!";
}
//Uncomment the following commented code to display the full results.

echo "<H3><U>Transaction Properties BEFORE Processing</U></H3>";
echo "<TABLE border='0'>\n";
echo " <TR><TD><B>Property</B></TD><TD><B>Value</B></TD></TR>\n";
foreach($trxnProperties as $key=>$value){
    echo " <TR><TD>$key</TD><TD>:$value</TD></TR>\n";
}
echo "</TABLE>\n";

echo "<H3><U>Transaction Properties AFTER Processing</U></H3>";
echo "<TABLE border='0'>\n";
echo " <TR><TD><B>Property</B></TD><TD><B>Value</B></TD></TR>\n";
foreach($trxnResult as $key=>$value){
    $value = nl2br($value);
    echo " <TR><TD valign='top'>$key</TD><TD>:$value</TD></TR>\n";
}
echo "</TABLE>\n";


// kill object
unset($client);
?>

当我提交付款时,我的页面来到了这个特定的代码,它抛出的错误是

 Fatal error: Uncaught SoapFault exception: [HTTP] in C:\wamp\www\Fd\php\process.php:49 Stack trace: #0 C:\wamp\www\Fd\php\process.php(49): SoapClient->__doRequest('<?xml version="...', 'https://api.dem...', 'http://secure2....', 1, 0) #1 [internal function]: SoapClientHMAC->__doRequest('<?xml version="...', 'https://api.dem...', 'http://secure2....', 1, 0) #2 C:\wamp\www\Fd\php\process.php(104): SoapClient->__call('SendAndCommit', Array) #3 C:\wamp\www\Fd\php\process.php(104): SoapClientHMAC->SendAndCommit(Array) #4 {main} thrown in C:\wamp\www\Fd\php\process.php on line 48.

第48行是

return parent::__doRequest($request, $location, $action, $version, $one_way);

我无法真正弄清楚这个错误是什么。谷歌搜索并尝试了各种解决方案,但没有成功。如果有帮助的话,我在我的 php 服务器中同时启用了 soap 和 openssl。

提前感谢您的帮助。

【问题讨论】:

    标签: php soap payment-gateway hmac firstdata


    【解决方案1】:
    $client = new SoapClientHMAC("https://api.demo.globalgatewaye4.firstdata.com/transaction/v12/wsdl");
    

    删除“.demo”=>“https://api.globalgatewaye4.firstdata.com/transaction/v12/wsdl

    您在 api first data 中使用实时访问

    【讨论】:

      【解决方案2】:

      有点太晚了,但无论如何......只是转储那些垃圾 SOAP 代码,这是我早期的 JSON 和 CURL 版本

      <?php
      
      class FirstData
      {
              protected $host = "api.demo.globalgatewaye4.firstdata.com";
              protected $protocol = "https://";
              protected $uri = "/transaction/v12";
      
              /*Modify this acording to your firstdata api stuff*/
              protected $hmackey = "XXXXXXXXXXXXXXXXXXXXXXX";
              protected $keyid = "XXXXX";
              protected $gatewayid = "XX000-00";
              protected $password = "XXXXXXX";
      
      
              public function request()
              {
                      $location = $this->protocol . $this->host . $this->uri;
                      $request = array(
                              'transaction_type' => "00",
                              'amount' => 10.00,
                              'cc_expiry' => "0415",
                              'cc_number' => '4111111111111111',
                              'cardholder_name' => 'Test',
                              'reference_no' => '23',
                              'customer_ref' => '11',
                              'reference_3' => '234',
                              'gateway_id' => $this->gatewayid,
                              'password' => $this->password,
                      );
      
                      $content = json_encode($request);
      
                      var_dump($content);
      
                      $gge4Date = strftime("%Y-%m-%dT%H:%M:%S", time()) . 'Z';
                      $contentType = "application/json";
                      $contentDigest = sha1($content);
                      $contentSize = sizeof($content);
                      $method = "POST";
      
                      $hashstr = "$method\n$contentType\n$contentDigest\n$gge4Date\n$this->uri";
      
                      $authstr = 'GGE4_API ' . $this->keyid . ':' . base64_encode(hash_hmac("sha1", $hashstr, $this->hmackey, true));
      
      
                      $headers = array( 
                              "Content-Type: $contentType",
                              "X-GGe4-Content-SHA1: $contentDigest",
                              "X-GGe4-Date: $gge4Date",
                              "Authorization: $authstr",
                              "Accept: $contentType"
                      );
      
                      //Print the headers we area sending
                      var_dump($headers);
      
      
                      //CURL stuff
                      $ch = curl_init();
                      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                      curl_setopt($ch, CURLOPT_URL, $location);
      
                      //Warning ->>>>>>>>>>>>>>>>>>>>
                      /*Hardcoded for easier implementation, DO NOT USE THIS ON PRODUCTION!!*/
                      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
                      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                      //Warning ->>>>>>>>>>>>>>>>>>>>
      
                      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                      curl_setopt($ch, CURLOPT_VERBOSE, 0);
                      curl_setopt($ch, CURLOPT_HEADER, 1);
      
                      curl_setopt($ch, CURLOPT_POST, 1);
                      curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
      
                      //This guy does the job
                      $output = curl_exec($ch);
      
                      //echo curl_error($ch); 
                      $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
                      $header = $this->parseHeader(substr($output, 0, $header_size));
                      $body = substr($output, $header_size);
      
                      curl_close($ch);
                      //Print the response header
                      var_dump($header);
      
                      /* If we get any of this X-GGe4-Content-SHA1 X-GGe4-Date Authorization
                       * then the API call is valid */
                      if (isset($header['authorization']))
                      {
                              //Ovbiously before we do anything we should validate the hash
                              var_dump(json_decode($body));
                      }
                      //Otherwise just debug the error response, which is just plain text
                      else
                      {
                              echo $body;
                      }
              }
      
              private function parseHeader($rawHeader)
              {
                      $header = array();
      
                      //http://blog.motane.lu/2009/02/16/exploding-new-lines-in-php/
                      $lines = preg_split('/\r\n|\r|\n/', $rawHeader);
      
                      foreach ($lines as $key => $line)
                      {
                              $keyval = explode(': ', $line, 2);
      
                              if (isset($keyval[0]) && isset($keyval[1]))
                              {
                                      $header[strtolower($keyval[0])] = $keyval[1];
                              }
                      }
      
                      return $header;
              }
      }
      
      $firstdata = new FirstData();
      
      $firstdata->request();
      

      【讨论】:

      • 你能帮我告诉如何/从哪里得到 $hmack_key 和 $key_id 吗? @KukoBits
      • 您是如何找到所有 JSON 变量的名称的?我在任何地方都找不到这方面的文档??
      • 在这里找到 JSON 变量列表,这对谁有帮助! (firstdata.zendesk.com/entries/…)
      • 您可以在以下位置找到 hmack_key 和 key_id。登录到您的 firstData 帐户后,转到 HOME 页面(默认页面),查找 TERMINALS,它是右侧的侧链接,单击它,然后选择一个终端(我有 3 个,因为我处于演示模式,所以我刚刚选择了零售),然后单击 API-ACCESS 选项卡,它是出现的众多选项卡之一。 Key_Id在哪里会很明显,只需要生成hMac Key即可。忽略 hmac 签名计算器,不需要它,因为上面的代码已经为您处理了。如果这有帮助,请点赞。
      • 只要确保你的变量没有用引号括起来。否则,此代码(带有@dhavald 的日期修复)对我有用。
      【解决方案3】:

      我尝试了 SOAP 没有成功,最后不得不切换到 JSON。 @KukoBit 的回答对我有用。唯一的问题是 GMT 中预期的日期字符串。我通过如下计算日期来解决它:

      $gge4Date = strftime("%Y-%m-%dT%H:%M:%S", time() - (int) substr(date('O'), 0, 3)*60*60) . 'Z';
      

      希望这会有所帮助。

      ps。我知道这应该是评论,但由于积分限制,我不能。

      【讨论】:

      • 使用 gmdate() 代替,它将始终返回 GMT 时间(无论您当前的时区如何)。 gmdate('c')
      【解决方案4】:

      提醒那些不断收到“未经授权的请求”的人。凭证错误或丢失。 .

      确保您没有将 PRODUCTION 凭据用于演示环境。他们不会工作。别再拔头发了:)
      你所要做的就是,转到

      https://firstdata.zendesk.com/entries/21510561-first-data-global-gateway-e4sm-demo-accounts

      注册免费演示。您将生成您的 hmac,并在那里获取您的其他数据,就像您在生产中一样。

      【讨论】:

      • 你的预测是一样的。我正在使用生产凭据。像魅力一样工作。谢谢
      猜你喜欢
      • 2019-06-27
      • 2017-04-09
      • 2012-11-11
      • 1970-01-01
      • 2011-05-05
      • 2019-02-21
      • 2020-04-16
      • 2016-02-02
      • 2012-05-21
      相关资源
      最近更新 更多