我一直在寻找paypal网站,论坛和谷歌一般在这个问题上寻找解决方案。我知道还有另一个与我的问题非常相似的问题,虽然它仍然没有答案,我不允许(还)发表评论,要求澄清:what's wrong with this code to update a paypal button? I get "buttontype invalid error"
我使用Paypal API相对较新,所以我只是重现了让我来到这里的步骤。
ini_set('track_errors',true);
$url = trim('https://api-3t.paypal.com/nvp');
$body_data = array(
'USER' => "omitted",
'PWD' => "omitted",
'SIGNATURE' => "_omitted_",
'VERSION' => "104",
'METHOD' => "BMUpdateButton",
'HOSTEDBUTTONID' => "_omitted_",
'BUTTONTYPE' => "CART",
'BUTTONCODE' => "HOSTED",
'L_BUTTONVAR0' => "amount="_new item price_",
'L_BUTTONVAR1' => "item_name="_item name_",
'L_BUTTONVAR2' => "currency_code="_new currency code_",
'L_BUTTONVAR3' => "on0=".$_POST['os0'],
'L_BUTTONVAR4' => "on1=".$_POST['on1'],
'L_BUTTONVAR5' => "on2=".$_POST['on2'],
'L_BUTTONVAR6' => "quantity=".$_POST['quantity']
);
$body_data = http_build_query($body_data, '', chr(38));
try
{
//create request and add headers
$params = array('http' => array(
'method' => "POST",
'content' => $body_data,
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
$fp = @fopen($url, 'r', false, $ctx);
//get response
$response = stream_get_contents($fp);
//check to see if stream is open
if ($response === false) {
throw new Exception("php error message = " . "$php_errormsg");
}
//echo $response . "<br/>";
//close the stream
fclose($fp);
//parse key from the response
$key = explode("&",$response);
//print_r ($key);
//set url to approve the transaction
$payPalURL = "https://www.paypal.com/cgi-bin/webscr" . str_replace("TOKEN", "token", htmlspecialchars(urldecode($key[0])));
If ( $key[5] == 'ACK=Success')
{
header( "Location: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=T3XNV39TEVDJG" );
}
else
{
echo $response;
echo $key[3];
echo 'ERROR Code: "' . str_replace("L_ERRORCODE0=", "", htmlspecialchars(urldecode($key[5]))) . '"<br/> Error Long Message: "' . str_replace("L_LONGMESSAGE0=", "", htmlspecialchars(urldecode($key[7]))) . '"';
}
}
catch(Exception $e)
{
echo 'Message: ||' .$e->getMessage().'||';
}
}
基本上我得到的是错误:
代码:“10004” 错误长消息:“指定的按钮类型无效。”
主要问题是即使我正在遵循我能够获得的任何API指令(恕我直言,PayPal开发人员网站是一团糟),我正在积极地想我正确设置BUTTONTYPE变量,我我仍然得到这个错误。
我测试的内容:
所以基本上我被困在这里。你有什么想法?我的网站托管在bluehost上,虽然我不允许“发布”该网站,直到我的客户修复此网站。
提前致谢
答案 0 :(得分:2)
我在这篇文章中已经回答了这个问题:
https://stackoverflow.com/a/20899747/2067005
BUTTONTYPE需要BUTTONSUBTYPE来陪伴它,即使它说它是一个可选字段。