locked
Get the current page after a call back function RRS feed

  • Question

  • User-218090889 posted

    I would like to be able to get back to the URL of the page that I am crawling when the callback function is called.
    Please any help with example?

    I am using C#.

    Sunday, September 13, 2020 10:08 PM

Answers

  • User475983607 posted

    Payment gateways have documentation that explains how to use their services.   I recommend contacting the service if you are having trouble.  

    Typically, a callback from a payment gateway is to a specific URL in your application.  The URL can be from configuration, state passed to the gateway, or REST where the URL is in the location header.  It is not clear why you do not know the URL

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 18, 2020 12:34 PM

All replies

  • User-1330468790 posted

    Hi Enzyme,

     

    Could you please share the codes or framework you are using for your project?

    That way, we could directly provide you with a solution of codes.

      

    Generally speaking, you could always get the HTTP referer, which means:

    An optional HTTP header field that identifies the address of the webpage (i.e., the URI or IRI) which is linked to the resource being requested. By checking the referrer, the new webpage can see where the request originated.

    In C#, there is an option to fetch that value through below codes

    string referer = Request.Headers["Referer"].ToString();

    which should be working in both ASP.NET and ASP.NET Core.

     

    Then, you could go back to previous page using Redirect method. For example, in ASP.NET Core MVC, 

    return Redirect(previousURL);  

     

    Hope this can help you.

    Best regards,

    Sean

    Monday, September 14, 2020 1:58 AM
  • User-218090889 posted

    Sean Fang

    Could you please share the codes or framework you are using for your project?

    What I Want to achieve with this, is to initialize payment on a payment processor with below code, then after the payment is made, it will return to the Callback Url were I will use the returned reference to verify the payment.
    But I will like the callback url page (https://MySite.com/Page2) to maintain the Login status of https://MySite.com/Page1  so that I can continue the have access to the User Id

    1) Initialization code on ~/Page1

     var client = new RestClient("https://api.paymentSite.co/transaction/initialize");
              
                var keyValues = new Dictionary<string, string>
                                {
    
                                    { "email", "email@mail.com"},
                                    { "amount", "5000"},
                                    { "reference", "Q76y6655"},                             
                                    { "callback_url","https://MySite.com/Page2"},
    
                                };
                //serialization using Newtonsoft JSON 
                string JsonBody = JsonConvert.SerializeObject(keyValues);
    
                var request = new RestRequest(Method.POST);
                request.AddHeader("Authorization", "Bearer SecretKey");
                request.AddHeader("Content-Type", "application/json");
                request.AddParameter("application/json", JsonBody, ParameterType.RequestBody);
                IRestResponse response = client.Execute(request);

    2) The Verification code on ~/Page2

    var client = new RestClient("https://api.paymentSite.co/transaction/verify/reference={Returned Reference}");
              
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", "Bearer SecretKey");
    
                IRestResponse response = client.Execute(request);
    
               

    Monday, September 14, 2020 3:01 AM
  • User-1330468790 posted

    Hi Enzyme,

     

    What do you mean "callback_url" here for the payment processor?

    I don't think you need to worry about maintain the login status for the current user as long as you have implement a mechanism to store the identity for users.

     

    You use RestClient for the payment and will get the response after the api finished the initialization.

    During that process, from my understanding, the "callback_url" is only used for the condition that

    • the payment processor will call the Page2, like call an api to visit your project and provide some information so that you could continue payment process from the server side. The payment processor should not have the user id. (except that you provide it with this information).

    It won't be used as the referer page.

    For user, only if the browser redirect to another website, the "callback_url" will have chance to act like a redirect target after processing the payment. The user will go back to your website, say Page2. At that time, the user ID could be tracked with your identity system (from session or cookies).

     

    Best regards,

    Sean

    Monday, September 14, 2020 9:32 AM
  • User-218090889 posted

    I don't think you need to worry about maintain the login status for the current user as long as you have implement a mechanism to store the identity for users.

     

    You use RestClient for the payment and will get the response after the api finished the initialization.

    During that process, from my understanding, the "callback_url" is only used for the condition that

    • the payment processor will call the Page2, like call an api to visit your project and provide some information so that you could continue payment process from the server side. The payment processor should not have the user id. (except that you provide it with this information).

    It won't be used as the referer page.

    For user, only if the browser redirect to another website, the "callback_url" will have chance to act like a redirect target after processing the payment. The user will go back to your website, say Page2. At that time, the user ID could be tracked with your identity system (from session or cookies).

    The issue is that when the payment processor will call the Page2, like call an api to visit your project, it comes with some information, but when I tried to use the provided information to continue payment process from my server side, I get error message that says
    object reference not set to an instance of an object.

    Below is my code in the Page2 code behind.

    protected void Page_Load(object sender, EventArgs e)
            {
                var trackerRefX = Request.QueryString["reference"].ToString();
                if (!string.IsNullOrEmpty(trackerRefX))
                {
                    Session["Reference"] = trackerRefX;
                }
            }
    
            protected void btPageVerify_Click(object sender, EventArgs e)
            {
                string Reference = Session["Reference"].ToString();
                string Id = Session["UserId"].ToString();
                string VerificationUrl = "https://paymentSite.com/transaction/verify/"+Reference;
    
                var client = new RestClient(VerificationUrl);
                var request = new RestRequest(Method.GET);
                request.AddHeader("Authorization", "Bearer mySecretKey");
    
                IRestResponse response = client.Execute(request);
    
                string data = response.Content;
                string dataT = data.Replace("", string.Empty);
                dynamic stuff = JObject.Parse(dataT);
    
                dynamic ResponseX = stuff.data; // Breaking down the Responce
                string received_status = ResponseX.status;



    Friday, September 18, 2020 12:17 PM
  • User475983607 posted

    Payment gateways have documentation that explains how to use their services.   I recommend contacting the service if you are having trouble.  

    Typically, a callback from a payment gateway is to a specific URL in your application.  The URL can be from configuration, state passed to the gateway, or REST where the URL is in the location header.  It is not clear why you do not know the URL

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 18, 2020 12:34 PM