贝宝html按钮自定义字段限制 [英] Paypal html button custom field limit

查看:172
本文介绍了贝宝html按钮自定义字段限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

贝宝(Paypal)html按钮的 custom (自定义)字段限制为256个字符.有没有办法增加该限制,或者我可以使用其他字段(例如custom1,custom2,other)等等?

there is a limit of 256 characters on the custom field for a Paypal html button. Is there a way to increase that limit or are there other fields that I can user (like custom1, custom2, other), etc...

谢谢

推荐答案

不是通过自定义字段发送全部数据,而是将数据保存在数据库中并发送记录ID.在ipn/取消上,获取ID并更新/删除记录.

Instead of sending a whole load of data via the custom field, save the data in a database, and send a record id. On ipn / cancel, retrieve the ID and update/delete the record.

要执行此操作,首先,您需要更改按钮代码以将其发布到您自己网站上的PHP文件中,而不是paypal上,因此需要常规按钮代码:

To do this, 1st you need to change the button code to post to a php file on your own site not paypal, so the regular button code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="seller@designerfotos.com">
<input type="hidden" name="item_name" value="hat">
<input type="hidden" name="item_number" value="123">
<input type="hidden" name="amount" value="15.00">
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
</form>

成为:

<form action="buttonhandler.php" method="post">
    <input type="hidden" name="item_number" value="123">
    <input type="image" name="submit" border="0"
    src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
    alt="PayPal - The safer, easier way to pay online">
</form>

请注意,缺少一些字段-cmd,business,item_name和amount,因为我们将在php中生成这些字段.

Note that a few fields are missing - cmd, business, item_name and amount, as we will generate those in php.

您可以在html按钮中定义金额,但最好在数据库中定义金额,然后您可以自动拒绝用户支付错误金额的订单(通过摆弄发送给Paypal的数据-他们目前可以使用您的常规html按钮系统执行的操作).

You could have the amount defined in the button html, but it would be better to have it defined in your database, then you can automatically reject orders where the user paid the wrong amount (by fiddling with the data sent to paypal - something they can currently do with your normal html button system).

在php文件中,您收集产品信息,将订单保存到数据库,并生成通常包含在按钮表单字段中的贝宝数据

In the php file, you collect the product info, save the order to the db, and generate the paypal data that would normally be included in the button form fields

//buttonhandler.php

$item_number = $_POST['item_number'];
//get item name, price from DB
//Note made up ORM code here for brevity - 
//use whatever db acccess method you usually do:
$item = Items::getOne($item_number);

//save order in db, and retrieve order id. You can save whatever you need into the order, 
//this is a simple example that just takes item number, amount and timestamp
Orders::add($item->number, $item->amount, time());
$orderId = Orders::lastInsertId();

//create paypal data
$paypalData=array(
    'business'=>'seller@designerfotos.com',
    'cmd'=>'_xclick',
    'notify_url'=>'http://yoursite.com/1hd-ff-ipn.php', //call this something random, you dont want it getting hit by web bots
    'return'=>'http://yoursite.com/thanks-for-your-order.php',
    'cancel_return'=>'http://yoursite.com/cancel.php?orderid=' . $orderId,
    'amount'=>$item->amount,
    'currency_code'=>'GBP',
    'item_number'=>$item->number,
    'item_name'=>$item->name,
    'custom'=>$orderId
);
 //build a query string and redirect to paypal
$query_string = http_build_query($paypalData);
header("Location: https://www.paypal.com/cgi-bin/webscr?" . $query_string);
//done
die();

现在,您可以在ipn脚本中对照orderid来交叉检查价格:

Now you can crosscheck price against orderid in your ipn script:

//1hd-ff-ipn.php
$order = Orders::getOne($_POST['custom']);
if ($_POST['mc_gross'] != $order->amount) {
    //price mismatch, handle accordingly
}
//more checks here as required, then
$order->paymentStatus = 'complete';
$order->save(); 

并在您的取消页面中删除订单

And delete orders in your cancel page

//cancel.php
Orders::delete($_GET['orderid');
?>
<h1>Sorry you cancelled</h1>

您还可以每小时/每天/以任何方式运行crom,以处理被遗弃的订单

You can also run a crom every hour/day/whatever to handle abandoned orders

//cron.php
//delete pending older than 1 day, 
Orders::deleteWhere('status = ? and ordered_on <?','pending', time() - (24 * 60 * 60));

这篇关于贝宝html按钮自定义字段限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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