PayPal - 使用 php 加密多项目自定义购物车动态结账按钮

2021-12-29 00:00:00 encryption dynamic php paypal checkout

我创建了一个网站,需要我构建自定义购物篮以满足业务需求.这一切正常.

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.

上周我一直在尝试制作一个加密的使用 PayPal 结账"按钮.

I have spent the last week trying to make an encrypted 'checkout with PayPal' button.

首先我尝试了这个:www.x.com/message/174366(没有超链接,因为我是新用户,抱歉),并且无法从该功能中获取任何加密数据.

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.

所以我又花了一天的时间研究并发现 使用 php 加密的网络支付

So I spent another day researching and found Encrypted web payments with php

将代码自定义到我的购物篮后,它会生成加密数据.但是当点击按钮时,PayPal 只显示一个项目输入框 - 即没有任何数据被传递.

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.

当我注释掉向按钮添加多个项目的代码并只编码一个静态项目(即使用 item_name 而不是 item_name_1 等)时,它工作正常.

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.

我曾尝试将 cmd 变量从 _s-xclick 更改为 _cart 和 _s-cart,如我遇到的某个论坛中提到的那样,但无济于事.我确实设置了上传变量.

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.

所以这不起作用

$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);

但这确实有效

$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?

推荐答案

好的,我已经解决了.在 EncryptedButtons 类中更改

right, i've solved it. In the EncryptedButtons class change

$this->_data = "cmd=_xclick
"; 

$this->_data = "cmd=_cart
"; 

并添加

$this->_data .= "upload=1
";

记住.在最后一行的 = 之前,否则会导致错误.希望这可以帮助某人.这个项目完成后,我将写一篇博文,并在完成后添加一个链接.

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.

相关文章