如何从asp.net中的paypal(Sandbox)获取返回URL的参数

时间:2013-12-28 10:27:45

标签: c# asp.net vb.net paypal

您好我正在使用paypal(沙盒帐户)集成到我的asp.net网站。我能够进入paypal的价格和项目名称,但我想得到这些参数的回报网址所以我可以保存他们我记录的数据库。

我正在尝试这是在本地。(这是否可以在本地返回url获取参数。)

在Paypal上点击“返回辅导员帐户的测试商店”,然后返回successpage.aspx。

我如何在此返回网址中获取参数值。

这里我写了结帐页面的代码:

Protected Sub imgbtn_Click(sender As Object, e As ImageClickEventArgs) Handles imgbtn.Click

Dim qty As Integer = Request.QueryString("qty")
Dim Amount As String = Request.QueryString("price")
Dim ItemDescription As String = Request.QueryString("ItemDescription")
Dim redirectUrl As String = ""

'Mention URL to redirect content to paypal site
redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" & ConfigurationManager.AppSettings("paypalemail").ToString()

'Product Name
redirectUrl += "&item_name=" + ItemDescription

'Product Amount
redirectUrl += "&amount=" + Amount

'Business contact paypal EmailID
redirectUrl += "&xxxxx-facilitator@gmail.com"

'Quantiy of product, Here statically added quantity 1
redirectUrl += "&quantity=" + qty.ToString()

'If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer
redirectUrl += "&return=" & ConfigurationManager.AppSettings("SuccessURL").ToString()


redirectUrl += "&cancel_return=" & ConfigurationManager.AppSettings("FailedURL").ToString()

Response.Redirect(redirectUrl)

End Sub

webconfig代码:

     <appSettings>
      <add key="paypalemail" value="xxxx-facilitator@gmail.com" />
     <add key="SuccessURL" value="http://localhost:53725/Project/SuccessPayment.aspx  " />
     <add key="FailedURL" value="http://localhost:53725/Project/Index.aspx" />


  </appSettings>

我尝试过一个stackoverflow的链接,但我没有得到这个。

http://stackoverflow.com/questions/15322148/paypal-multi-parameters-in-return-cancel-return-urls

我这是第一次这样做所以请告诉我你的宝贵答案。

由于

1 个答案:

答案 0 :(得分:0)

将您设置返回网址的代码行更改为:

redirectUrl += "&return=" & ConfigurationManager.AppSettings("SuccessURL").ToString() & _
"&custom=MyCustomValue"

并跟踪此类任何其他自定义参数。此外,您应该对整个返回URL进行url编码,因为它在查询字符串中包含查询字符串。