예제 #1
0
        public static HttpClient Client()
        {
            PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);
            var client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #2
0
        public async Task <IActionResult> Execute(string paymentId, string PayerId)
        {
            var environment = new SandboxEnvironment("Acc2-UPp-z25_Olh73h5VZB3XjR16eUKtL2lHoIc27IJn8-2f5R8-Kish229pYjzdy18KR8khHJRQO5Q", "EIb_0hbZQPAEioCGLAzVpn87zRswB7zLAoRtda06Oc4IhrDAmtGYAI2z6xYplX6TdARnsuVh2TC3tHNM");
            var client      = new PayPalHttpClient(environment);

            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution()
            {
                PayerId = PayerId
            });
            await _context.Orders.Where(m => m.Paymentid == paymentId).ForEachAsync(m => m.IsConfirm = true);

            await _context.SaveChangesAsync();

            try
            {
                BraintreeHttp.HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(Redirect("sold"));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(BadRequest(debugId));
            }
        }
예제 #3
0
        public async Task <IActionResult> Execute(string paymentId, string PayerId)
        {
            //SandboxEnvironment(clientId, clientSerect)
            string clientId     = "AYOwjSPbuM8boAckmyHBzPF3fS5jkqsE6-i-fd_2Y66bMFW7t9miYPklGgcNAdXweQa4ijsjCRQnElL1";
            string clientSecret = "EL485ImsKFuaWVHj8YqVRNwzc1-q8xsmFMaDnFyvBTwH5JT4zqyGe7dLT9F4-Q64-ebEaix79UYxnO4H";
            var    environment  = new SandboxEnvironment(clientId, clientSecret);
            var    client       = new PayPalHttpClient(environment);


            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution()
            {
                PayerId = PayerId
            });

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(RedirectToAction("Success"));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(RedirectToAction("Fail"));
            }
        }
예제 #4
0
        public async Task <object> Process(PaymentModel.Payment payment)
        {
            if (_paypalSettings == null)
            {
                throw new NullReferenceException("Paypal settings cannot be null.");
            }

            var env            = new SandboxEnvironment(_paypalSettings.ClientId, _paypalSettings.ClientSecret);
            var client         = new PayPalHttpClient(env);
            var paymentDetails = new PaymentMapper(payment).GetPaymentDetails();
            var request        = new PaymentCreateRequest();

            request.RequestBody(paymentDetails);

            try
            {
                var response = await client.Execute(request);

                var result = response.Result <PayPal.v1.Payments.Payment>();
                var json   = JsonConvert.SerializeObject(result);
                return(result);
            }
            catch (Exception ex)
            {
                return(ex);
            }
        }
예제 #5
0
        public async Task <Payment> CreatePaymentAsync(PaypalTransaction transaction)
        {
            PayPalEnvironment environment;

            if (isSandboxMode)
            {
                environment = new SandboxEnvironment(clientId, clientSecret);
            }
            else
            {
                environment = new LiveEnvironment(clientId, clientSecret);
            }
            var client = new PayPalHttpClient(environment);

            try
            {
                var payment = CreatePayment(transaction);
                var request = new PaymentCreateRequest().RequestBody(payment);

                var response = await client.Execute(request);

                var statusCode = response.StatusCode;
                var result     = response.Result <Payment>();
                return(result);
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(null);
            }
        }
예제 #6
0
        public async Task <Payment> ExecutePaymentAsync(PayVM payVM)
        {
            var paymentId = payVM.PaymentID;

            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            var body = new PaymentExecution()
            {
                PayerId = payVM.PayerID
            };

            request.RequestBody(body);

            string ClientID    = this.configuration.GetSection("ClientID").Get <string>();
            string Secret      = this.configuration.GetSection("Secret").Get <string>();
            var    environment = new SandboxEnvironment(ClientID, Secret);

            var client = new PayPalHttpClient(environment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(result);
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(new Payment());
            }
        }
예제 #7
0
        public async Task <Payment> CreatePayment(string intent, string paymentMethod = "credit_card", string invoiceNumber = null)
        {
            string ClientID    = this.configuration.GetSection("ClientID").Get <string>();
            string Secret      = this.configuration.GetSection("Secret").Get <string>();
            var    environment = new SandboxEnvironment(ClientID, Secret);

            var client  = new PayPalHttpClient(environment);
            var request = new PaymentCreateRequest();

            request.RequestBody(BuildRequestBody(intent, paymentMethod, invoiceNumber));

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(result);
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(new Payment());
            }
        }
