Getting a 10004 error with button type invalid using BMUpdateButton method
for PayPal
I've been searching the paypal website, forums and Google in general
searching for a solution on this issue. I am aware that there is another
question quite similar to mine, although it does remains unanswered and
I'm not allowed (yet) to post comments to ask for clarification here:
what's wrong with this code to update a paypal button? I get "buttontype
invalid error"
I'm relatively new using the Paypal APIs, so I'll just reproduce the steps
that brought me here.
Created a hosted button of type 'add to cart' on Paypal.
Copied the generated HTML to my website.
Instead of posting directly to Paypal I just post to a PHP script (pasted
below).
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().'||';
}
}
and basically what I'm getting is the error:
Code: "10004" Error Long Message: "The button type specified is invalid."
The main issue is that even though I'm following whatever API instructions
I'm able to get (IMHO the PayPal developers website is a mess), and I'm
positively thinking I'm setting the BUTTONTYPE variable correctly, I'm
still getting this error.
What I have tested:
Tested the hosted button directly, works fine. But I do need to update the
price of the item dynamically.
Changed the BUTTONTYPE to something wrong. This gives me the appropiate
error: 11925, but when I move it to the 'right'value I get the previous
error code again.
Removed all variables except the ones required: USER, PWD, SIGNATURE,
VERSION, METHOD, HOSTEDBUTTONID,BUTTONTYPE,BUTTONCODE. I get the same
error.
Changed the version. Just in case the values allowed for BUTTONTYPE had
changed from one to another. Same error.
So basically I'm stuck here. Do you have any ideas? My website is hosted
on bluehost although I'm not allowed to 'publish' the site until this is
fixed for my client.
Thanks in advance
No comments:
Post a Comment