douche5961 2012-03-12 09:15
浏览 35
已采纳

将值或变量传递给paypal cart

I am developing a website so that a customer can buy gardening products. Currently, a customer can browse products on the website. When they select an individual product, I want them to be able to add to cart using Paypal's custom button. My website is set up so that when a user selects a product, it grabs the information from the database. What do I need to do in order for the product they have added to cart to appear in the Paypal cart? (with its name, and price).

From what I understand, you have to create each individual button for each item on your website. But I do not know what product the customer has selected from the database and my website is set up so that it retrieves the product info from the db.

Hope somebody could help me

  • 写回答

2条回答 默认 最新

  • douwu0335 2012-03-12 10:35
    关注

    You can use a single button for all products. You can change the item_name and amount depending upon the product selected. You can pass userid in item_number field.

    When a customer selects the product, query to the database and fetch the product name and amount and update it to the hidden fields.

    <?php
    $amt = amt from db;
    $name = product name from db;
    $userid = user's id;
    ?>
    
    <form name=subs action='https://www.paypal.com/cgi-bin/webscr' method='post'>
    <table cellspacing=0 cellpadding=0><tr><td>
    <input type="hidden" name="on0" value="user">
    <input type="hidden" name="os0" value="<?php echo $user_email; ?>">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="sales@yoursite.com">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="button_subtype" value="services">
    <input type="hidden" name="no_note" value="0">
    <input type="hidden" name="cn" value="add">
    <input type="hidden" name="no_shipping" value="2">
    <input type="hidden" name="rm" value="1">
    <input type="hidden" name="return" value="http://yoursite.com/payment-success.php"> //return to this url after payment completed
    <input type="hidden" name="cancel_return" value="http://yoursite.com/payment-cancel.php"> //return to this url when payment cancelled
    <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
    <input type="hidden" name="custom" value="CustomValue">
    <input type="hidden" name="notify_url" value="http://yoursite.com/payment-confirm.php"> //return instant payment notification to this url where you can get the response from paypal and process it
    <input type="hidden" name="event" value="add">
    <input type="hidden" name="mnt" value="0"> 
    <input type="hidden" name="amount" value="<?php echo $amt; ?>" id="paypalamt"> //the product's amount
    <input type="hidden" name="item_number" id="paypalno" value="<?php echo $userid; ?>"> //you can send the customer/user id with this, so that you can retrieve it after payment completion
    <input type="hidden" name="item_name" id="itemname" value="<?php echo $name; ?>"> //here you can set your product name
    </td></tr>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等