在BlueSnap Payment Gateway中,如何创建托管付款字段令牌请求

时间:2018-09-17 06:06:07

标签: php jquery ajax curl

curl -v -X POST https://ws.bluesnap.com/services/2/payment-fields-tokens \ 
-H 'Content-Type: application/json' \ 
-H 'Accept: application/json' \  
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \ 
-d '

在php中,如何在curl发布和显示位置网址中描述上述代码。

1 个答案:

答案 0 :(得分:0)

$api_usernam  = bluesnap::$username ;
$api_password = bluesnap::$password ;
$auth_token   = base64_encode(  $api_usernam . ':' . $api_password );
        $header = array("Authorization: Basic ".$auth_token."", "Content-type: application/json");
        $url = "https://sandbox.bluesnap.com/services/2/payment-fields-tokens"; //change the URL on production

        //start request
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

         $resp = curl_exec($ch);

         curl_close($ch);

             list($Headers, $Response)=explode("\r\n\r\n",$resp, 2);
            $Headers=explode("\n", $Headers);
            foreach($Headers as $Header)
            {
            if (stripos($Header, "Location")!==false)
            {
            $Token=trim(str_replace("Location: ", "", $Header));
            }
            }

            $Token = substr(strrchr( $Token, '/' ),1);

        // test if secuss

         return $Token;

    }