【发布时间】:2017-10-27 12:38:07
【问题描述】:
POST 是通过 PayPal documentations 发送 PayPal 按钮的推荐方法。他们明确表示:
<FORM action="https://www.paypal.com/cgi-bin/webscr" method="post">重要提示:请勿更改这些值。这些属性是必需的 对于所有支付按钮和购物车上传命令
但是在this tutorial 中,作者在服务器端构建按钮变量,然后将客户端重定向到 PayPal,这将使请求通过“GET”而不是“POST”发送到 PayPal。 类似的东西
这是发送给客户的表单(它没有 PayPal 变量,只有按钮和一些与我的业务相关的可选变量)
<form class="paypal" action="/payments.php" method="post">
<select name="product">
<option value="A">A</option>
<option value="B">B</option>
</select>
<input name="discountCode" type="text">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
然后他在服务器上构建了 PayPal 变量并将客户端重定向到 PayPal 以继续进行
payments.php
$paypal_email = 'user@example.com';
$return_url = 'http://example.com/payment-successful.html';
$cancel_url = 'http://example.com/payment-cancelled.html';
$notify_url = 'http://example.com/payments.php';//same file
$item_name = 'Test Item'; //build the item and amount depend on what is selected in the form
$item_amount = 5.00;
$querystring = '';
$querystring .= "?business=".urlencode($paypal_email)."&";
$querystring .= "cmd=_xclick&";
$querystring .= "item_name=".urlencode($item_name)."&";
$querystring .= "amount=".urlencode($item_amount)."&";
$querystring .= "return=".urlencode(stripslashes($return_url))."&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$querystring .= "notify_url=".urlencode($notify_url);
// Redirect to paypal (will cause GET request to PayPal)
header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring);
exit();
这种方法对我有用,但是 POST 方法是 PayPal 推荐的方法。我发现 PHP 更舒服,让我有机会在客户端转到 PayPal 之前做一些工作,例如根据用户选择更新我的后端系统或从 HTML <form> 隐藏一些敏感变量(如 notify_url)(客户仍然可以看到他被引导到的位置)。
在服务器端构建 PayPal 变量然后通过 GET 请求将客户端重定向到 PayPal 是否可靠且受支持?
【问题讨论】:
-
您可以通过创建隐藏表单并使用 javascript 提交来轻松地使用发布表单数据进行重定向。
-
您的意思是隐藏
<input>的常规形式,没有涉及<input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="user@example.com">之类的java 脚本? -
并在
</form>之后添加<script type="text/javascript">document.getElementById('myFormId').submit();</script>,而不是header("Location: ...");。所以你基本上回显了一个包含所有隐藏字段的普通表单并自动提交。 -
我需要更新
<form>产品价格取决于使用的折扣代码,并在用户访问 PayPal 网站之前更新我的后端数据库中使用的折扣代码状态。我的第二个选项将是您所说的使用 java 脚本,就像这里 https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1512&expand=true&locale=en_US 一样。但是如果这个 PHP 工作不被推荐并且不可靠,我将使用这个 java 脚本选项。 -
@DainisAbols 哦,是的,我刚刚知道了! .是的,这是一个切割器解决方案,非常感谢您