I need a help. I tried to impliment one time payments with Bluesnap. After payment I need to return user to site with needed parametr.
I found in documentation tow ways how can impliment it. I could use thankyou.backtosellerurl with encription or custom param.
I tried thankyou.backtosellerurl param but after payment nothing happens. I got default Bluesnap thank you page.
Than I tried to use custom1 param but also not got needed result. For Custom param I add settings on page design in admin panel http://joxi.ru/p27LM9EsKnXJQA
My code.
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'];
}
To use the
thankyou.backtosellerurl
BlueSnap need to allow a specific permission on your account.You should contact BlueSnap support and ask them to do so