PayPal - encrypt muti item custom cart dynamic checkout button with php
I have created a site that required me to build a custom basket in order to meet the needs of the business. This is all working fine.
I have spent the last week trying to make an encrypted 'checkout with PayPal' button.
Firstly I tried this: www.x.com/message/174366 (not hyperlinked because I'm a new user, sorry), and couldn't get any encrypted data out of the function.
So I spent another day researching and found Encrypted web payments with php
After customizing the code to my basket, it generates encrypted data. But when the button is clicked PayPal just shows an item input box - i.e. none of the data is passed.
When I comment out the code for adding multiple items to the button and just code one static item (i.e. using item_name instead of item_name_1 etc) it works fine.
I have tried to change the cmd variable from _s-xclick to _cart and _s-cart as mentioned in some forum I came across to no avail. I do have the upload variable set.
So this doesn't work
$itm=1;
for($j=0;$j<count($tempIArr);$j++)
{
$names[] = 'item_name_'.$itm;
$values[] = $tempIArr[$j]->getName();
开发者_开发技巧 $names[] = 'amount_'.$itm;
$values[] = $tempIArr[$j]->getTotal();
$itm++;
}
$paypal->addButtonParam($names, $values);
But this does work
$names[] = 'item_name';
$values[] = 'someProduct';
$names[] = 'amount';
$values[] = 99;
$paypal->addButtonParam($names, $values);
Anybody got any ideas on how to make it work with multiple items?
right, i've solved it. In the EncryptedButtons class change
$this->_data = "cmd=_xclick\n";
to
$this->_data = "cmd=_cart\n";
and add
$this->_data .= "upload=1\n";
Remember the . before the = on the last line otherwise it will lead to errors. Hope this helps someone. Once this project is finished I will be writing up a blog post and will add a link when I get it done.
Not everyone has the power to install OpenSSL on their hosting plan, or to get it working with all these steps and hoops to jump through. Another solution is tamper detection with an unencrypted button. I explain this here:
How do I make a PayPal encrypted buy now button with custom fields?
精彩评论