Esempio n. 1
0
        public async Task <JsonResult> ErrorBill(PayPal.v1.Payments.Payment payment)
        {
            Logging logging = new Logging();

            logging.ErrorLogs(payment.ToString());

            return(Json(payment));
        }
Esempio n. 2
0
        public async Task <ActionResult> Pay(string prijs, string o_email = "", string o_name = "", string o_postal = "", string o_address = "", string o_number = "")
        {
            var db = new ModelContext();
            //if userId null "UserId = HttpContext.Session.GetInt32("SessionAccountId");" en de user zelf zijn data laten invullen
            var UserId = HttpContext.Session.GetInt32("UID");

            o_email   = o_email.Replace(" ", "_");
            o_postal  = o_postal.Replace(" ", "_");
            o_address = o_address.Replace(" ", "_");
            o_number  = o_number.Replace(" ", "_");
            if (UserId == null)
            {
                var checkEmail = (from s in db.Account where s.email == o_email select s.email).Any();
                if (checkEmail == true)
                {
                    var getEmail = (from s in db.Account where s.email == o_email select s).Single();
                    HttpContext.Session.SetInt32("SessionAccountId", getEmail.id);
                    db.Account.Remove(getEmail);
                    db.SaveChanges();
                }
                UserId = HttpContext.Session.GetInt32("SessionAccountId");
                Account a = new Account
                {
                    id             = UserId.GetValueOrDefault(0),
                    email          = o_email,
                    password       = "",
                    voornaam       = "",
                    achternaam     = o_name,
                    straatnaam     = o_address,
                    huisnummer     = o_number,
                    postcode       = o_postal,
                    provincie      = "",
                    telefoonnummer = null,
                    IsUnregistered = true
                };

                db.Account.Add(a);
                db.SaveChanges();
            }
            int UserIdResult = (from s in db.Account where s.id == UserId select s.id).Single();

            o_name    = (from s in db.Account where s.id == UserIdResult select s.achternaam).Single();
            o_postal  = (from s in db.Account where s.id == UserIdResult select s.postcode).Single();
            o_address = (from s in db.Account where s.id == UserIdResult select s.straatnaam).Single();
            o_number  = (from s in db.Account where s.id == UserIdResult select s.huisnummer).Single();
            o_name    = o_name.Replace(" ", "_");
            o_postal  = o_postal.Replace(" ", "_");
            o_address = o_address.Replace(" ", "_");
            o_number  = o_number.Replace(" ", "_");
            // string o_aanhef, string o_name, string o_postal, string o_address, string o_number
            var environment = new SandboxEnvironment("ATAmdaFGY2Pz6CH83fmdK8OaXu2Wd8b9fLDyuU8X3SNiAzvu2_Ks4IU3wPiNbpE74nWIkhb4jN_7pz9E", "EOksjziNOaGEYh-OroCWTFT_EKDlqJEIpsrZLMtUhmYNxgDZ_v6KGwyL1MFcWJ-dfv97PApRKroAAT0g");
            var Pay_client  = new PayPalHttpClient(environment);

            Console.WriteLine("Prijs:" + prijs);
            var payment = new PayPal.v1.Payments.Payment()
            {
                Intent       = "sale",
                Transactions = new List <PayPal.v1.Payments.Transaction>()
                {
                    new PayPal.v1.Payments.Transaction()
                    {
                        Amount = new PayPal.v1.Payments.Amount()
                        {
                            Total    = prijs,
                            Currency = "EUR",
                            Details  = new  PayPal.v1.Payments.AmountDetails()
                            {
                                Subtotal = prijs
                            }
                        },
                        ItemList = new PayPal.v1.Payments.ItemList()
                        {
                            Items = new List <PayPal.v1.Payments.Item>()
                            {
                                new PayPal.v1.Payments.Item()
                                {
                                    Name        = "Petgoods4All Products",
                                    Currency    = "EUR",
                                    Price       = prijs,
                                    Quantity    = "1",
                                    Description = "Bedankt voor uw aankoop"
                                }
                            }
                        }
                        ,
                        Description = "Betaling Petgoods4All"
                    }
                },
                RedirectUrls = new PayPal.v1.Payments.RedirectUrls()
                {
                    CancelUrl = "http://localhost:56003/",
                    ReturnUrl = "http://localhost:56003/Order/OrderProducts?prijs=" + prijs + "&o_aanhef=" + "DHR/MVR." + "&o_name=" + o_name + "&o_postal=" + o_postal + "&o_address=" + o_address + "&o_number=" + o_number
                },
                Payer = new PayPal.v1.Payments.Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PayPal.v1.Payments.PaymentCreateRequest request = new PayPal.v1.Payments.PaymentCreateRequest();
            request.RequestBody(payment);
            System.Net.HttpStatusCode statusCode;

            try
            {
                BraintreeHttp.HttpResponse httpResponse = await Pay_client.Execute(request);

                BraintreeHttp.HttpResponse response = httpResponse;
                statusCode = response.StatusCode;
                PayPal.v1.Payments.Payment result = response.Result <PayPal.v1.Payments.Payment>();
                string redirectUrl = null;
                foreach (PayPal.v1.Payments.LinkDescriptionObject link in result.Links)
                {
                    if (link.Rel.Equals("approval_url"))
                    {
                        redirectUrl = link.Href;
                        Console.WriteLine(redirectUrl);
                        return(Redirect(redirectUrl));
                    }
                }
            }
            catch (BraintreeHttp.HttpException httpException)
            {
                statusCode = httpException.StatusCode;
                var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
                Console.WriteLine("Paypal_error: " + debugId + statusCode);
                return(Redirect("http://localhost:56003/"));
            }

            return(Redirect("http://localhost:56003/"));
        }
Esempio n. 3
0
        public async Task <string> ProcessPayment(PayPalTestViewModel model)
        {
            var environment = new SandboxEnvironment(_configuration["PayPal:SandBox:ClientId"], _configuration["PayPal:SandBox:ClientSecret"]);
            var client      = new PayPalHttpClient(environment);

            var payment = new PayPal.v1.Payments.Payment()
            {
                Intent       = "sale",
                Transactions = new List <Transaction>()
                {
                    new Transaction()
                    {
                        Amount = new Amount()
                        {
                            Total    = model.Amount,
                            Currency = "INR"
                        }
                    }
                },
                RedirectUrls = new RedirectUrls()
                {
                    ReturnUrl = _urlHelper.Action("Done", "Test", new { amt = model.Amount }, _context.HttpContext.Request.Scheme, _context.HttpContext.Request.Host.ToString()),
                    CancelUrl = _urlHelper.Action("Cancel", "Test", new { amt = model.Amount }, _context.HttpContext.Request.Scheme, _context.HttpContext.Request.Host.ToString())
                },
                Payer = new Payer()
                {
                    PaymentMethod = "paypal"
                }
            };

            PaymentCreateRequest request = new PaymentCreateRequest();

            request.RequestBody(payment);

            System.Net.HttpStatusCode statusCode;

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

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

            string redirectUrl = null;

            foreach (LinkDescriptionObject link in result.Links)
            {
                if (link.Rel.Equals("approval_url"))
                {
                    redirectUrl = link.Href;
                }
            }

            if (redirectUrl == null)
            {
                // Didn't find an approval_url in response.Links
                return(null);
            }
            else
            {
                return(redirectUrl);
            }
        }