예제 #8
0
        public static async Task <bool> ExecutePayment(string paymentId, string payerId)
        {
            SandboxEnvironment environment = new SandboxEnvironment(
                "AcsZudPzaw7QNmu68Q15SdtKMCM0HJMKO-q-Lp1IXgLwqe-Dt9CWOYqsBtZ_QiS2hVVL0o50BK8xW0Dk",
                "EJo0Vn_JKFf5qq4pN6zOKm50fmYN4dI8ZTeB5j2vl5YtWRnKeAPOvXK2WZ4faxGA8QaUM1KhVj-kF8kr");

            _client = new PayPalHttpClient(environment);


            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution
            {
                PayerId = payerId
            });


            try
            {
                HttpResponse response = await _client.Execute(request);

                HttpStatusCode Status = response.StatusCode;

                return(Status.ToString() == "OK");
            }
            catch (HttpException)
            {
                return(false);
            }
        }
예제 #9
0
        public static IServiceCollection AddPayPalExpressCheckout(
            this IServiceCollection services,
            string sectionName = nameof(PayPalExpressCheckoutOptions),
            Action <PayPalExpressCheckoutOptions>?configureOptions = default)
        {
            services.AddChangeTokenOptions <PayPalExpressCheckoutOptions>(sectionName, configureAction: o => configureOptions?.Invoke(o));

            services.AddTransient <PayPalHttp.HttpClient>(sp =>
            {
                PayPalEnvironment environment;

                var options = sp.GetRequiredService <IOptionsMonitor <PayPalExpressCheckoutOptions> >().CurrentValue;

                if (options.IsSandBox)
                {
                    environment = new SandboxEnvironment(options.ClientId, options.ClientSecret);
                }
                else
                {
                    environment = new LiveEnvironment(options.ClientId, options.ClientSecret);
                }

                return(new PayPalHttpClient(environment));
            });

            return(services);
        }
예제 #10
0
        public async Task <IActionResult> Execute(string paymentId, string PayerId)
        {
            //SandboxEnvironment(clientId, clientSerect)
            string clientId     = "ATEyDHMWKozlcGDf5yNduG92WTeajJf9gqXc34Dd0AU7LbWgFvH3qY_8ImvFfZls5uZMzaoeZAdZBCrm";
            string clientSecret = "EH1J-u4MfbsyBENy8zBoVHHOnU9DMsDRjGDaXwfZltNEVc3rv_t26ANZ_L2Z4eQlS12oRnUj_Zr8dizO";
            var    environment  = new SandboxEnvironment(clientId, clientSecret);
            var    client       = new PayPalHttpClient(environment);


            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution()
            {
                PayerId = PayerId
            });

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(RedirectToAction("Success"));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(RedirectToAction("Fail"));
            }
        }
        public async Task <PaymentServiceResponseDTO> CreateInvoice(Domain.Order order)
        {
            var environment = new SandboxEnvironment("AZTu0aTctY3TsQRanLBGIjRYVhzo7rc25etnkVduypxV38zDdRja0Z6_adpN7nakww62w667wNh4_OKT", "EPT6TcCPEuAbNrCatN0_FyrWFTGtO6-1c77lhSj_pMrIx3o2V09BnpZnhLe3CfGO0wtW0IULHGI4yrGc");
            var client      = new PayPalHttpClient(environment);

            int totalPrice = 0;

            foreach (var product in order.ProductsInOrder)
            {
                totalPrice += product.Product.Price;
            }

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        ItemList = new ItemList(),
                        Amount   = new Amount()
                        {
                            Total    = totalPrice.ToString(),
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(new PaymentServiceResponseDTO {
                    PaymentUrl = result.Links.FirstOrDefault(link => link.Rel == APPROVAL_URL).Href
                });
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(null);
            }
        }
예제 #12
0
        public async Task <string> PaypalPayment(double total)
        {
            var environment = new SandboxEnvironment(configuration["PayPal:clientId"], configuration["PayPal:secret"]);
            var client      = new PayPalHttpClient(environment);

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = total.ToString(),
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = configuration["PayPal:cancelUrl"],
                    ReturnUrl = configuration["PayPal:returnUrl"]
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);
            string paypalRedirectUrl = null;

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                var     links      = result.Links.GetEnumerator();
                while (links.MoveNext())
                {
                    LinkDescriptionObject lnk = links.Current;
                    if (lnk.Rel.ToLower().Trim().Equals("approval_url"))
                    {
                        //saving the payapalredirect URL to which user will be redirected for payment
                        paypalRedirectUrl = lnk.Href;
                    }
                }
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
            }
            return(paypalRedirectUrl);
        }
예제 #13
0
        public async Task <string> CreateInvoice(Basket basket)
        {
            var environment = new SandboxEnvironment("AUcBbHNGlkF8pMud0Imkq_lEkvMeN2ebB3_fDS7-NIfvndr5x7maf6ol2WczTBEG5d4qoXHckCMqID5u", "EH8ICa3Sh-oEy_DXHDAzRpl8pjLWD2bphuGoUJeO39U-AqYr3ycFSi_icSjfz6lgz4O28VEuH91Ps33K");
            var client      = new PayPalHttpClient(environment);

            int totalPrice = 0;

            foreach (var product in basket.Products.ToList())
            {
                totalPrice += product.Cost;
            }

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        ItemList = new ItemList(),
                        Amount   = new Amount()
                        {
                            Total    = totalPrice.ToString(),
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(result.Links.FirstOrDefault(link => link.Rel == APPROVAL_URL).Href);
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(null);
            }
        }
예제 #14
0
        public PayPalHttpClient getClient()
        {
            // Creating a sandbox environment
            var environment = new SandboxEnvironment(ClientId, ClientSecret);

            // Creating a client for the environment
            var client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #15
0
        public static PayPalEnvironment environment()
        {
            SandboxEnvironment e = new SandboxEnvironment(
                System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID") != null ?
                System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID") : "AUzXMqocpNRiSklEJVwW2NVAyFJWpM5W6HF3u5ZfE9Q84xWyzXd1trIKX531Z8oyU_62Dg0robvJHi9U",
                System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET") != null ?
                System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET") : "EBROKA7H9paW6bJ9CEY3xM0C3bBn1RmjmTutN68fdOa8X2RnyWskM4voyDP7r6bMesbfhjcrcGVCfkd1");

            return(e);
        }
예제 #16
0
        public HttpClient Client()
        {
            // Creating a sandbox environment
            PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);

            // Creating a client for the environment
            PayPalHttpClient client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #17
0
        //public static async Task<CreditCard>  CreateCreditCard(CardModel card)
        //{
        //    // ### Api Context
        //    // Pass in a `APIContext` object to authenticate
        //    // the call and to send a unique request id
        //    // (that ensures idempotency). The SDK generates
        //    // a request id if you do not pass one explicitly.
        //    var environment = new SandboxEnvironment("AXBzX3BK0EIKIf87NiLs0FF56f6CBINvplAEI-eGQA5UCzlpzpsu1GwG3Jbz_0UaMcGVn6QF9xifYafT", "EHX5uun_f-IokPZKeziZPr8bP_S7NScvdqpw13mXaaHJz2TSVlNhsY8TjHqM3PTSzeZnDjkjtc4SlvtR");
        //    var client = new PayPalHttpClient(environment);
        //    // Payment Resource
        //    var creditCard = new CreditCard()
        //    {
        //        BillingAddress = new Address()
        //        {
        //            City = card.City,
        //            CountryCode = card.Country,
        //            Line1 = card.Address1,
        //            Line2 = card.Address2,
        //        },
        //        Cvv2 = card.CVC,
        //        ExpireMonth = card.Exp_Month,
        //        ExpireYear = card.Exp_Year,
        //        LastName = card.Name,
        //        Number = card.CardNumber,
        //        Type = card.Type
        //    };
        //    FundingInstrument fundInstrument = new FundingInstrument();
        //    fundInstrument.CreditCard = creditCard;

        //    List<FundingInstrument> fundingInstrumentList = new List<FundingInstrument>();
        //    fundingInstrumentList.Add(fundInstrument);
        //    client.
        //    PaymentCreateRequest request = new PaymentCreateRequest();
        //    request.RequestBody(payment);
        //    // Create a payment using a valid APIContext
        //    try
        //    {
        //        HttpResponse response = await client.Execute(request);
        //        var statusCode = response.StatusCode;
        //        Payment result = response.Result<Payment>();
        //        return result;
        //    }
        //    catch (HttpException httpException)
        //    {
        //        var statusCode = httpException.StatusCode;
        //        var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
        //    }

        //}

        public static async Task <Payment> ExecutePayment(string paymentId, string payerId)
        {
            var environment = new SandboxEnvironment("AXBzX3BK0EIKIf87NiLs0FF56f6CBINvplAEI-eGQA5UCzlpzpsu1GwG3Jbz_0UaMcGVn6QF9xifYafT", "EHX5uun_f-IokPZKeziZPr8bP_S7NScvdqpw13mXaaHJz2TSVlNhsY8TjHqM3PTSzeZnDjkjtc4SlvtR");
            var client      = new PayPalHttpClient(environment);
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.

            // Payment Resource
            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = "10",
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);
            // Create a payment using a valid APIContext
            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(result);
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
            }
            return(null);
        }
