简体   繁体   中英

How to integrate CoinGate APIS for cryptography in asp.net c#?

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.

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"
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM