贝宝解析正确的物品返回的值 [英] Parse PayPal items returned values properly

查看:137
本文介绍了贝宝解析正确的物品返回的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站集成了贝宝付款方式,我把它所有运行得很好,我被堵在点是贝宝送我到我的有关购买的客户和项目信息返回URL。

I'm integrating a paypal payment method on my website, I got it all running just fine, I'm stuck at the point were paypal sends me to my return URL with information about the customer and items purchased.

我一定要确认阵列上这种结构如下

I get this following structure on the confirmation array

Array
(
    some customer info
    ...
    [L_NAME0] => Frame%20Rojo
    [L_NAME1] => External%20Hard%20Disk
    [L_NUMBER0] => PD1002
    [L_NUMBER1] => PD1003
    [L_QTY0] => 1
    [L_QTY1] => 1
    [L_TAXAMT0] => 0%2e00
    [L_TAXAMT1] => 0%2e00
    [L_AMT0] => 29%2e00
    [L_AMT1] => 100%2e00
    ...
)

我很感兴趣的是拯救整个项目清单,数量和价格,以我的数据库中,以便以后我可以跟踪哪些已发送,什么不是。

What I'm interested is in saving the whole item list, quantities and prices to my database so I can later keep track of what's been sent and what not.

在这里,我的问题是,你可以看到,贝宝将返回我一组的名称的东西+ N的值(L_NUMBER0等),所以,我不能只建立一个表对我的DDBB因为我不知道有多少项目将一个用户得到。我可以将它保存在2个表:购买和items_per_purchase状结构,但我仍面临解析该数组的问题

My issue here is that as you can see, paypal returns to me a set of values that are names "something+n" (L_NUMBER0 and so on), so, I can't just set up a table on my DDBB as I don't know how many items would an user get. I could save it on 2 tables: purchase and items_per_purchase like structure, but I still face the issue of parsing that array.

什么是通过它来运行,看看每购买有多少个项目,以节省的最佳方式?

What would be the best way to run through it and see how many items per purchase there are to save?

我觉得某种bucle至极的看到:

I thought of some kind of bucle wich sees:

while(if(isset($_GET['L_NUMBER'.$cont]))) {
    // save to ddbb
    L_NAME.$cont
    L_NUMBER.$cont
    ...
    cont++
} 

...并增加了一些柜台,但我想知道是否有更好的解决方案。

... and increment some counter but I would like to know if there's a better solution.

推荐答案

我认为您的解决方案是好的,但你并不需要一个如果中的,而测试...

I think your solution is fine, though you don't need an if inside the while test...

$cont = 0;
while (isset($_GET['L_NUMBER' . $cont])) {
    // save to database after assembling array keys as follows...
    // L_NAME . $cont
    // L_NUMBER . $cont
    // etc.

    cont++;
}

和你永远不应该从 $信任输入_ GET 。我建议使用<一个href=\"http://stackoverflow.com/questions/60174/how-can-i-$p$pvent-sql-injection-in-php\">parameterized查询与PDO 。

And you should never trust input from $_GET. I recommend using parameterized queries with PDO.

这篇关于贝宝解析正确的物品返回的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