예제 #18
0
        public async Task <string> PayPalPaymentAsync(int orderPrice)
        {
            const string CLIENT_ID     = "Ab8zPbxBbiYu1TuE-3jyw0M6m41tBR4mhjXNDP1ZzQMEJ4JfQ9yJJy3qLT2LrO0oIrf-qpm7beMLAAXD";
            const string CLIENT_SECRET = "EMSYp9szDMBOMFd-nag3_VbHHm7LieAVIFK4FZNtidyRfGpIQwhcnEfdwPlophxERxgkhHsUMRngbm09";

            var environment = new SandboxEnvironment(CLIENT_ID, CLIENT_SECRET);
            var client      = new PayPalHttpClient(environment);

            var payment = new Payment
            {
                Intent = "order",

                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = orderPrice.ToString(),
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },

                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(response.StatusCode.ToString());
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(statusCode.ToString());
            }
        }
예제 #19
0
        private HttpClient Client()
        {
            PayPalEnvironment environment =
                new SandboxEnvironment(
                    CommonSecurityConstants.PaypalClientId,
                    CommonSecurityConstants.PaypalClientSecret);

            PayPalHttpClient client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #20
0
        public async Task <string> ExecutePayment(string paymentId, string token, string payerId, string email)
        {
            var environment = new SandboxEnvironment("AV8B5CBqWFqiUEBdhbe2rBVqX0RwNjY74nORYSEI3P8WZ-rRzRxXd1H0pA_qrywn0MCZuXzg3x-WwDeY", "EL-1QQduQKljgE0uHFs6WKAM4JtYrbf8CzOisxNCczPvdnkQYQDT1-rCM1W1dYM3Dhu8L9AcwqwhKdZH");
            var client      = new PayPalHttpClient(environment);
            PaymentExecuteRequest request = new PaymentExecuteRequest(paymentId);

            request.RequestBody(new PaymentExecution()
            {
                PayerId = payerId
            });


            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                //PayerId en payment opslaan in DB
                var employee = _context.Employees.Find(email);
                employee.Balance = employee.Balance + 10;
                Models.Transaction transaction = new Models.Transaction()
                {
                    Amount                = 10,
                    DateTime              = DateTime.UtcNow,
                    Employee              = employee,
                    employeeEmail         = email,
                    ProviderName          = "PayPal",
                    ProviderTransactionId = paymentId,
                    TransactionType       = "ExternalTopUp"
                };
                try
                {
                    _context.Add(transaction);
                    _context.Update(employee);
                    await _context.SaveChangesAsync();

                    return("Complete");
                }
                catch (SqlException error)
                {
                    _logger.LogError("While running this error showed up:", error);
                    return("Failed");
                }
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return("Failed");
            }
        }
        private async Task <PayPal.v1.Payments.Payment> ExecutePayment(string payerId, string paymentId)
        {
            var environment      = new SandboxEnvironment(_configuration["Service:Paypal:ClientId"], _configuration["Service:Paypal:ClientSecret"]);
            var client           = new PayPalHttpClient(environment);
            var paymentExecution = new PaymentExecution {
                PayerId = payerId
            };
            var paymentExecutionRequest = new PaymentExecuteRequest(paymentId).RequestBody(paymentExecution);
            var response = await Task.Run(() => client.Execute <PaymentExecuteRequest>(paymentExecutionRequest));

            return(response.Result <PayPal.v1.Payments.Payment>());
        }
