mvc paypal支付详细信息金额不显示

时间:2013-05-20 10:24:57

标签: c# asp.net-mvc paypal

在我的项目中包括paypal快速退房。我发送下面课程的所有细节。我的代码如下;

public class PayPal
{
    public static PayPalRedirect ExpressCheckout(PayPalOrder order)
    {
        var values = new NameValueCollection();
        values["USER"] = PayPalSettings.Username;
        values["PWD"] = PayPalSettings.Password;
        values["SIGNATURE"] = PayPalSettings.Signature;
        values["METHOD"] = "SetExpressCheckout";
        values["VERSION"] = "63.0";
        values["RETURNURL"] = PayPalSettings.ReturnUrl;
        values["CANCELURL"] = PayPalSettings.CancelUrl;
        values["PAYMENTREQUEST_0_PAYMENTACTION"] = "SALE";
        values["PAYMENTREQUEST_0_CURRENCYCODE"] = "USD";
        values["PAYMENTREQUEST_0_AMT"] = order.Amount.ToString("0.00", CultureInfo.InvariantCulture);
        values["PAYMENTREQUEST_0_DESC"] = "Apart Name";


        values = Submit(values);

        string ack = values["ACK"].ToLower();

        if (ack == "success" || ack == "successwithwarning")
        {
            return new PayPalRedirect
            {
                Token = values["TOKEN"],
                Url = String.Format("https://{0}/cgi-bin/webscr?cmd=_express-checkout&token={1}",
                   PayPalSettings.CgiDomain, values["TOKEN"])
            };
        }
        throw new Exception(values["L_LONGMESSAGE0"]);
    }

    private static NameValueCollection Submit(NameValueCollection values)
    {
        string data = String.Join("&", values.Cast<string>()
          .Select(key => String.Format("{0}={1}", key, HttpUtility.UrlEncode(values[key]))));

        var request = (HttpWebRequest)WebRequest.Create(
           String.Format("https://{0}/nvp", PayPalSettings.ApiDomain));

        request.Method = "POST";
        request.ContentLength = data.Length;

        using (var writer = new StreamWriter(request.GetRequestStream()))
        {
            writer.Write(data);
        }

        using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
        {
            return HttpUtility.ParseQueryString(reader.ReadToEnd());
        }
    }
}

和我的控制员;

 public ActionResult Pay(FormCollection form)
    {
        var redirect = PayPal.ExpressCheckout(new PayPalOrder { Amount = 50 });
        Session["token"] = redirect.Token;
        return new RedirectResult(redirect.Url);
    }

但是我无法在paypal页面上显示金额?????我显示desc但我没有显示金额???怎么了?谢谢你的答复。

2 个答案:

答案 0 :(得分:0)

您是否通过Amount,我认为您没有通过Amount价值如果没有,请添加

public class CartController : Controller
{
   public ActionResult Index()
   {
      return View();
   }

   public ActionResult Pay()
   {
      PayPalRedirect redirect = PayPal.ExpressCheckout(new PayPalOrder { Amount = 50 });

      Session["token"] = redirect.Token;

      return new RedirectResult(redirect.Url);
   }
}

更多详细信息请查看PayPal with ASP.NET MVC

希望它对你有所帮助。

答案 1 :(得分:0)

尝试传递一个订单项名称和金额,看看是否会出现这种情况。此外,您是否可以提供发送给PayPal的实际数据字符串,减去您的API凭据,以便我可以使用我的API凭据对其进行测试。

示例:

https://api-3t.sandbox.paypal.com/nvp?USER=paypal_api1.x.com&PWD=NAEWP67N2BMRSD234P2&SIGNATURE=Ae0iZ4smtdchhBLFKKdS8s8OSA220f033rNWM4EYTk1J-tsdbDOFq0JpNi&METHOD=SetExpressCheckout&VERSION=92.0&RETURNURL=https://www.ccaples.com/mts/pp_nvp_quick_test.php&CANCELURL=https://www.ccaples.com/mts/pp_nvp_quick_test.php&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_AMT=200&PAYMENTREQUEST_0_ITEMAMT=200&PAYMENTREQUEST_0_SHIPPINGAMT=0.00&PAYMENTREQUEST_0_TAXAMT=0.0&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_DESC=test EC payment