-1

every one I need to integrate Cryptography currency in our project.And I have to choose CoinGate APIS for Cryptography currency. I am new for this Cryptography payment integration so any know how can do with the asp.net with MVC c#. I have created one demo for the payment integration and I go for the create order but that time I am getting an error Unauthorized. And In this demo I have not idea how can set callback_url for the payment etc.. Anyone know how can do that then please let me know. Here below I have listed my code. I have to go with this URL:

https://github.com/cizu64/Coingate.net

This is my controller Index method for the go create order:

    public async Task<ActionResult> Index()
    {
        var cg = new Coingate.Net.Coingate(apikey, apiSecret,appId);
        var orders = await cg.CreateOrder(new Order
        {
            Price = 100,
            Currency = "USD",
            ReceiveCurrency = "BTC"
        });
        return View();
    }

 public async Task<dynamic> CreateOrder(Order dto, string resourcePath = "/v1/orders/")
    {
        _client.BaseAddress = new Uri(_baseUri);
        ConfigureHeaders(Signature());
        var body = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("order_id", dto.OrderId.ToString()),
            new KeyValuePair<string, string>("price", dto.Price.ToString()),
            new KeyValuePair<string, string>("currency", dto.Currency),
            new KeyValuePair<string, string>("receive_currency", dto.ReceiveCurrency),
            new KeyValuePair<string, string>("title", dto.Title),
            new KeyValuePair<string, string>("description", dto.Description),
            new KeyValuePair<string, string>("callback_url", dto.CallbackUrl),
            new KeyValuePair<string, string>("cancel_url", dto.CancelUrl),
            new KeyValuePair<string, string>("success_url", dto.SuccessUrl)
        });
        var response = await _client.PostAsync(resourcePath, body);
        if (!response.IsSuccessStatusCode) return HttpStatusCode.BadRequest;
        var order = await response.Content.ReadAsAsync<dynamic>();
        return order;
    }

This is my order class:

    public int OrderId { get; set; }
    public double Price { get; set; }
    public string Currency { get; set; }
    public string ReceiveCurrency { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public string CallbackUrl { get; set; }
    public string CancelUrl { get; set; }
    public string SuccessUrl { get; set; }

Anyone know how can do that then please let me know.

Edit
  • 29
  • 1
  • 3
  • 9

1 Answers1

-1

So i took a look at the linked github to see how the request was made, and noticed that in the creation there is a sandbox boolean.

When this is entered it redirects to a diffrent API

Sandbox: https://api-sandbox.coingate.com/

Non-sandbox: https://api.coingate.com/

The sandbox requires an different account to be created, which is why you are getting the Unauthorized as i'm guessing you are using the credentials from the production entviroment.

You can solve this in 2 ways, 1. Create an account on the sandbox enviroment. 2. change var cg = new Coingate.Net.Coingate(apikey, apiSecret,appId); to var cg = new Coingate.Net.Coingate(apikey, apiSecret,appId, false);

This can be all found here

Regarding the callback URL. This can easily be added in the following way

var orders = cg.CreateOrder(new Order
{
    Price = 100,
    Currency = "USD",
    ReceiveCurrency = "BTC",
    CallbackUrl = "url here"
});
Vincentw
  • 164
  • 3
  • 17
  • Yes, I have used this GitHub link and also download this project and this class library used and give a reference to my demo project. And I am Create Order call API and in the response also get 200 status code but with the response I am not getting order details. so can you please help me on that. – Edit Mar 12 '18 at 09:52
  • I am also working that on your point 1 and 2. it's true in my demo – Edit Mar 12 '18 at 09:58
  • To get the details of the order created, you will need to read the details of the variable orders in the index method. This should hold the details of the order. Also if it is true it is pointed to the sandbox which requires an different login then the production environment. So make sure you are using the correct credentials. – Vincentw Mar 12 '18 at 09:58
  • Please see this link https://developer.coingate.com/docs/create-order This API call after in the response give me status code 200 and also with json return. so I want this json also. so can you please help me – Edit Mar 12 '18 at 10:01
  • Thanks for helping out. I have updated the GitHub project and implemented version 2. – cerberus Jun 12 '19 at 15:57