예제 #22
0
        public async Task <PaymentServiceResponseDTO> CreateInvoice(Domain.Order order)
        {
            var environment = new SandboxEnvironment("AdV4d6nLHabWLyemrw4BKdO9LjcnioNIOgoz7vD611ObbDUL0kJQfzrdhXEBwnH8QmV-7XZjvjRWn0kg", "EPKoPC_haZMTq5uM9WXuzoxUVdgzVqHyD5avCyVC1NCIUJeVaNNUZMnzduYIqrdw-carG9LBAizFGMyK");
            var client      = new PayPalHttpClient(environment);

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = "10",
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                return(new PaymentServiceResponseDTO
                {
                    PaymentUrl = result.Links.FirstOrDefault(link => link.Rel == APPROVAL_URL).Href
                });
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(null);
            }
        }
예제 #23
0
        public async Task <PaymentServiceResponseDTO> CreateInvoice(Domain.Order order)
        {
            var environment = new SandboxEnvironment("AVKtkv3o13BU3eqJMpxTDJepdIsPUy1wwZNItREABfTzfc5pVhunjudf5LhzctAPw_WTC6Vvgaap5HSu", "EFCsGNXXcPrxCGkyuJM5d4Ge-fKzBeBtvE6tcDk4LOAGAFghMXDIPai8hMWKah5LLmz2ZaIPzG69fyzY");
            var client      = new PayPalHttpClient(environment);

            var payment = new Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = "10",
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                return(new PaymentServiceResponseDTO
                {
                    PaymentUrl = result.Links.FirstOrDefault(link => link.Rel == APPROVAL_URL).Href
                });
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(null);
            }
        }
예제 #24
0
        public async Task <IActionResult> ConfirmAsync([FromRoute] string id)
        {
            string webroot     = HttpContext.Request.Scheme;
            string webroot1    = HttpContext.Request.Host.ToUriComponent();
            string pathReturn  = "http://" + webroot1 + "/paypal/execute-payment";
            string pathCancel  = "http://" + webroot1 + "/paypal/cancel";
            var    environment = new SandboxEnvironment("Acc2-UPp-z25_Olh73h5VZB3XjR16eUKtL2lHoIc27IJn8-2f5R8-Kish229pYjzdy18KR8khHJRQO5Q", "EIb_0hbZQPAEioCGLAzVpn87zRswB7zLAoRtda06Oc4IhrDAmtGYAI2z6xYplX6TdARnsuVh2TC3tHNM");
            var    client      = new PayPalHttpClient(environment);
            string idUser      = id;
            var    payment     = new Payment()
            {
                Intent       = "sale",
                Transactions = GetTransactionsList(id),
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = pathCancel,
                    ReturnUrl = pathReturn
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                },
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);
            var path = CreateExcelOrder.Create(_context.Orders.Where(m => m.UserId == id).Where(m => m.IsConfirm == false).ToList(), id, _environment);

            try
            {
                BraintreeHttp.HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                LinkDescriptionObject approvalLink = PaypalHelpers.findApprovalLink(result.Links);
                var orders = _context.Orders.Include(m => m.Product).Where(m => m.UserId == id).Where(m => m.IsConfirm == false);
                await orders.ForEachAsync(m => m.Paymentid = result.Id);

                await _context.SaveChangesAsync();

                return(Ok(new ConfirmModel {
                    confirmPath = approvalLink.Href.ToString(), excelPath = path
                }));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(NoContent());
            }
        }
예제 #25
0
        public static HttpClient client()
        {
            string clientId = ConfigurationManager.AppSettings["pwdEmail"].ToString();
            string secret   = ConfigurationManager.AppSettings["pwdEmail"].ToString();

            // Creating a sandbox environment
            PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);

            // Creating a client for the environment
            PayPalHttpClient client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #26
0
        public PayPalHttpClient Client()
        {
            _clientId = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_PayPalClient");
            _secret   = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_PayPalSecret");

            // Creating a sandbox environment
            var environment = new SandboxEnvironment(_clientId, _secret);

            // Creating a client for the environment
            var client = new PayPalHttpClient(environment);

            return(client);
        }
예제 #27
0
        public async Task <Payment> CreatePayment()
        {
            var    environment = new SandboxEnvironment("AfCRA5WhUKekcea2LHhTYMHVsDNixBuPFeqygJ9W3m6IkfKHrmp8JHryqWe_XMVXH1TJnaHIphmYJg6Z", "EL00PS-mY7IzkA-_NsGkHxTdBFE2Wz2jPh8NnaDjkIbCUJJSY-6iOA73q12Gpwuw0cn3Kb6e8z76PlVF");
            var    client      = new PayPalHttpClient(environment);
            string intent      = "sale";

            var payment = new Payment()
            {
                Intent = intent,

                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = "10",
                            Currency = "VND",
                        }
                    }
                },

                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal",
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();

                return(result);
            }
            catch (Exception exception)
            {
                return(null);
            }
        }
