duanhao7786 2012-01-03 07:41
浏览 121

如何在paypal IPN中获取item_number?

here's a sample response from the paypal after I completed the payment of the cart using the sandbox

Array
(
    [address_city] => San Jose
    [address_country] => United States
    [address_country_code] => US
    [address_name] => Test User
    [address_state] => CA
    [address_status] => confirmed
    [address_street] => 1 Main St
    [address_zip] => 95131
    [business] => test_biz@gmail.com
    [charset] => windows-1252
    [custom] => 
    [first_name] => Test
    [form_charset] => UTF-8
    [item_name1] => iPod Touch
    [item_name2] => Giant Hamburger, the world's biggest
    [item_number1] => 2
    [item_number2] => 1
    [last_name] => User
    [mc_currency] => USD
    [mc_fee] => 0.79
    [mc_gross] => 17.00
    [mc_gross_1] => 7.00
    [mc_gross_2] => 10.00
    [mc_handling] => 0.00
    [mc_handling1] => 0.00
    [mc_handling2] => 0.00
    [mc_shipping] => 2.00
    [mc_shipping1] => 2.00
    [mc_shipping2] => 0.00
    [merchant_return_link] => click here
    [notify_version] => 3.4
    [num_cart_items] => 2
    [payer_email] => test_per@gmail.com
    [payer_id] => TRCLJTHLNCJ7Q
    [payer_status] => verified
    [payment_date] => 23:14:45 Jan 02, 2012 PST
    [payment_fee] => 0.79
    [payment_gross] => 17.00
    [payment_status] => Completed
    [payment_type] => instant
    [protection_eligibility] => Eligible
    [quantity1] => 1
    [quantity2] => 1
    [receiver_email] => test_biz@gmail.com
    [receiver_id] => 74PV23B8KSK84
    [residence_country] => US
    [tax] => 0.00
    [tax1] => 0.00
    [tax2] => 0.00
    [test_ipn] => 1
    [transaction_subject] => Shopping CartiPod TouchGiant Hamburger, the world's biggest
    [txn_id] => 4BK63214AG342352Y
    [txn_type] => cart
    [verify_sign] => A0Jk1FY.7aHd-VRk44a4grBP7kE.A0Azn34Obs6QiSJKuCvAWSWyItkH
)

as you can see, there's item_name1 and item_name2 how to get the values of these items let's say e.g I have had paid 10 items?. that would be like from item_name1 to item_name10

I generated that numbering of items via my PHP code, like this

<?php
  $i = 1;
  foreach($_SESSION['cart'] as $id => $qty):
  $product = find_product($id);
?>

<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['ProductDescription']; ?>">
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['ProductID']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['ProductOverridePrice']; ?>">
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $qty; ?>">

<?php
  $i++;
  endforeach;
?>

and if you look at the sample paypal response, there is mc_gross_1 , mc_gross_2 ...tax1,tax2 and the like ..so how will I get those values of the ones that has incremented numbers and save it in the db ?

  • 写回答

1条回答 默认 最新

  • duanhui1869 2012-01-03 08:47
    关注

    You do also have [num_cart_items] = 2 though. So just do a loop ...

    for ($i = 1; $i <= $_POST['num_cart_items']; $i++) {
       $name = $_POST['item_name' . $i];
       $number = $_POST['item_number' . $i];
       $quantity = $_POST['quantity' . $i];
       //etc...
    
       $query = "INSERT INTO payments (product_name, product_id, product_quantity)
                 VALUES ('" . mysql_real_escape_string($name) . "', '" . mysql_real_escape_string($number) . "', '" . mysql_real_escape_string($quantity) . "')";
       mysql_query($query);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?