Пример #1
0
        public StripePaymentGatewayPage(float Amount)
        {
            InitializeComponent();
            BindingContext = model = new PaymentGatewayViewModel()
            {
                Amount = Amount
            };

            NavigationPage.SetHasBackButton(this, false);
            NavigationPage.SetHasNavigationBar(this, false);
        }
Пример #2
0
        public async Task <IActionResult> PaymentGateway(PaymentGatewayViewModel model)
        {
            var user = this._context.Users.FirstOrDefault(u => u.Id == model.UserId);

            if (user != null)
            {
                //Check file size of the uploaded thumbnail
                //reject if the file is greater than 2mb
                var fileSize = model.PaymentImage.Length;
                if ((fileSize / 1048576.0) > 14)
                {
                    ModelState.AddModelError("", "The file you uploaded is too large. Filesize limit is 14mb.");
                    return(View(model));
                }
                //Check file type of the uploaded thumbnail
                //reject if the file is not a jpeg or png
                if (model.PaymentImage.ContentType != "image/jpeg" && model.PaymentImage.ContentType != "image/png")
                {
                    ModelState.AddModelError("", "Please upload a jpeg or png file for the thumbnail.");
                    return(View(model));
                }
                //Formulate the directory where the file will be saved
                //create the directory if it does not exist
                var dirPath = _env.WebRootPath + "/images/payments-gateway/" + model.UserId.ToString();
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                //always name the file thumbnail.png
                var filePath = dirPath + "/payment-gateway.png";
                if (model.PaymentImage.Length > 0)

                {
                    //Open a file stream to read all the file data into a byte array
                    byte[] bytes = await FileBytes(model.PaymentImage.OpenReadStream());

                    //load the file into the third party (ImageSharp) Nuget Plugin
                    using (Image <Rgba32> image = Image.Load(bytes))
                    {
                        //use the Mutate method to resize the image 150px wide by 150px long
                        image.Mutate(x => x.Resize(400, 700));
                        //save the image into the path formulated earlier
                        image.Save(filePath);
                    }
                }


                return(RedirectToAction("Payment"));
            }

            return(NotFound());
        }