嗨最近我使用的是Paypal Sanbox,它的工作非常完美。 我的问题是,当使用或cancal付款时我没有得到任何回复许多文件说使用paypay ipn但是有必要吗? 第二种是当用户可以支付然后在我的控制器中返回但用户关闭浏览器选项卡然后不返回
型号:
public class PayPalModel
{
public string cmd { get; set; }
public string business { get; set; }
public string no_shipping { get; set; }
public string @return { get; set; }
public string cancel_return { get; set; }
public string notify_url { get; set; }
public string currency_code { get; set; }
public string item_name { get; set; }
public string amount { get; set; }
public string actionURL { get; set; }
public PayPalModel(bool useSandbox)
{
this.cmd = "_xclick";
this.business = ConfigurationManager.AppSettings["business"];
this.cancel_return = ConfigurationManager.AppSettings["cancel_return"];
this.@return = ConfigurationManager.AppSettings["return"];
if (useSandbox)
{
this.actionURL = ConfigurationManager.AppSettings["test_url"];
}
else
{
this.actionURL = ConfigurationManager.AppSettings["Prod_url"];
}
this.notify_url = ConfigurationManager.AppSettings["notify_url"];
this.currency_code = ConfigurationManager.AppSettings["currency_code"];
}
控制器:
public ActionResult Index()
{
return View();
}
public ActionResult RedirectFromPaypal()
{
return View();
}
public ActionResult CancelFromPaypal()
{
return View();
}
public ActionResult NotifyFromPaypal()
{
return View();
}
// [Authorize(Roles="Customers")]
// [HttpPost]
public ActionResult ValidateCommand(string product, string totalPrice)
{
bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]);
var paypal = new PayPalModel(useSandbox);
paypal.item_name = product;
paypal.amount = totalPrice;
return View(paypal);
// return View();
}
WebConfig
:
<add key="business" value="MyPaypalAc@gmail.com" />
<add key="IsSandbox" value="true" />
<add key="currency_code" value="USD" />
<add key="return" value="http://localhost/PayPal/RedirectFromPaypal" />
<add key="cancel_return" value="http://localhost/PayPal/CancelFromPaypal" />
<add key="notify_url" value="http://localhost/PayPal/NotifyFromPaypal" />
<add key="test_url" value="http://www.sandbox.paypal.com/cgi-bin/webscr" />
<add key="Prod_url" value="http://www.sandbox.paypal.com/cgi-bin/webscr" />
任何有关paypal方法用于了解用户付款或cancal并重定向到我的网页的任何想法 谢谢你
答案 0 :(得分:0)
建议在网站付款标准中使用IPN,因为无法保证在付款完成后所有买家都会被重定向到您的返回网址。
您可以在PayPal帐户中启用自动退货(直接链接到此部分https://www.paypal.com/cgi-bin/customerprofileweb?cmd=_profile-website-payments),但即便如此,您还需要考虑:
&#34;我们将您重定向到(卖方)网站&#34;
有些买家可能会关闭浏览器的窗口/标签而不是等待。
这些买家需要点击&#34;返回(卖家)&#34;按钮被重定向回您的网站,其中一些可能会错过此链接。
启用IPN后,您将始终从PayPal异步收到包含交易详情的POST,无论买家是否已返回您的网站。
答案 1 :(得分:0)
最后很多例子展示,我使用的是IPN
听取IPN控制器
public ActionResult IPN()
{
SmartQueueContext context = new SmartQueueContext();
// var order = new Order(); // this is something I have defined in order to save the order in the database
// Receive IPN request from PayPal and parse all the variables returned
var formVals = new Dictionary<string, string>();
formVals.Add("cmd", "_notify-validate"); //notify-synch_notify-validate
// formVals.Add("at", "this is a long token found in Buyers account"); // this has to be adjusted
// formVals.Add("tx", Request["tx"]);
// if you want to use the PayPal sandbox change this from false to true
string response = GetPayPalResponse(formVals, false);
if (response.Contains("VERIFIED"))
{
//string transactionID = GetPDTValue(response, "txn_id"); // txn_id //d
// string sAmountPaid = GetPDTValue(response, "mc_gross"); // d
//string deviceID = GetPDTValue(response, "custom"); // d
//string payerEmail = GetPDTValue(response, "payer_email"); // d
//string Item = GetPDTValue(response, "item_name");
//validate the order
string transactionID = Request["txn_id"];
string sAmountPaid = Request["mc_gross"];
string payerEmail = Request["payer_email"]; // d
context.PayPalTransfer(SessionManager.ClientId, transactionID, payerEmail);
return RedirectToAction("Summary", "PackageSetup");
}
else
{
return RedirectToAction("CancelFromPaypal", "PayPal");
}
// return RedirectToAction("Index", "PackageSetup");
}