简体   繁体   中英

mvc paypal payment details amount dont show

In my project include paypal express check out. I send all details in below class. And My code below;

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());
        }
    }
}

and my controller ;

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

But I cant show amount on paypal page????? I show desc but I dont show amount??? what is wrong? thanks for reply.

Have you passing Amount or not, I think you are not passing Amount Value If not then add

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);
   }
}

For More Details Check PayPal with ASP.NET MVC

Hope it helps you.

Try passing over a line item name and amount and see if it shows up in that case. Also, can you provide the actual string of data you are sending over to PayPal, minus your API credentials so that I can test it with my API credentials.

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM