尝试将tranzila付款网关集成到我的php项目中,并在上线之前使用本地主机上的虚拟信用卡号进行测试。我从tranzila官方文档中获取了php代码。 下面给出的代码
`
$tranzila_api_host = 'secure5.tranzila.com';
$tranzila_api_path = '/cgi-bin/tranzila71u.cgi';
// Prepare transaction parameters
$query_parameters['supplier'] = 'TERMINAL_NAME'; // 'TERMINAL_NAME' should be replaced by actual terminal name
$query_parameters['sum'] = '45'; // Transaction sum
$query_parameters['currency'] = '1'; // Type of currency 1 NIS, 2 USD, 978 EUR, 826 GBP, 392 JPY
$query_parameters['ccno'] = '12312312'; // Test card number
$query_parameters['expdate']= '0820'; // Card expiry date: mmyy
$query_parameters['myid'] = '12312312'; // ID number if required
$query_parameters['mycvv'] = '123'; // number if required
$query_parameters['cred_type'] = '1'; // This field specifies the type of transaction, 1 - normal transaction, 6 - credit, 8 - payments
// $query_parameters['TranzilaPW'] = 'TranzilaPW' ;
$query_string = '' ;
foreach($query_parameters as $name => $value) {
$query_string .= $name.'='.$value.'&' ;
}
$query_string = substr($query_string , 0 , - 1 ) ; // Remove trailing '&'
// Initiate CURL
$cr = curl_init();
curl_setopt($cr,CURLOPT_URL ,"https://$tranzila_api_host$tranzila_api_path");
curl_setopt($cr,CURLOPT_POST,1);
curl_setopt($cr,CURLOPT_FAILONERROR,true);
curl_setopt($cr,CURLOPT_POSTFIELDS,$query_string) ;
curl_setopt($cr,CURLOPT_RETURNTRANSFER,1);
curl_setopt($cr,CURLOPT_SSL_VERIFYPEER,0);
// Execute request
$result = curl_exec($cr);
$error = curl_error($cr);
if(!empty($error)){
die( $error );
}
curl_close ($cr);
// Preparing associative array with response data
$response_array = explode('&',$result);
$response_assoc = array();
if(count($response_array) > 1){
foreach($response_array as $value){
$tmp = explode('=',$value);
if (count($tmp) > 1 ){
$response_assoc [$tmp[0]] = $tmp[1];
}
}
}
// Analyze the result string
if(!isset($response_assoc['Response'])){
die($result."\n");
/**
* When there is no 'Response' parameter it either means
* that some pre-transaction error happened (like authentication
* problems), in which case the result string will be in HTML format,
* explaining the error, or the request was made for generate token only
* (in this case the response string will only contain 'TranzilaTK'
* parameter)
*/
}else if($response_assoc['Response'] !== '000'){
die($response_assoc['Response']."\n");
// Any other than '000' code means transaction failure
// (bad card, expiry, etc ..)
}else{
die("Success \n");
}
`
在这里我出于安全原因在这里用原始供应商名称替换了供应商。在实际供应商处运行此代码时,出现“未授权”错误。