Пример #1
0
        /// <summary>
        /// Generate the token used to redirect the user to pay
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="stakeType"></param>
        /// <param name="reddeSettings"></param>
        /// <param name="MomoNumber"></param>
        /// <returns>The generated token and checkout Tranaction id</returns>
        public static async Task <(string token, int?checkoutransId)> GenerateReddeToken(EntityTypes entityType, IStakeType stakeType, ReddeSettingsDTO reddeSettings, string MomoNumber = null)
        {
            string customerMobileNumber = MomoNumber ?? stakeType.User.PhoneNumber;

            //string customerEmail = email == "default" ? stakeType.User.Email : email;
            try
            {
                ReddeCheckoutRequest request = new ReddeCheckoutRequest
                {
                    Amount          = stakeType.Amount,
                    Apikey          = reddeSettings.ApiKey,
                    Appid           = reddeSettings.AppId,
                    Description     = entityType.GetType().Name + " Investment",
                    Failurecallback = "https://ntoboasuccess.com",
                    Logolink        = "https://ntoboafund.com/assets/images/ntlog.png",
                    Merchantname    = reddeSettings.NickName,
                    Clienttransid   = stakeType.Id,
                    Successcallback = "https://ntoboafailure.com",
                };

                var httpClient = new HttpClient();


                var data = JsonConvert.SerializeObject(request, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
                var stringContent = new StringContent(data);
                httpClient.DefaultRequestHeaders.Add("apikey", reddeSettings.ApiKey);
                stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var responseMessage = await httpClient.PostAsync("https://api.reddeonline.com/v1/checkout/", stringContent);

                var contentString = await responseMessage.Content.ReadAsStringAsync();

                ReddeCheckoutResponse response = JsonConvert.DeserializeObject <ReddeCheckoutResponse>(contentString);

                return(response.Responsetoken, response.Checkouttransid);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"GenerateReddeToken {ex.Message}");
                return(null, null);
            }
        }
Пример #2
0
        private static async Task <int?> GenerateAndSendReddeInvoice(EntityTypes entityType, IStakeType stakeType, ReddeSettingsDTO reddeSettings, string PayOption, string MomoNumber = null, string voucher = null)
        {
            string customerMobileNumber = MomoNumber ?? stakeType.User.PhoneNumber;

            //string customerEmail = email == "default" ? stakeType.User.Email : email;
            try
            {
                ReddeRequest request = new ReddeRequest
                {
                    Amount          = stakeType.Amount,
                    Appid           = reddeSettings.AppId,
                    Clientreference = stakeType.TxRef,
                    Clienttransid   = stakeType.TxRef,
                    Description     = entityType.ToString() + " Investment",
                    Nickname        = reddeSettings.NickName,
                    Paymentoption   = PayOption,
                    Vouchercode     = voucher,
                    Walletnumber    = FormatGhanaianPhoneNumberWp(customerMobileNumber)
                };

                var httpClient = new HttpClient();


                var data = JsonConvert.SerializeObject(request, new JsonSerializerSettings {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                });
                var stringContent = new StringContent(data);
                httpClient.DefaultRequestHeaders.Add("apikey", reddeSettings.ApiKey);
                stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var responseMessage = await httpClient.PostAsync("https://api.reddeonline.com/v1/receive", stringContent);

                var contentString = await responseMessage.Content.ReadAsStringAsync();

                ReddeInitialResponse response = JsonConvert.DeserializeObject <ReddeInitialResponse>(contentString);

                return(response.Transactionid);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"GenerateReddeToken {ex.Message}");
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Sends the momo invoice to users phone
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="stakeType"></param>
        /// <param name="redSettings"></param>
        /// <param name="momoAndVoucher"></param>
        /// <returns>Transaction Id</returns>
        public static async Task <int?> GenerateAndSendReddeMomoInvoice(EntityTypes entityType, IStakeType stakeType, ReddeSettingsDTO redSettings, string momoAndVoucher)
        {
            var mandV      = momoAndVoucher.Split('*');
            var MomoNumber = mandV[0];
            var voucher    = mandV[1];

            if (string.IsNullOrEmpty(MomoNumber))
            {
                return(null);
            }

            return(await GenerateAndSendReddeInvoice(entityType, stakeType, redSettings, getReddePayOption(MomoNumber), MomoNumber, voucher));
        }