Paypal actionurl is automatic change from old to new url

sandeep_005
New Community Member

Hello,

 

i want to why my paypal payment action method is automatically changes from https://www.sandbox.paypal.com/cgi-bin/webscr url to https://www.sandbox.paypal.com/webapps when a customer to payment.

 

if customer pay by the https://www.sandbox.paypal.com/cgi-bin/webscr this url then the process work fine get the transcation id or ipn status perfectly after payment.

 

but if the customer pay by https://www.sandbox.paypal.com/webapps i dont get any parameter from paypal after sucessfully payment.

 

I want o knwo what is the reason for that.

 

 This is my code

 

 

public ActionResult ValidateCommand(string product, string totalPrice)
{
bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);
var paypal = new PayPalModel(useSandbox);

try
{

paypal.item_name = product;
paypal.amount = totalPrice;
if (totalPrice == "0" || totalPrice == null || product == "" || product == null)
{
ViewData["zeroPrice"] = "Your grand total price Zero, so please select item and try again.";
return RedirectToAction("viewcart", "Home");
}
}
catch(Exception ex)
{
log.CreateErrorMessage(ex);
}
return View(paypal);
}

 

public ActionResult RedirectFromPaypal(FormCollection collection)
{
CultureInfo ci = new CultureInfo("en-us");

string strFormValues = Encoding.ASCII.GetString(Request.BinaryRead(Request.ContentLength));
dynamic strNewValue = null;

// getting the URL to work with
string URL = null;


string UseSandbox = Convert.ToString(ConfigurationManager.AppSettings["UseSandbox"]);

if (UseSandbox == "true")
{
URL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
//URL = "https://www.sandbox.paypal.com/webapps";

}
else
{
URL = "https://www.paypal.com/cgi-bin/webscr";
}
//for ssl and tls
ServicePointManager.Expect100Continue = true;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

// Create the request back
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);

// Set values for the request back
req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";
strNewValue = strFormValues + "&cmd=_notify-validate";
req.ContentLength = strNewValue.Length;

// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();

//send the request, read the response
HttpWebResponse strResponse = (HttpWebResponse)req.GetResponse();
Stream IPNResponseStream = strResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(IPNResponseStream, encode);

Char[] read = new Char[257];
// Reads 256 characters at a time.
int count = readStream.Read(read, 0, 256);

while (count > 0)
{
// Dumps the 256 characters to a string
String IPNResponse = new String(read, 0, count);
count = readStream.Read(read, 0, 256);

NumberFormatInfo provider = new NumberFormatInfo();
provider.NumberDecimalSeparator = ".";
provider.NumberGroupSeparator = ",";
provider.NumberGroupSizes = new int[] { 3 };

string strCumtomeMessage = Request.Form["custom"];
string status = Request.Form["payment_status"];
string paystatus = Request.Form["payer_status"];

string[] strPaymentId = new string[2];

if (strCumtomeMessage != "" && strCumtomeMessage != null)
{
strPaymentId = strCumtomeMessage.Split('&');
}

//if (IPNResponse == "VERIFIED")
if (Request.Form["payer_status"] == "verified" || Request.Form["payer_status"] == "VERIFIED")
{
if (status.ToLower() == "completed")
{

string pg = Convert.ToString(Request.Form["payment_gross"]);

string tid = Convert.ToString(Request.Form["txn_id"]);

string ps = Request.Form["payment_status"].ToLower();

string p_date = Convert.ToString(Request.Form["payment_date"]);

string i_name = Convert.ToString(Request.Form["item_name"]);

//pass parameter to view
Cartparameters objPram = new Cartparameters();
objPram.ItemPrice = pg;
objPram.RefNo = tid;
objPram.PaymentStatus = ps;
objPram.Date = p_date;
objPram.ItemName = i_name;


// add order in data base
Order_Save(pg, tid, ps, p_date, i_name);

// send email admin and user
SendMail(pg, tid, ps, p_date, i_name);

return View(objPram);

}
}
}

return View();
}

 

Pls help me

to solve this issue.

Login to Me Too
1 REPLY 1

MTS_Nacho
Moderator
Moderator

When you point to https://www.sandbox.paypal.com/cgi-bin/webscr for a payment, we will then do other internal redirections and the final landing page will, indeed, look similar to https://www.sandbox.paypal.com/webapps

 

However, this shouldn't cause any impact to the payments or to the IPN sent after the payments.

 

If IPN is enabled in your account (or if you are passing a dynamic notification URL using "notify_url") we will continue sending the notifications.

 

Do you experience issues when receiving the IPN from PayPal Sandbox, or when POSting back to validate the IPN?

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.