0

I am invoking an API and I have done the crate_order call. When a user is done with their payment, the API sends a Payment callBack data in POST and uses the Content-Type application/x-www-form-urlencoded.

I am not sure how to catch that POST data in C# and save the data in an object so I can return.

The call_back URL is my CgCallback method: example.com/CgCallback.

This method looks like:

public CgCallback incomingData()
{
     CgCallback resultCgOrder = new CgCallback();

    resultCgOrder.Id = Request.Form["id"];
    resultCgOrder.OrderId = Request.Form["order_id"];
    return resultCgOrder;
}

Unfortunately giving this error:

The name 'Request' does not exist in the current context

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Sam
  • 9
  • 9
  • this question has been awnsered multiple times : here is a link https://stackoverflow.com/questions/6159103/how-can-i-get-all-element-values-from-request-form-without-specifying-exactly-wh – Mohamoud Mohamed Mar 10 '18 at 10:08
  • 1
    Possible duplicate of [Why the name 'Request' does not exist when writing in a class.cs file?](https://stackoverflow.com/questions/10439709/why-the-name-request-does-not-exist-when-writing-in-a-class-cs-file) – Stephen Kennedy Mar 10 '18 at 10:45

1 Answers1

0

i think u need set up the callback url page for coingate trigger your page.

public partial class Test_CallBack_Page : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string tempID           = GetFormVariableOrNull(Request.Form["id"]);
        string tempOrder_ID     = GetFormVariableOrNull(Request.Form["order_id"]);
        string tempStatus       = GetFormVariableOrNull(Request.Form["status"]);
        //pending, confirming, paid, invalid, expired, canceled, refunded

        if (tempStatus.Equals("paid"))
        {
            //update your Purchase Order
        }
    }

    protected string GetFormVariableOrNull(object formvariable)
    {
        if (formvariable != null)
        {
            try
            {
                return formvariable.ToString();
            }
            catch (Exception ex)
            {
                /// log the exception in file or DB
                Console.WriteLine(ex.Message);/// just for an example
                return null;
            }
        }
        else return null;
    }
}

do u mind share your code? i confusing on create order with coingate api using c#.

  • Hi Yth, thanks man for the reply. don't worry, will share my code soon with u. i couldn't able to finish the create order and stack in this callback_URL area. once sorted will knock u. – Sam Mar 12 '18 at 08:01