PayPal - encrypt muti item custom cart dynamic checkout button with php

纵然是瞬间 提交于 2019-12-01 08:50:15

问题


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?


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/4382987/paypal-encrypt-muti-item-custom-cart-dynamic-checkout-button-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!