Exemple #1
0
        public async Task <string> CancelRecurring(string userId = null, string profileId = null)
        {
            var responseData = string.Empty;

            try
            {
                var parameters = new List <KeyValuePair <string, string> > {
                    new KeyValuePair <string, string>("METHOD", "ManageRecurringPaymentsProfileStatus"),
                    new KeyValuePair <string, string>("VERSION", "204.0"),
                    new KeyValuePair <string, string>("USER", _appSettings.PaypalApiUsername),
                    new KeyValuePair <string, string>("PWD", _appSettings.PaypalApiPassword),
                    new KeyValuePair <string, string>("SIGNATURE", _appSettings.PaypalApiSignature),
                    new KeyValuePair <string, string>("ACTION", "Cancel")
                };


                if (!string.IsNullOrEmpty(userId))
                {
                    var paymentResponse = await WebApiReq.GetReq($"/api/PaymentTransaction/GetUserPaymentProfiles?id={userId}", "", "", _appSettings.ApiDomain);

                    if (paymentResponse.IsSuccessStatusCode)
                    {
                        var payments = await paymentResponse.Content.ReadAsAsync <PaymentTransaction>();

                        profileId = payments.paymentId;
                    }
                }

                if (!string.IsNullOrEmpty(profileId))
                {
                    parameters.Add(new KeyValuePair <string, string>("PROFILEID", profileId));

                    var response = await WebApiReq.PostReq("", parameters, "", "", _appSettings.PaypalExpressUrl);

                    if (response.IsSuccessStatusCode)
                    {
                        try
                        {
                            responseData = await response.Content.ReadAsStringAsync();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            throw;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(responseData);
        }
Exemple #2
0
        public static async Task <string> GetUserProfileCount(long userId, Helpers.AppSettings _appSettings, ILogger _logger)
        {
            string count = "0";
            HttpResponseMessage response = await WebApiReq.GetReq("/api/User/GetUserProfileCount?userId=" + userId, "", "", _appSettings.ApiDomain);

            if (response.IsSuccessStatusCode)
            {
                try
                {
                    count = await response.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.StackTrace);
                    count = "Error while getting profiles count";
                }
            }
            else
            {
                count = "Error while calling profile count api.";
            }
            return(count);
        }