示例#1
0
        public async Task <object> createPayment([FromBody] object model)
        {
            object result = null; object resdata = null;

            try
            {
                bKmodel _bkModel = JsonConvert.DeserializeObject <bKmodel>(model.ToString());
                if (_bkModel != null)
                {
                    using (var httpClientHandler = new HttpClientHandler())
                    {
                        using (var objClient = new HttpClient(httpClientHandler))
                        {
                            objClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", _bkModel.authToken);
                            objClient.DefaultRequestHeaders.TryAddWithoutValidation("x-app-key", _objCredentials.app_key);

                            string data    = "{ " + '"' + "amount" + '"' + ": " + '"' + _bkModel.amount + '"' + ", " + '"' + "intent" + '"' + ": " + '"' + _bkModel.intent + '"' + ", " + '"' + "currency" + '"' + ": " + '"' + _bkModel.currency + '"' + ", " + '"' + "merchantInvoiceNumber" + '"' + ": " + '"' + _bkModel.merchantInvoiceNumber + '"' + " }";
                            var    content = new StringContent(data, Encoding.UTF8, "application/json");
                            using (HttpResponseMessage res = await objClient.PostAsync(_objAPIs.createUrl, content))
                            {
                                if (res.IsSuccessStatusCode)
                                {
                                    resdata = res.Content.ReadAsStringAsync().Result;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
            return(result = new
            {
                resdata
            });
        }
示例#2
0
        public async Task <object> executePayment([FromBody] object model)
        {
            object result = null; object resdata = null;

            try
            {
                bKmodel _bkModel = JsonConvert.DeserializeObject <bKmodel>(model.ToString());
                if (_bkModel != null)
                {
                    using (var httpClientHandler = new HttpClientHandler())
                    {
                        using (var objClient = new HttpClient(httpClientHandler))
                        {
                            objClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", _bkModel.authToken);
                            objClient.DefaultRequestHeaders.TryAddWithoutValidation("x-app-key", _objCredentials.app_key);

                            string _exucuteUrl = _objAPIs.exucuteUrl + "/" + _bkModel.paymentID;
                            using (HttpResponseMessage res = await objClient.PostAsync(_exucuteUrl, null))
                            {
                                if (res.IsSuccessStatusCode)
                                {
                                    resdata = res.Content.ReadAsStringAsync().Result;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
            return(result = new
            {
                resdata
            });
        }
示例#3
0
        public async Task <object> savePayment([FromBody] object model)
        {
            object result = null; object resdata = null;

            try
            {
                bKmodel _bkModel = JsonConvert.DeserializeObject <bKmodel>(model.ToString());
                if (_bkModel != null)
                {
                    //Save To database
                    resdata = "Transaction Saved!";
                }
            }
            catch (Exception) { }
            return(result = new
            {
                resdata
            });
        }
示例#4
0
        public async Task <object> getbKashToken()
        {
            object result = null; object resdata = null;

            try
            {
                using (var httpClientHandler = new HttpClientHandler())
                {
                    httpClientHandler.ServerCertificateCustomValidationCallback = (messages, cert, chain, errors) => { return(true); };
                    using (var objClient = new HttpClient(httpClientHandler))
                    {
                        objClient.DefaultRequestHeaders.TryAddWithoutValidation("username", _objCredentials.bk_username);
                        objClient.DefaultRequestHeaders.TryAddWithoutValidation("password", _objCredentials.bk_password);

                        string data    = "{ " + '"' + "app_key" + '"' + ": " + '"' + _objCredentials.app_key + '"' + ", " + '"' + "app_secret" + '"' + ": " + '"' + _objCredentials.app_secret + '"' + " }";
                        var    content = new StringContent(data, Encoding.UTF8, "application/json");
                        using (HttpResponseMessage res = await objClient.PostAsync(_objAPIs.grantTokenUrl, content))
                        {
                            if (res.IsSuccessStatusCode)
                            {
                                var     bkresult  = res.Content.ReadAsStringAsync().Result;
                                bKmodel _objModel = new bKmodel()
                                {
                                    authToken             = bkresult,
                                    appKey                = _objCredentials.app_key,
                                    currency              = "BDT",
                                    merchantInvoiceNumber = Common.genRandomNumber(11),
                                    intent                = "sale"
                                };

                                resdata = _objModel;
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
            return(result = new
            {
                resdata
            });
        }