Paypal multi parameters in return , cancel_return

2019-08-27 22:17发布

问题:

I'm doing simple Paypal payment integration in ASP.NET app., I tried to build the returning query string for both success & cancel but it doesn't work because I'm sending more than one parameter in the querystring

string returnUrl = ConfigurationManager.AppSettings["PayPalSandBoxUrl"] + "&business=" + email;
        returnUrl += "&amount= 100";
        returnUrl += "&item_name=Invoice to somebody";
        // the problem goes in following params
        returnUrl += "&return=" + ConfigurationManager.AppSettings["Domain"] + "Payment.aspx?param1=" + param1 + "&param2=" + param2 ;
        returnUrl += "&cancel_return=" + ConfigurationManager.AppSettings["Domain"] + "Payment.aspx?cancel=true&param1=" + param1;

I think it gets some confusion between paypal request parameters and the return query parameters , is there any solution for this ??

回答1:

When you add on the URL parameters that contains symbols that can confuse the real parametres, symbols as ?, &, / etc, you must encode them with the UrlEncode

So make your string as:

string returnUrl = 
        ConfigurationManager.AppSettings["PayPalSandBoxUrl"] 
         + "&business=" + HttpServerUtility.UrlEncode(email);
        returnUrl += "&amount= 100";
        returnUrl += "&item_name=" + HttpServerUtility.UrlEncode("Invoice to somebody");
        // the problem goes in following params
        returnUrl += "&return=" 
          + HttpServerUtility.UrlEncode(ConfigurationManager.AppSettings["Domain"] + "Payment.aspx?param1=" + param1 + "&param2=" + param2) ;
        returnUrl += "&cancel_return=" 
          + HttpServerUtility.UrlEncode(ConfigurationManager.AppSettings["Domain"] + "Payment.aspx?cancel=true&param1=" + param1 );