2014-0925

国外支付接口FirstData开发示例

作者: momy 分类: 编程开发 0 Comment »
摘要:这里示例是Payment Page方式,即跳转到Firstdata网站进行支付

这里示例是Payment Page方式,即跳转到Firstdata网站进行支付

1.申请帐号,配置相关Payment Page

Receipt Page Setup里边设置Relay Response Url,记着开启Relay Response;这个Url是我们自己网站用来更新订单状态的,源码如下:

<?php
require_once("../../../include/common.inc.php");
require_once("../../../users/config.php");
echo"<h2>";
echo$_REQUEST['x_response_reason_text'];
echo"</h2>";
if($_REQUEST['x_response_code'] == '1') {
$item_number=$_REQUEST["x_cust_id"];
echo"<p>OrderNO:".$item_number."</p>";
$dsql->ExecuteNoneQuery("Update `#@__line_order` set ischeck='1' where buyid ='$item_number'");
echo"<p>";
echo"Your order was processed successfully. Here is your receipt.";
echo"Your order will be shipped in two business days.";
echo"</p>";
echo"<pre>";
echo$_REQUEST["exact_ctr"];
echo"</pre>";
if(! empty( $_REQUEST["exact_issname"] )) {
echo"<p>";
echo"Issuer: ". $_REQUEST["exact_issname"] . "<br/>";
echo"Confirmation Number: ". $_REQUEST["exact_issconf"];
echo"</p>";
}
echo"<p>";
$track_url= $cfg_basehost."/users/order.php?po=all&buyid=". $item_number;
echo"You can track it at <a href=\"". $track_url. "\">". $track_url. "</a>";
echo"</p>";
} elseif($_REQUEST['x_response_code'] == '2') {
echo"<p>";
echo"Your payment failed.";
echo"Here is your receipt.";
echo"</p>";
echo"<pre>";
echo$_REQUEST["exact_ctr"];
echo"</pre>";
} else{
echo"<p>";
echo"An error occurred while processing your payment.";
echo"Please try again later.";
echo"</p>";
}
?>

2.发起支付页面,即套装到支付页面的方法如下:

<?php
require_once("../../../include/common.inc.php");
require_once("../../../users/config.php");
?>
使用firstdata付款 <br>
订单总额:<?php echo$_REQUEST['jiage'];?> usd <br>
<form action="https://demo.globalgatewaye4.firstdata.com/payment"method="POST"name="myForm"id="myForm">
<?php
$x_login= "HCO-DMINF-714"; // Take from Payment Page ID in Payment Pages interface
$transaction_key= "NQk12yz74utJrcmd7gvA"; // Take from Payment Pages configuration interface
$x_amount= $_REQUEST['jiage'];
$x_cust_id= $_REQUEST['buyid'];
$x_currency_code= "USD"; // Needs to agree with the currency of the payment page
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence= rand(1000, 100000) + 123456;
$x_fp_timestamp= time(); // needs to be in UTC. Make sure webserver produces UTC
// The values that contribute to x_fp_hash
$hmac_data= $x_login. "^". $x_fp_sequence. "^". $x_fp_timestamp. "^". $x_amount. "^". $x_currency_code;
$x_fp_hash= hash_hmac('MD5', $hmac_data, $transaction_key);
$x_relay_response="TRUE";
$x_relay_url=$cfg_basehost."/order/pay/firstdata/ok.php";
echo('<input name="x_login" value="'. $x_login. '" type="hidden">');
echo('<input name="x_amount" value="'. $x_amount. '" type="hidden">');
echo('<input name="x_fp_sequence" value="'. $x_fp_sequence. '" type="hidden">');
echo('<input name="x_fp_timestamp" value="'. $x_fp_timestamp. '" type="hidden">');
echo('<input name="x_fp_hash" value="'. $x_fp_hash. '" size="50" type="hidden">');
echo('<input name="x_currency_code" value="'. $x_currency_code. '" type="hidden">');
echo('<input name="x_relay_response" value="'. $x_relay_response. '" type="hidden">');
echo('<input name="x_relay_url" value="'. $x_relay_url. '" type="hidden">');
echo('<input name="x_cust_id" value="'. $x_cust_id. '" type="hidden">');
?>
<input type="hidden"name="x_show_form"value="PAYMENT_FORM"/>
</form>
<script type='text/javascript'>document.myForm.submit();</script>


特别说明下,上边的x_relay_url是第一步更新订单状态接口的地址,x_cust_id是订单ID,记着传到服务器,服务器会原样返回给你,这样第一步就可以更新订单状态为已支付,怎么验证是否是支付服务器返回的数据请参看相关开发文档,如有需要可联系本站管理员。


test

标签: Payment Page FirstData 国外支付接口 阅读: 13010
上一篇: The type or namespace name 'Schema' does not exist - 10222次
下一篇: PHP调用接口GET和POST方法 - 12725次

向右滑动解锁留言