做外贸电商的,应该都需要一个信用卡的支付通道。类似通道也有很多,如stripe,PayPal信用卡等等。但公司在尝试了诸如此类的通道之后最终选择了深圳的一家叫钱海支付的公司。在mangeto上该支付方式有对应的插件,安装即可。但是存在一个问题,就是国内的支付平台原理都是先生成订单再提交支付平台,这样在支付失败后就应该可以再次提交,这个功能在插件里面并没有实现。经和平台技术支持沟通了解到,一个订单的支付有效期为30分钟,那么理论上在30分钟内是可以多次请求提交的。为了彻底的吃透这种支付方式,于是就联系了平台索要了api文档和demo,最终调试代码如下:
请求方法:
<?php
//Oceanpayment Account
$account = '140105';
//Oceanpayment Terminal
$terminal = '14010501';
//securecode
$secureCode = '12345678';
//Order Currency,International standard ISO 4217 is applied
$order_currency = 'USD';
//Order Amount,Maximum 2 fields for decimal numbers, e.g. 5.01; if the transaction amount is 0, no need to send it to Oceanpayment’s system.
$order_amount = '0.01';
//The URL merchant get response from Oceanpayment.
$backUrl = 'http://www.abc.com/back.php';
//The URL merchant get response from server.
$noticeUrl = 'http://www.abc.com/notice.php';
//Payment Method
$methods = 'Credit Card';
//Order Number
$order_number = 'order123456789';
//Cardholder’s first name,Default value can be customer ID or N/
$billing_firstName = OceanHtmlSpecialChars('testBillingFirstName');
//Cardholder’s last name,Default value can be customer ID or N/
$billing_lastName = OceanHtmlSpecialChars('testBillingLastName');
//Cardholder’s email address,Default value can be 'customerID@Domain.com'
$billing_email = OceanHtmlSpecialChars('test@demo.com');
//Cardholder’s phone number,Default value can be N/A
$billing_phone = '13800138000';
//Cardholder’s country,International standard ISO 3166 is applied, e.g. US,Default value can be N/A
$billing_country = 'US';
//Cardholder’s state
$billing_state = 'AO';
//Cardholder’s city,Default value can be N/A
$billing_city = 'New York';
//Cardholder’s address,Default value can be N/A
$billing_address = 'Eighth Avenue';
//Cardholder’s zip,Default value can be N/A
$billing_zip = '518000';
//Order notes information
$order_notes = '';
//Secure signature verification for security transactionssha256 Encryption
$signValue = hash("sha256",$account.$terminal.$backUrl.$order_number.$order_currency.$order_amount.$billing_firstName.$billing_lastName.$billing_email.$secureCode);
//Recipients’s first name
$ship_firstName = 'testShipFirstName';
//Recipients’s last name
$ship_lastName = 'testShipLastName';
//Recipients’s phone number
$ship_phone = '13800138000';
//Recipients’s country,International standard ISO 3166 is applied, e.g. US
$ship_country = 'US';
//Recipients’s state
$ship_state = 'AO';
//Recipients’s city
$ship_city = 'New York';
//Recipients’s address
$ship_addr = 'Eighth Avenue';
//Recipients’s zip
$ship_zip = '518000';
//Products’s name,multiple products can be separated by ‘;’,Default value can be N/A
$productName = 'productName';
//Products’s SKU,multiple products can be separated by ‘;’,Default value can be N/A
$productSku = 'productSku';
//Products’s num,multiple products can be separated by ‘;’,Default value can be N/A
$productNum = 'productNum';
//Terminal type, e.g. PC、WAP、Andriod、iOS
$cart_info = 'PC';
//Oceanpayment API version
$cart_api = 'V1.8.0';
//Payment Pages;0: PC;1: Mobile
$pages = 0;
?>
<form action="https://secure.oceanpayment.com/gateway/service/test" id="creditcard_payment_checkout" name="creditcard_payment_checkout" method="POST">
<input type="hidden" id="account" name="account" value="<?php echo $account;?>" >
<input type="hidden" id="terminal" name="terminal" value="<?php echo $terminal;?>" >
<input type="hidden" id="order_number" name="order_number" value="<?php echo $order_number;?>" >
<input type="hidden" id="order_currency" name="order_currency" value="<?php echo $order_currency;?>" >
<input type="hidden" id="order_amount" name="order_amount" value="<?php echo $order_amount;?>" >
<input type="hidden" id="methods" name="methods" value="<?php echo $methods;?>" >
<input type="hidden" id="signValue" name="signValue" value="<?php echo $signValue;?>" >
<input type="hidden" id="backUrl" name="backUrl" value="<?php echo $backUrl;?>" >
<input type="hidden" id="noticeUrl" name="noticeUrl" value="<?php echo $noticeUrl;?>" >
<input type="hidden" id="billing_firstName" name="billing_firstName" value="<?php echo $billing_firstName;?>" >
<input type="hidden" id="billing_lastName" name="billing_lastName" value="<?php echo $billing_lastName;?>" >
<input type="hidden" id="billing_email" name="billing_email" value="<?php echo $billing_email;?>" >
<input type="hidden" id="billing_phone" name="billing_phone" value="<?php echo $billing_phone;?>" >
<input type="hidden" id="billing_country" name="billing_country" value="<?php echo $billing_country;?>" >
<input type="hidden" id="billing_state" name="billing_state" value="<?php echo $billing_state;?>" >
<input type="hidden" id="billing_city" name="billing_city" value="<?php echo $billing_city;?>" >
<input type="hidden" id="billing_address" name="billing_address" value="<?php echo $abilling_address;?>" >
<input type="hidden" id="billing_zip" name="billing_zip" value="<?php echo $billing_zip;?>" >
<input type="hidden" id="ship_firstName" name="ship_firstName" value="<?php echo $ship_firstName;?>" >
<input type="hidden" id="ship_lastName" name="ship_lastName" value="<?php echo $ship_lastName;?>" >
<input type="hidden" id="ship_phone" name="ship_phone" value="<?php echo $ship_phone;?>" >
<input type="hidden" id="ship_country" name="ship_country" value="<?php echo $ship_country;?>" >
<input type="hidden" id="ship_state" name="ship_state" value="<?php echo $ship_state;?>" >
<input type="hidden" id="ship_city" name="ship_city" value="<?php echo $ship_city;?>" >
<input type="hidden" id="ship_addr" name="ship_addr" value="<?php echo $ship_addr;?>" >
<input type="hidden" id="ship_zip" name="ship_zip" value="<?php echo $ship_zip;?>" >
<input type="hidden" id="order_notes" name="order_notes" value="<?php echo $order_notes;?>" >
<input type="hidden" id="productName" name="productName" value="<?php echo $productName;?>" >
<input type="hidden" id="productSku" name="productSku" value="<?php echo $productSku;?>" >
<input type="hidden" id="productNum" name="productNum" value="<?php echo $productNum;?>" >
<input type="hidden" id="cart_info" name="cart_info" value="<?php echo $cart_info;?>" >
<input type="hidden" id="cart_api" name="cart_api" value="<?php echo $cart_api;?>" >
<input type="hidden" id="pages" name="pages" value="<?php echo $pages;?>" >
</form>
<script type="text/javascript">
document.creditcard_payment_checkout.submit();
</script>
<?php
/**
* Oceanpayment HtmlSpecialChars
*/
function OceanHtmlSpecialChars($parameter){
//Strip whitespace (or other characters) from the beginning and end of a string
$parameter = ($parameter);
// Convert special characters to HTML entities( < > " ')
$parameter = str_replace(array("<",">","'","\""),array("<",">","'","""),$parameter)
return $parameter;
}
?>
返回方法:
//Oceanpayment Account
$account = $_REQUEST['account'];
//Oceanpayment Terminal
$terminal = $_REQUEST['terminal'];
//Oceanpayment Payment ID
$payment_id = $_REQUEST['payment_id'];
//Merchant order number
$order_number = $_REQUEST['order_number'];
//Ordr currency
$order_currency = $_REQUEST['order_currency'];
//Order amount
$order_amount = $_REQUEST['order_amount'];
//The status of order number
$payment_status = $_REQUEST['payment_status'];
//The payment details
$payment_details = $_REQUEST['payment_details'];
//Secure signature verification for security transactions sha256 Encryption
$back_signValue = $_REQUEST['signValue'];
//Order Notes information
$order_notes = $_REQUEST['order_notes'];
//Payment Method
$methods = $_REQUEST['methods'];
//Cardholder’s country
$payment_country = $_REQUEST['payment_country'];
//Risks match
$payment_risk = $_REQUEST['payment_risk'];
//secureCode
$secureCode = '';
//Cardholder’s Card No.,only return head 6 and end 4 numbers
$card_number = $_REQUEST['card_number'];
//payment authType
$payment_authType = $_REQUEST['payment_authType'];
$local_signValue = hash("sha256",$account.$terminal.$order_number.$order_currency.$order_amount.$order_notes.$card_number.
$payment_id.$payment_authType.$payment_status.$payment_details.$payment_risk.$secureCode);
if (strtolower($local_signValue) == strtolower($back_signValue)) {
if ($payment_status == 1) {
//Success
}elseif($payment_status == -1){
//Pending
if ($payment_authType == 1) {
//Pre-authorisation for credit cards, will display when active
//Display the successful payment page to consumers
//Orders need to be reviewed manually
}else{
//Other abnormal issues
//Failed
}
}elseif($payment_status == 0){
//Failed
}
}else{
//Failed
}
通知地址代码:
//acquire pushed input stream XML
$xml_str = file_get_contents("php://input");
/**
* to be decided if the responded input stream is a xml
*/
function xml_parser($str){
$xml_parser = xml_parser_create();
if(!xml_parse($xml_parser,$str,true)){
xml_parser_free($xml_parser);
return false;
}else {
return true;
}
}
if(xml_parser($xml_str)){
$xml = simplexml_load_string($xml_str);
//assign the pushed parameters to $_REQUEST
$_REQUEST['response_type'] = (string)$xml->response_type;
$_REQUEST['account'] = (string)$xml->account;
$_REQUEST['terminal'] = (string)$xml->terminal;
$_REQUEST['payment_id'] = (string)$xml->payment_id;
$_REQUEST['order_number'] = (string)$xml->order_number;
$_REQUEST['order_currency'] = (string)$xml->order_currency;
$_REQUEST['order_amount'] = (string)$xml->order_amount;
$_REQUEST['payment_status'] = (string)$xml->payment_status;
$_REQUEST['payment_details'] = (string)$xml->payment_details;
$_REQUEST['signValue'] = (string)$xml->signValue;
$_REQUEST['order_notes'] = (string)$xml->order_notes;
$_REQUEST['card_number'] = (string)$xml->card_number;
$_REQUEST['payment_authType'] = (string)$xml->payment_authType;
$_REQUEST['payment_risk'] = (string)$xml->payment_risk;
$_REQUEST['methods'] = (string)$xml->methods;
$_REQUEST['payment_country'] = (string)$xml->payment_country;
$_REQUEST['payment_solutions'] = (string)$xml->payment_solutions;
//secureCode
$secureCode = '';
$local_signValue =hash("sha256",$_REQUEST['account'].$_REQUEST['terminal'].$_REQUEST['order_number'].
$_REQUEST['order_currency'].$_REQUEST['order_amount'].$_REQUEST['order_notes'].$_REQUEST['card_number'].
$_REQUEST['payment_id'].$_REQUEST['payment_authType'].$_REQUEST['payment_status'].
$_REQUEST['payment_details'].$_REQUEST['payment_risk'].$secureCode);
if (strtolower($local_signValue) == strtolower($_REQUEST['signValue'])) {
if ($_REQUEST['payment_status'] == 1) {
//Success
}elseif($_REQUEST['payment_status'] == -1){
//Pending
if ($_REQUEST['payment_authType'] == 1) {
//Pre-authorisation for credit cards, will display when active
//Display the successful payment page to consumers
//Orders need to be reviewed manually
}else{
//Failed
}
}elseif($_REQUEST['payment_status'] == 0){
//Failed
}
}else{
//Failed
}
echo "receive-ok";
}