我需要在我的php代码实现BeanStream支付网关。我是支付网关实施方面的新手。有人能帮我做演示项目或脚本吗?事先谢谢。
我知道这是一个老问题,但由于我刚刚在我的代码中实现了Beanstream支付网关,我想我无论如何都会回答这个问题:
一旦你有了Beanstream的帐户,你就可以访问他们的API手册,其中提供了关于所有请求和响应字段的一些很好的文档。您可以使用PHP中的curl库轻松地连接到Beanstream API。下面是一个基于他们的文档执行简单支付的示例方法($global_ccauth只是一个包含我的请求信息的ORM对象,我每次都将其存储在我的数据库中,包括来自Beanstream的响应字符串,但要小心,你可能想要混淆ORM模型中的信用卡号码,然后保存到数据库中,就像我一样):
public static function do_payment($global_ccauth, $submitted_card_number) {
$payment_result = array(
'status' => FALSE,
'response' => array(),
);
// attempt to process the payment using CURL and a POST request to the Beanstream server as per Beanstream's example
$request = curl_init();
// Get curl to POST
curl_setopt($request, CURLOPT_POST, 1);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // return the results instead of echoing them
curl_setopt($request, CURLOPT_URL, BEANSTREAM_URL);
// These are the transaction parameters that we will POST
$auth_parameters = "requestType=BACKEND";
$auth_parameters .= "&merchant_id=" . BEANSTREAM_MERCHANT;
$auth_parameters .= "&username=" . BEANSTREAM_API_USER;
$auth_parameters .= "&password=" . BEANSTREAM_API_PASS;
$auth_parameters .= "&trnCardOwner=" . $global_ccauth->trnCardOwner;
$auth_parameters .= "&trnCardNumber=". $submitted_card_number;
$auth_parameters .= "&trnExpMonth=" . $global_ccauth->trnExpMonth;
$auth_parameters .= "&trnExpYear=" . $global_ccauth->trnExpYear;
//$auth_parameters .= "&trnCardCvd=";
$auth_parameters .= "&trnOrderNumber=" . $global_ccauth->trnOrderNumber ;
$auth_parameters .= "&trnAmount=" . $global_ccauth->trnAmount;
$auth_parameters .= "&ordName=" . $global_ccauth->ordName;
$auth_parameters .= "&ordEmailAddress=" . $global_ccauth->ordEmailAddress;
$auth_parameters .= "&ordPhoneNumber=" . $global_ccauth->ordPhoneNumber;
$auth_parameters .= "&ordAddress1=" . $global_ccauth->ordAddress1;
$auth_parameters .= "&ordAddress2=" . $global_ccauth->ordAddress2;
$auth_parameters .= "&ordCity=" . $global_ccauth->ordCity;
$auth_parameters .= "&ordProvince=" . $global_ccauth->ordProvince;
$auth_parameters .= "&ordPostalCode=" . $global_ccauth->ordPostalCode;
$auth_parameters .= "&ordCountry=" . $global_ccauth->ordCountry;
curl_setopt($request, CURLOPT_POSTFIELDS, $auth_parameters);
// Now POST the transaction. $txResult will contain Beanstream's response
$auth_result = curl_exec($request);
curl_close($request);
if ($auth_result !== FALSE) {
// save the raw results
$global_ccauth->response = $auth_result;
$global_ccauth->save();
// parse the results
parse_str($auth_result, $parsed_result);
$payment_result['response'] = $parsed_result;
if ( ! empty($parsed_result['trnApproved']) && $parsed_result['trnApproved'] == 1) {
// the request was approved
$payment_result['status'] = TRUE;
} else {
// the request was not approved
// do something smart
}
} else {
// curl POST request failed
// do something smart
}
return $payment_result;
}
我也实施了他们的定期付款自动处理每月付款,它似乎工作得很好。你只需要根据他们的API文档调整你发送的参数。
PHP-Payments似乎是什么你正在寻找http://payments.calvinfroedge.com/