php 贝宝.一种在接受付款之前验证付款的方法
有没有办法在贝宝继续订单之前验证付款?
我使用我自己的购物车。 当客户单击“提交订单”时,我将用户重定向到其他页面调用 PayPalRedirect.php
PayPalRedirect.php
<form name="paypalform" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="invoice" value="<? echo $idInvoice; ?>">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="notify_url" value="http://mydomain.com/catalog/IPNReceip">
<?
$cpt = 1;
foreach($ordering as $k => $v)
{
?>
<input type="hidden" name="item_name_<? echo $cpt?>" value="<? echo$v->Product->ProductNumber; ?>">
<input type="hidden" name="quantity_<? echo $cpt?>" value="<? echo $v->Qty; ?>">
<input type="hidden" name="amount_<? echo $cpt?>" value="<? echo $v->Price ?>">
<?
$cpt++;
}
?>
<input type="hidden" name="currency_code" value="CAD">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
我使用此 JavaScript 在页面加载时提交表单:
<script>
document.forms.paypalform.submit();
</script>
这个时候就一切正常了。用户被重定向到PayPal页面,可以登录PayPal然后支付订单。
我现在的问题是。 PayPal 有没有办法调用我这边的网络服务(例如: http://mydomain.com/ValidatePayment .php)并传递paypal收到的购物车中的所有商品以确认价格正确。如果价格不正确,我想回复 paypal 付款无效并取消交易。所有这一切都发生在客户点击 paypal 页面的 PayNow 之前。 如果可能的话我该怎么做?
多谢
Is there a way to validate a payment before paypal proceed the order ?
I Use my own shopping cart.
When the customer click on Submit Order, I redirect the user on an other page call, PayPalRedirect.php
PayPalRedirect.php
<form name="paypalform" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="invoice" value="<? echo $idInvoice; ?>">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="notify_url" value="http://mydomain.com/catalog/IPNReceip">
<?
$cpt = 1;
foreach($ordering as $k => $v)
{
?>
<input type="hidden" name="item_name_<? echo $cpt?>" value="<? echo$v->Product->ProductNumber; ?>">
<input type="hidden" name="quantity_<? echo $cpt?>" value="<? echo $v->Qty; ?>">
<input type="hidden" name="amount_<? echo $cpt?>" value="<? echo $v->Price ?>">
<?
$cpt++;
}
?>
<input type="hidden" name="currency_code" value="CAD">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
I use this JavaScript to submit the form when the page is loaded:
<script>
document.forms.paypalform.submit();
</script>
At this time all is alright. The user is Redirect to PayPal page and can login to PayPal and then pay the order.
My question at this point is. Is there a way with PayPal to call a web service in my side (for example: http://mydomain.com/ValidatePayment.php) and pass all the items of the shoping cart that paypal receive to confirm that the price is correct. If the price is not correct, I would like to response to paypal that the payment is invalid and cancel the transaction. All that before the customer click on PayNow of paypal page.
How can I do this if it's possible?
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能做你想做的事。一旦您将客户发送至 Paypal,他们将处理付款并在最后向您发送确认信息。
如果您想确保客户支付了正确的金额,您应该检查 Paypal 发送给您的确认信息。
您可能知道 Paypal 有两种付款确认机制 - PDT 和 IPN。
PDT 依赖于客户在付款后返回您的网站。客户付款后,Paypal 将向您发送一条包含交易详细信息的 PDT 消息。您可以使用此信息向客户出示收据。问题是客户在付款后是否立即关闭浏览器。如果发生这种情况,您可能永远不会收到 PDT 消息。
IPN 不依赖于客户返回您的网站。每次客户付款时,Paypal 都会向您发送一条 IPN 消息,其中包含交易详细信息。
您可以使用其中之一或两者来确认付款已完成。您还可以检查付款是否符合您预期的金额。
请参阅下面我在我的网站上使用的流程:
1 - 客户按下按钮使用 Paypal 进行付款
2 - 我的网站将客户发送到 Paypal 并附上交易详细信息
3 - Paypal 处理付款
4 - 付款完成后,Paypal 将发送客户返回我的网站并带有 PDT 消息。
5 - 我的网站向 Paypal 发送一条确认消息,以检查 PDT 消息是否合法且来自 Paypal。
6 - Paypal 发回一条消息,其中包含交易的所有详细信息,包括支付的价格。
7 - 我的网站检查来自 Paypal 的确认消息,并在屏幕上向我的客户显示收据
8 - 一旦付款到我的卖家账户,Paypal 也会发送一条 IPN 消息。
9 - 当我的网站收到 IPN 消息时,它会向 Paypal 发回一条消息,以确认该消息是合法的并且源自 Paypal。
10 - 我的网站然后检查从 Paypal 发回的确认消息并确认付款是否正确。
请注意,在大多数情况下,我会收到来自 Paypal 的两条消息(一条 PDT 和一条 IPN)。没关系,因为我会跟踪每笔交易,如果我收到已标记为已付款的交易的 IPN,我只需丢弃 IPN 消息即可。
请注意,如果您收到 PDT 消息,则实际上并不需要 IPN 消息。不过,我建议您同时实施这两种方法,以防客户在 Paypal 有机会将其送回您的网站之前关闭浏览器。
在这两条消息(PDT 和 IPN)中,Paypal 都会告诉您付款是否已结清。您可能知道,某些付款类型在提交到 Paypal 几天后才会清算。 Paypal 建议您在付款结清之前不要发货。付款结清后,Paypal 将向您发送另一条 IPN 消息。
我的网站上有两个脚本 - 一个用于处理 PDT 消息,另一个用于处理 IPN 消息。它们在处理付款确认时非常相似。请参阅下面的示例:
我希望这会有所帮助。请随时提出后续问题。
祝你好运!
I don't think it is possible to do what you want. Once you send the client over to Paypal, they will handle the payment and send you a confirmation at the end.
If you want to make sure the client paid the correct amount, you should check the confirmation that Paypal sends you.
As you probably know Paypal has two payment confirmation mechanisms - PDT and IPN.
PDT relies on the client coming back to your website after the payment. Once the client makes the payment, Paypal will send you a PDT message with the details of the transaction. This information is what you can use to show a receipt to the client. The issue is if the client closes his browser immediately after making a payment. If that happens, you may never receive the PDT message.
IPN does not rely on the client coming back to your website. Every time a client makes a payment, Paypal will send you an IPN message with the details of the transaction.
You can use either one or both to confirm that payment was completed. And you can also check that the payment was made for the amount you were expecting.
See below the flow I use on my website:
1 - client presses button to make payment with Paypal
2 - my website sends client to Paypal with the details of the transaction
3 - Paypal handles the payment
4 - once payment is completed, Paypal will send the client back to my website with a PDT message.
5 - my website sends a confirmation message to Paypal to check that the PDT message is legit and came from Paypal.
6 - Paypal sends back a message with all the details of the transaction, including price paid.
7 - my website checks the confirmation message from Paypal and shows a receipt on screen to my client
8 - Paypal will also send an IPN message once a payment is made to my seller account.
9 - when my website receives an IPN message, it sends back a message to Paypal to confirm that the message is legit and was originated from Paypal.
10 - my website then checks the confirmation message sent back from Paypal and confirms the payment was correct.
Note that in most cases I will receive two messages from Paypal (one PDT and one IPN). It is ok because I keep track of each transaction and if I receive an IPN for a transaction where I have already marked as paid, I simply discard the IPN message.
Note that if you receive the PDT message you don't really need the IPN message. However I recommend you implement both just in case the client closes his browser before Paypal has a chance to send him back to your website.
In both messages (PDT and IPN) Paypal tells you if the payment cleared or not. As you probably know, some payment types do not clear until a few days after they are submitted to Paypal. Paypal recommends that you don't ship the product until the payment has cleared. Paypal will send you another IPN message once the payment is cleared.
I have two scripts on my website - one to handle the PDT messages and another one to handle the IPN messages. They are very similar when handling payment confirmation. See below an example:
I hope this helps. Please feel free to ask follow up questions.
Good luck!