public async Task <SalesOrder> GetPayPalOrderByExternalDocumentNumber(string externalDocumentNumber)
        {
            SalesOrder order = null;
            var        query = String.Format("salesOrders?$filter=externalDocumentNumber eq '{0}'", externalDocumentNumber);

            var apiEndPoint = this.ApiEndPoint + query;

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo);
                var responseMessage = await httpClient.GetAsync(apiEndPoint);

                if (responseMessage.IsSuccessStatusCode)
                {
                    var orders = JsonConvert.DeserializeObject <SalesOrders>(await responseMessage.Content.ReadAsStringAsync());
                    if (orders != null && orders.Value != null && orders.Value.Count > 0)
                    {
                        order = orders.Value[0];
                    }
                }
            }
            return(order);
        }
Beispiel #2
0
        public async Task <PayPalResponseOrder> CreateRequest(SalesOrder order, Customer customer)
        {
            PayPalResponseOrder response = null;
            var paypalOrder = new PayPalOrder()
            {
                Intent        = "AUTHORIZE",
                PurchaseUnits = new List <PurchaseUnit>()
                {
                    new PurchaseUnit()
                    {
                        Amount = new Amount()
                        {
                            CurrencyCode = order.CurrencyCode, Value = order.TotalAmountIncludingTax.ToString()
                        },
                        Payee = new Payee()
                        {
                            EmailAddress = config.payPalSandboxAccount, MerchantId = config.paypalMerchantId
                        },
                    },
                },
            };

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo);

                var jsonObject      = JsonConvert.SerializeObject(paypalOrder);
                var content         = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
                var responseMessage = await httpClient.PostAsync(ApiOrderEndpoint, content);

                if (responseMessage.IsSuccessStatusCode)
                {
                    response = JsonConvert.DeserializeObject <PayPalResponseOrder>(await responseMessage.Content.ReadAsStringAsync());
                }
            }
            return(response);
        }
        public async Task <SalesOrder> GetPayPalOrderByWebhook(WebHookEvent ev)
        {
            SalesOrder order       = null;
            var        apiEndPoint = this.ApiWebHookEndPoint + ev.Resource;

            log.LogInformation("GetPayPalOrderByWebhook with endpoint " + apiEndPoint);
            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo);
                var responseMessage = await httpClient.GetAsync(apiEndPoint);

                if (responseMessage.IsSuccessStatusCode)
                {
                    order = JsonConvert.DeserializeObject <SalesOrder>(await responseMessage.Content.ReadAsStringAsync());
                    //Only allow PAYPAL payments not yet paid and not being processed to be processed
                    if (order != null)
                    {
                        order = (order.PaymentTermsId.ToString().Equals(config.paymentTermsIdPayPal) &&
                                 order.ExternalDocumentNumber.Equals(String.Empty)) ? order : null;
                    }
                }
            }
            return(order);
        }
Beispiel #4
0
        public async Task <Employees> GetSaleagentByOrder(SalesOrder order)
        {
            Employees employees = null;

            if (order == null || String.IsNullOrEmpty(order.Salesperson))
            {
                return(null);
            }
            var query = String.Format("employees?$filter=number eq '{0}'", order.Salesperson);

            var apiEndPoint = this.ApiEndPoint + query;

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", this.AuthInfo);
                var responseMessage = await httpClient.GetAsync(apiEndPoint);

                if (responseMessage.IsSuccessStatusCode)
                {
                    employees = JsonConvert.DeserializeObject <Employees>(await responseMessage.Content.ReadAsStringAsync());
                }
            }
            return(employees);
        }