我需要帮助。我试图通过 Bluesnap 实现一次性付款。付款后,我需要使用所需参数将用户返回到站点。
我在文档中发现了如何实现它的两种方式。我可以将thankyou.backtosellerurl 与encription 或自定义参数一起使用。
我尝试了thankyou.backtosellerurl 参数,但付款后没有任何反应。我有默认的 Bluesnap 感谢页面。
比我尝试使用 custom1 参数但也没有得到所需的结果。对于自定义参数,我在管理面板http://joxi.ru/p27LM9EsKnXJQA中添加页面设计设置
我的代码。
function generatePaymentLink($amount, $text = 'Pay Now'){
return '<a class="payment-link" target="_blank" href="'.generatePaymentUrl($amount).'">'.$text.'</a>';
}
function generatePaymentUrl($amount){
$config = getConfiguration();
$res = request('https://sandbox.bluesnap.com/services/2/tools/param-encryption');
if($config['sandbox_mode']){
return $config['sandbox']['url'].'?merchantid='.$config['sandbox']['merchantid'].'&enc='.$res;
}
return $config['production']['url'].'?merchantid='.$config['production']['merchantid'].'&amount='.$amount;
}
function getConfiguration(){
require_once (__DIR__.'/config.php');
return $config;
}
function wrapCdata($string)
{
return '<![CDATA['
.str_replace(']]>', ']]><![CDATA[', $string)
.']]>';
}
function paramEncryption(array $params)
{
// compose request XML
$params_xml = '';
foreach ($params as $key => $value)
{
$key = wrapCdata($key);
$value = wrapCdata($value);
$params_xml .= "<parameter>\n<param-key>$key</param-key>\n
<param-value>$value</param-value>\n</parameter>\n";
}
$request_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<param-encryption xmlns=\"http://ws.plimus.com\">\n
<parameters>\n".$params_xml." </parameters>\n</param-encryption>\n";
return $request_xml;
}
function request($url, $http_method = 'POST')
{
$request_xml = paramEncryption([
'thankyou.backtosellerurl' => urlencode('https://siteurl.com/ipn-button.php?test=loremIpsum'),
'amount' => 22,
'currency' => 'USD',
'custom1' => 'loremIpsumCustom'
]);
$username = '//User';
$password = '//Password';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_USERAGENT => 'AIOP STORE',
CURLOPT_COOKIESESSION => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'),
CURLOPT_RETURNTRANSFER => true,
]);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_xml);
curl_setopt($ch, CURLOPT_URL, $url);
$response_xml = curl_exec($ch);
if ($response_xml === false)
{
curl_close($ch);
}
curl_close($ch);
$xml = simplexml_load_string($response_xml);
$json = json_encode($xml);
$configData = json_decode($json, true);
return $configData['encrypted-token'];
}