Bhavin Bhaskaran
Bhavin Bhaskaran

Reputation: 582

Session value is not getting after payment completion

I am using paytabs(a payment gateway like paypal) in my mvc project.In that when when I call create-paypage-api-call it will go to paytab website and complete the payment section and will return back to my page. return back url is an action method in same controller and that url i have to pass as a parameter when calling create-paypage-api-call.

before calling it I am saving customerID in session. But I am not able to get the session value in the retrurnpage.

Here is my code

This is my payment gateway calling actionresult

public ActionResult paymentcall()
    {
         //my logic part here let it be int customerid = 123

          session[id] = customerid;

         //create-paypage-api-call starts here
         request = (HttpWebRequest)WebRequest.Create("https://www.paytabs.com/apiv2/create_pay_page");
         request.Method = "POST";
         formContent = "[email protected]&amount=333"//      formcontent will contain some more parameters that i wont mention here


     formContent += "&return_url=" + "http://example.com/mycontroller/TheReturnPage"; // this is the returnpage after payment

         byteArray = Encoding.UTF8.GetBytes(formContent);
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = byteArray.Length;
                dataStream = request.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();
                response = request.GetResponse();
                dataStream = response.GetResponseStream();
                reader = new StreamReader(dataStream);
                responseFromServer = HttpUtility.UrlDecode(reader.ReadToEnd());
                PTResp = new PromoPayTabsMakePaymentResponse();
                PTResp = JsonConvert.DeserializeObject<PromoPayTabsMakePaymentResponse>(responseFromServer);
                System.Web.HttpContext.Current.Response.Redirect(PTResp.payment_url);
     }

when call this it will go to the paytabs website and complete the payment there like entering card details cvv . after payment it is successfully returning back to TheReturnPage actionmethod

public ActionResult TheReturnPage()
{
    int aa = Convert.ToInt32(Session["id"]);
}

but in returnpage i am getting session value zero. I tride redirecting from paymentcall action just after creating session. At that time it is getting.Session value is is not getting when it goes to paytabs page and returning back from there. (paytabs page is https and my website is http. I dont know whether this info is needed. Just mentioning)

Upvotes: 1

Views: 2497

Answers (1)

Alan Tsai
Alan Tsai

Reputation: 2525

I am guessing because you redirect to paytabs and when it return page back to you, it is not the same session as the one you had with your customer (because it is from paytabs to you now)

The only thing I can think of is put a transaction id or something which you can identify on the return url, such that:

formContent += "&return_url=" + "http://example.com/mycontroller/TheReturnPage?id=" + someId

then use that someId to retrieve customer info from a database or some external storage.

Upvotes: 2

Related Questions