Exemplo n.º 1
0
        private HttpRequestMessage GenerateHttpRequestMessage(object model, string apiAction, string nonce)
        {
            // we don't know if an URL in config has a slash at the end of it, so we remove it from URL, and always include it at the start of path
            string url       = _apiURL.TrimEnd('/') + apiAction;
            string jsonModel = JsonConvert.SerializeObject(model);
            string signature = Signature.CalculateSignature(_secretKey, nonce + url + jsonModel);

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, url);

            httpRequestMessage.Headers.Add(Constants.Netgiro_AppKey, _applicationId);
            httpRequestMessage.Headers.Add(Constants.Netgiro_Signature, signature);
            httpRequestMessage.Headers.Add(Constants.Netgiro_Nonce, nonce);
            httpRequestMessage.Content = new StringContent(jsonModel, Encoding.UTF8, "application/json");

            return(httpRequestMessage);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Callback()
        {
            var signature = this.Request.Headers[Constants.Netgiro_Signature];
            var nonce     = this.Request.Headers[Constants.Netgiro_Nonce];
            var json      = await ReadBody(HttpContext);

            var paymentResponseObj = JsonConvert.DeserializeObject <PaymentResponse>(json);
            var transactionId      = paymentResponseObj.PaymentInfo.TransactionId;

            var callbackUrl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}{Url.Action(nameof(CallbackController.Callback), "Callback")}";

            var calculatedSignature = Signature.CalculateSignature(_appSettings.SecretKey, nonce, callbackUrl, json);

            if (signature != calculatedSignature)
            {
                return(BadRequest());
            }

            await this._hubcontext.Clients.Client(_clientManager.GetClientByTransactionId(transactionId)).SendAsync("ReceiveMessage", "user", "Callback received");

            return(Ok());
        }
Exemplo n.º 3
0
        private RestRequest GenerateRestRequest(object model, string apiAction, string nonce)
        {
            var request = new RestRequest(apiAction, Method.POST, DataFormat.Json);

            // we don't know if an URL in config has a slash at the end of it, so we remove it from URL, and always include it at the start of path
            var url       = _apiURL.TrimEnd('/') + request.Resource;
            var jsonModel = JsonConvert.SerializeObject(model, new JsonSerializerSettings
            {
                Error = (object sender, ErrorEventArgs args) =>
                {
                    args.ErrorContext.Handled = true;
                }
            });

            var signature = Signature.CalculateSignature(_secretKey, nonce + url + jsonModel);

            request.AddJsonBody(model);
            request.AddHeader(Constants.Netgiro_AppKey, _applicationId);
            request.AddHeader(Constants.Netgiro_Signature, signature);
            request.AddHeader(Constants.Netgiro_Nonce, nonce);

            return(request);
        }