예제 #28
0
        public async Task <string> PayPalPaymentAsync(int orderPrice)
        {
            var environment = new SandboxEnvironment("AR_Hs07d93iQYwXhs9EQ6IDyzPfQEglNyWASQy0ge5LzeFgBa_KCcLefYAH1k-AhbiFxYM9R812rrTQT", "EHvkxwY2zbqtPEVtzs5lzsuLU1nBOP3mdndiM_iPnZt0A1gLuDdUjXW3GBrdXpaXpxGscjCZ37VMcCk-");
            var client      = new PayPalHttpClient(environment);

            var payment = new Payment
            {
                Intent = "order",

                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = orderPrice.ToString(),
                            Currency = "USD"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    CancelUrl = "https://example.com/cancel",
                    ReturnUrl = "https://example.com/return"
                },

                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            try
            {
                HttpResponse response = await client.Execute(request);

                var     statusCode = response.StatusCode;
                Payment result     = response.Result <Payment>();
                return(response.StatusCode.ToString());
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(statusCode.ToString());
            }
        }
예제 #29
0
        public async Task <HttpResponse> GetTransaction(string OrderId, bool debug = false)
        {
            //string orderId = "8TH80554NC7396247";
            string orderId = "23139793XR804084D";

            try
            {
                //RefundsGetRequest
                //CapturesGetRequest

                var request = new OrdersCaptureRequest(orderId);
                request.RequestBody(new OrderActionRequest());
                PayPalEnvironment payPalEnvironment = new SandboxEnvironment("Af8jLh10kVlYkx4lunz6GSduOt92LyS_hRCOjzRZaU1SZrr1Eb7xYXBjLn-ue6SqiVlsTCEPPlMmL4bI", "EKQBNJEbuBx-yIx0vdtFTiptyfnnyjQVYwhPAmiuKe19T3Viko-B8E-wYrfQuvGdVCOJ97zH9-arreb4");

                var response = await new PayPalHttpClient(payPalEnvironment).Execute(request);
                var result   = response.Result <Order>();

                foreach (PurchaseUnit purchaseUnit in result.PurchaseUnits)
                {
                    foreach (PayPalCheckoutSdk.Orders.Capture capture in purchaseUnit.Payments.Captures)
                    {
                        //captureId = capture.Id;
                    }
                }

                Console.WriteLine("Retrieved Order Status");
                //result.Payer.A
                Console.WriteLine("Status: {0}", result.Status);
                Console.WriteLine("Order Id: {0}", result.Id);
                //Console.WriteLine("Intent: {0}", result.CheckoutPaymentIntent);
                Console.WriteLine("Links:");
                //foreach (LinkDescription link in result.Links)
                //{
                //    Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                //}
                // AmountWithBreakdown amount = result.PurchaseUnits[0].AmountWithBreakdown;
                // Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value);
                //   Console.WriteLine("Response JSON: \n {0}", PayPalClient.ObjectToJSONString(result));
                return(response);
            }
            catch (Exception e)
            {
                OrdersGetRequest request = new OrdersGetRequest(orderId);

                PayPalEnvironment payPalEnvironment = new SandboxEnvironment("Af8jLh10kVlYkx4lunz6GSduOt92LyS_hRCOjzRZaU1SZrr1Eb7xYXBjLn-ue6SqiVlsTCEPPlMmL4bI", "EKQBNJEbuBx-yIx0vdtFTiptyfnnyjQVYwhPAmiuKe19T3Viko-B8E-wYrfQuvGdVCOJ97zH9-arreb4");

                return(await new PayPalHttpClient(payPalEnvironment).Execute(request));
            }
        }
예제 #30
0
        public async Task <IActionResult> Execute(string token)
        {
            var environment = new SandboxEnvironment("Acc2-UPp-z25_Olh73h5VZB3XjR16eUKtL2lHoIc27IJn8-2f5R8-Kish229pYjzdy18KR8khHJRQO5Q", "EIb_0hbZQPAEioCGLAzVpn87zRswB7zLAoRtda06Oc4IhrDAmtGYAI2z6xYplX6TdARnsuVh2TC3tHNM");
            var client      = new PayPalHttpClient(environment);

            try
            {
                return(Redirect("cancel"));
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                return(BadRequest(debugId));
            }
        }