Exemplo n.º 1
0
        public string DataBindEmail(SalesOrder order, PayPalResponseOrder responseOrder)
        {
            StringBuilder message = new StringBuilder();

            if (order == null)
            {
                return(String.Format("Sorry, order not found"));
            }

            message.Append(String.Format("The {0} order ", order.Number));
            message.Append(String.Format("is in status {0} and ready to be paid with PayPal<br>", order.Status));
            message.Append(String.Format("The total amount to pay is {0} {1}<br>", order.TotalAmountIncludingTax.ToString(), order.CurrencyCode));
            message.Append(String.Format("<a href='{0}/AzPayPal?orderID={1}'>Click here to pay with paypal</a>", config.paypalPlaceholderUrl, responseOrder.Id));

            return(message.ToString());
        }
Exemplo n.º 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);
        }