1

我需要帮助。我试图通过 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'];

}
4

2 回答 2

2

要使用thankyou.backtosellerurlBlueSnap,需要对您的帐户授予特定权限。

您应该联系BlueSnap 支持并要求他们这样做

于 2018-11-29T11:48:48.627 回答
0

使用thankyou.backtosellerurl 参数需要BlueSnap 为您的帐户启用权限,但仅当您打算在不同的交易/产品/购物者位置或您端需要您设置的任何其他逻辑上传递不同的回调URL 时才应使用此参数回调 URL 仅在您创建结帐页面时作为参数。如果是这种情况,您需要联系 BlueSnap 支持并要求他们为您的帐户启用相关权限。

如果您有一个固定的回调 URL,您可以通过页面设计 -> 设置在您的 BlueSnap 帐户控制台上设置它。

于 2018-12-10T13:48:00.693 回答