Example #1
0
        public async Task <PaymentInitalizationResponseModel> InitializePaymentToPayStack(decimal amount)
        {
            var setting = GetPayStackSetting();
            var user    = await _statisticsService.UserFullName();

            //Fetch
            PaymentInitalizationResponseModel     modal    = new PaymentInitalizationResponseModel();
            TransactionInitializationRequestModel reqModel = new TransactionInitializationRequestModel
            {
                amount      = (amount * 100).ToString(),
                email       = user.email,
                callbackUrl = setting.callbackUrl,
                //reference = "Invoice Generated"
            };
            var SecKey = string.Format("Bearer {0}", setting.SecretKey);

            var baseAddress = $"{BaseConstants.PaystackBaseEndPoint}{BaseConstants.PaystackInitializeTransactionEndPoint}";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            var http = (HttpWebRequest)WebRequest.Create(new Uri(baseAddress));

            http.Headers.Add("Authorization", SecKey);
            http.Accept      = "application/json";
            http.ContentType = "application/json";
            http.Method      = "POST";

            string        parsedContent = JsonConvert.SerializeObject(reqModel);
            ASCIIEncoding encoding      = new ASCIIEncoding();

            Byte[] bytes = encoding.GetBytes(parsedContent);

            Stream newStream = http.GetRequestStream();

            newStream.Write(bytes, 0, bytes.Length);
            newStream.Close();

            var response = http.GetResponse();
            var stream   = response.GetResponseStream();
            var sr       = new StreamReader(stream);
            var content  = sr.ReadToEnd();
            var cc       = JsonConvert.DeserializeObject(content);
            var cd       = JsonConvert.DeserializeObject(cc.ToString());

            modal = JsonConvert.DeserializeObject <PaymentInitalizationResponseModel>(content);
            return(modal);
        }
Example #2
0
        /// <summary>
        /// This methods initializes payment transactioons - It inlcude subaccount, transactioncharge etc
        /// </summary>
        /// <param name="email"></param>
        /// <param name="amount"></param>
        /// <param name="subaccount"></param>
        /// <param name="transaction_charge"></param>
        /// <param name="bearer"></param>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="callbackUrl"></param>
        /// <param name="reference"></param>
        /// <param name="plan"></param>
        /// <param name="invoice_limit"></param>
        /// <param name="makeReferenceUnique"></param>
        /// <returns></returns>

        public async Task <PaymentInitalizationResponseModel> InitializeTransaction(TransactionInitializationRequestModel requestObj)
        {
            var client = HttpConnection.CreateClient(this._secretKey);

            var bodyKeyValues = new List <KeyValuePair <string, string> >();


            foreach (var property in requestObj.GetType().GetProperties())
            {
                if (property.GetValue(requestObj) != null)
                {
                    bodyKeyValues.Add(new KeyValuePair <string, string>(property.Name, property.GetValue(requestObj).ToString()));
                }
            }

            var formContent = new FormUrlEncodedContent(bodyKeyValues);

            var response = await client.PostAsync("transaction/initialize", formContent);

            var json = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <PaymentInitalizationResponseModel>(json));
        }