【问题标题】:How do I get information back from paypal after the payment is approved?支付成功后如何从paypal取回信息?
【发布时间】:2012-11-22 17:42:09
【问题描述】:

我有一个带有订阅 paypal 按钮的 asp.net MVC4 操作:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">
                <input type="hidden" name="item_number" value="@item.Id">
                <input type="hidden" name="item_name" value="@item.Name">
                <input type="hidden" name="src" value="1">@*Recurring until user cancels*@
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="p3" value="1"> @*Billing cycle amount*@
                <input type="hidden" name="t3" value="M"> @*billing cycle period - Month*@
                <input type="hidden" name="no_note" value="1">
                <input type="hidden" name="business" value="dude@dude.com">@*Hiva's paypal account*@
                <input type="hidden" name="currency_code" value="USD">
                <input type="hidden" name="return" value="@returnUrl">
                <input type="hidden" name="amount" id="amount" value="@item.Price">
                <input type="submit" name="Submit" value="Subscribe">
            </form>

在返回 URL 中,它触发了一个操作,我希望能够看到表单详细信息以及付款是否通过,以及所有这些好东西。这就是我所拥有的:

        public ActionResult PaymentConfirm(FormCollection form)
    {
        //if successful, blah blah
        var user = User.Identity.Name;
        //Merchant merch = ctx.Merchants.Single(x => x.User.UserName == user);
        //merch.Plan = plan;

        return RedirectToAction("Index", "Merchant");
    }

我怎样才能得到这些数据!

【问题讨论】:

  • 查看 PayPal IPN? paypal.com/ipn
  • 我手头没有相关信息,但 IPN 文档很好地涵盖了它。基本上,您会在返回的查询字符串中获得一个交易编号,然后您可以将其提交回 PayPal 以确认用户没有编造。

标签: c# asp.net asp.net-mvc paypal


【解决方案1】:

正如评论所述,解决方案是 IPN。基本上,IPN 是您在商家帐户中设置的 URL,位于销售工具下。

  1. 您可能希望创建指向您的操作的 url。 (要在本地执行此操作,您需要进行端口转发以使您的站点公开可用)

  2. IPN 包含您需要的所有信息。每当付款时都会调用它,并且它还带有付款状态,无论是成功还是失败。

这是您可以参考的代码示例的链接。

https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

更新:有关 IPN 如何在幕后工作的详细信息,请参考以下链接

https://www.paypal.com/cgi-bin/webscr?cmd=p/acc/ipn-info-outside

【讨论】:

  • 好吧,我看了一下并实现了代码,但我仍然不明白一些东西。这是我在重定向到贝宝后应该放在我的页面上的内容吗?目前我有一个付款页面,上面有提交付款的表单,然后我让它转到我放入代码示例的页面,它路由正常,但我在那里看不到任何可用的数据。
  • 当你说“它路由正常”时,你是说它在幕后调用你的 IPN url?
  • 是的,上面的表格,当您点击提交时,它会将您带到贝宝沙盒网站登录并批准付款。在贝宝网站上的流程结束时,我单击返回我的网站的链接。然后它将路由到我的付款确认页面(我有示例代码)。
  • @davidisawesome IPN 是“带外” - 它与用户/浏览器导航无关。不幸的是,我相信上面页面中的示例代码(至少是 C#)是用于验证(已经)发送给您的 POST。 This link 可能更适合您更广泛地了解 IPN。
  • 我已经添加了解决方案的链接供其他人参考
【解决方案2】:

如果您使用PayPal REST API,那么您可以这样做:

        // You create the ProcessPayment() method
        string jsonResponse = ProcessPayment(model);

        var jss = new JavaScriptSerializer();
        Payment payment = jss.Deserialize<Payment>(jsonResponse); 

        APIContext apiContext = Configuration.GetAPIContext();
        Payment originalPayment = Payment.Get(apiContext, payment.id);

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2011-08-20
    • 2012-11-13
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 2019-07-29
    • 2011-11-08
    • 2017-03-01
    相关资源
    最近更新 更多