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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