public ActionResult OnceOff()
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase)
            {
                // Merchant Details
                merchant_id  = this.payFastSettings.MerchantId,
                merchant_key = this.payFastSettings.MerchantKey,
                return_url   = this.payFastSettings.ReturnUrl,
                cancel_url   = this.payFastSettings.CancelUrl,
                notify_url   = this.payFastSettings.NotifyUrl,

                // Buyer Details
                email_address = "*****@*****.**",

                // Transaction Details
                m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380",
                amount           = 30,
                item_name        = "Once off option",
                item_description = "Some details about the once off payment",

                // Transaction Options
                email_confirmation   = true,
                confirmation_address = "*****@*****.**"
            };

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #2
0
        public void Can_Generate_Correct_Signature_Without_Passphrase_Once_Off()
        {
            // Arrange
            var onceOffRequest = new PayFastRequest();

            // Merchant Details
            onceOffRequest.merchant_id  = "10004241";
            onceOffRequest.merchant_key = "132ncgdwrh2by";
            onceOffRequest.return_url   = "https://5ca4377c.ngrok.io/home/return";
            onceOffRequest.cancel_url   = "https://5ca4377c.ngrok.io/home/cancel";
            onceOffRequest.notify_url   = "https://5ca4377c.ngrok.io/home/notify";

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            onceOffRequest.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            onceOffRequest.amount           = 30;
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Some details about the once off payment";

            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            // Act
            var signature = onceOffRequest.signature;

            // Assert
            Assert.Equal("66d25171083fa3e36ff3ebaa3c7f0713", signature);
        }
예제 #3
0
        public ActionResult OnceOff()
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            //double amount = Convert.ToDouble(db.Items.Select(x => x.CostPrice).FirstOrDefault());
            //var products = db.Items.Select(x => x.Name).ToList();
            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = 1500;
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Some details about the once off payment";


            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #4
0
        public IActionResult OnceOff()
        {
            var onceOffRequest = new PayFastRequest(this._payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this._payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this._payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this._payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this._payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this._payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = User.Identity.Name;

            // Transaction Details, need to change to real details
            onceOffRequest.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            onceOffRequest.amount           = 30;
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Some details about the once off payment";
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this._payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
        public IActionResult OnceOff(int AmountDue)
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details

            onceOffRequest.email_address = "*****@*****.**";//"*****@*****.**";
            // Transaction Details
            onceOffRequest.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            onceOffRequest.amount           = AmountDue;
            onceOffRequest.item_name        = "Rental payment for the month";
            onceOffRequest.item_description = "Some details about the once off payment";

            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**"; //"*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #6
0
        public ActionResult AdHoc()
        {
            var adHocRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            adHocRequest.merchant_id  = this.payFastSettings.MerchantId;
            adHocRequest.merchant_key = this.payFastSettings.MerchantKey;
            adHocRequest.return_url   = this.payFastSettings.ReturnUrl;
            adHocRequest.cancel_url   = this.payFastSettings.CancelUrl;
            adHocRequest.notify_url   = this.payFastSettings.NotifyUrl;
            #endregion Methods
            // Buyer Details
            adHocRequest.email_address = "*****@*****.**";
            //double amount = Convert.ToDouble(db.FoodOrders.Select(x => x.Total).FirstOrDefault());
            //var products = db.FoodOrders.Select(x => x.UserEmail).ToList();
            // Transaction Details
            adHocRequest.m_payment_id     = "";
            adHocRequest.amount           = 70;
            adHocRequest.item_name        = "Adhoc Agreement";
            adHocRequest.item_description = "Some details about the adhoc agreement";

            // Transaction Options
            adHocRequest.email_confirmation   = true;
            adHocRequest.confirmation_address = "*****@*****.**";

            // Recurring Billing Details
            adHocRequest.subscription_type = SubscriptionType.AdHoc;

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{adHocRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #7
0
        public PayFastRequest MappToPayFastRequest(OnceOffPaymentModel onceOffPaymentModel)
        {
            var onceOffRequest = new PayFastRequest(onceOffPaymentModel.Merchant.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = onceOffPaymentModel.Merchant.MerchantId;
            onceOffRequest.merchant_key = onceOffPaymentModel.Merchant.MerchantKey;
            onceOffRequest.return_url   = onceOffPaymentModel.Merchant.ReturnUrl;
            onceOffRequest.cancel_url   = onceOffPaymentModel.Merchant.CancelUrl;
            onceOffRequest.notify_url   = onceOffPaymentModel.Merchant.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = onceOffPaymentModel.Buyer.EmailAddress; //  "*****@*****.**";
            onceOffRequest.name_first    = onceOffPaymentModel.Buyer.Firstname;    // "Testing";
            onceOffRequest.name_last     = onceOffPaymentModel.Buyer.Lastname;     //"User";

            // Transaction Details
            onceOffRequest.m_payment_id     = onceOffPaymentModel.Transaction.PaymentId;   // "8d00bf49-e979-4004-228c-08d452b86380";
            onceOffRequest.amount           = onceOffPaymentModel.Transaction.Amount;      //30;
            onceOffRequest.item_name        = onceOffPaymentModel.Transaction.Item;        //"Once off option";
            onceOffRequest.item_description = onceOffPaymentModel.Transaction.Description; //"Some details about the once off payment";

            // Transaction Options
            onceOffRequest.email_confirmation   = onceOffPaymentModel.Transaction.IsConfirmationEmailProvided; // true;
            onceOffRequest.confirmation_address = onceOffPaymentModel.Transaction.ConfirmationAddress;         // t"*****@*****.**";

            return(onceOffRequest);
        }
        public ActionResult AdHoc()
        {
            var adHocRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            adHocRequest.merchant_id  = this.payFastSettings.MerchantId;
            adHocRequest.merchant_key = this.payFastSettings.MerchantKey;
            adHocRequest.return_url   = this.payFastSettings.ReturnUrl;
            adHocRequest.cancel_url   = this.payFastSettings.CancelUrl;
            adHocRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            adHocRequest.email_address = "*****@*****.**";

            // Transaction Details
            adHocRequest.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            adHocRequest.amount           = 70;
            adHocRequest.item_name        = "Adhoc Agreement";
            adHocRequest.item_description = "Some details about the adhoc agreement";

            // Transaction Options
            adHocRequest.email_confirmation   = true;
            adHocRequest.confirmation_address = "*****@*****.**";

            // Recurring Billing Details
            adHocRequest.subscription_type = SubscriptionType.AdHoc;

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{adHocRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
        public ActionResult Recurring()
        {
            var recurringRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            recurringRequest.merchant_id  = this.payFastSettings.MerchantId;
            recurringRequest.merchant_key = this.payFastSettings.MerchantKey;
            recurringRequest.return_url   = this.payFastSettings.ReturnUrl;
            recurringRequest.cancel_url   = this.payFastSettings.CancelUrl;
            recurringRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            recurringRequest.email_address = "*****@*****.**";

            // Transaction Details
            recurringRequest.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            recurringRequest.amount           = 20;
            recurringRequest.item_name        = "Recurring Option";
            recurringRequest.item_description = "Some details about the recurring option";

            // Transaction Options
            recurringRequest.email_confirmation   = true;
            recurringRequest.confirmation_address = "*****@*****.**";

            // Recurring Billing Details
            recurringRequest.subscription_type = SubscriptionType.Subscription;
            recurringRequest.billing_date      = DateTime.Now;
            recurringRequest.recurring_amount  = 20;
            recurringRequest.frequency         = BillingFrequency.Monthly;
            recurringRequest.cycles            = 0;

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{recurringRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #10
0
        public ActionResult OnceOff()
        {
            var         onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);
            int         ReservationID  = int.Parse(Session["bookID"].ToString());
            RoomBooking roomBooking    = new RoomBooking();

            roomBooking = db.RoomBookings.Find(ReservationID);
            var userName = User.Identity.GetUserName();
            var guest    = db.guests.Where(x => x.Email == userName).FirstOrDefault();

            var attachments = new List <Attachment>();

            attachments.Add(new Attachment(new MemoryStream(GeneratePDF(ReservationID)), "Reservation Receipt", "application/pdf"));


            var mailTo = new List <MailAddress>();

            mailTo.Add(new MailAddress(User.Identity.GetUserName(), guest.FullName));
            var body = $"Hello {guest.FullName}, please see attached receipt for the recent reservation you made. <br/>Make sure you bring along your receipt when you check in for your room.<br/>";

            ExploreBookings.Models.EmailService emailService = new ExploreBookings.Models.EmailService();
            emailService.SendEmail(new EmailContent()
            {
                mailTo          = mailTo,
                mailCc          = new List <MailAddress>(),
                mailSubject     = "Application Statement | Ref No.:" + roomBooking.RoomBookingId,
                mailBody        = body,
                mailFooter      = "<br/> Many Thanks, <br/> <b>Explorer</b>",
                mailPriority    = MailPriority.High,
                mailAttachments = attachments
            });
            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details

            onceOffRequest.email_address = "*****@*****.**";
            //onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = Convert.ToDouble(roomBooking.Total);
            onceOffRequest.item_name        = "Room Booking payment";
            onceOffRequest.item_description = "Some details about the once off payment";

            BusinessLogic.UpdateRoomsAvailable(roomBooking.RoomId);
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #11
0
        public ActionResult OnceOff()
        {
            var       onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);
            int       eventId        = int.Parse(Session["event"].ToString());
            BookEvent èvent          = new BookEvent();

            èvent = db.BookEvents.Find(eventId);
            var userName = User.Identity.Name;
            var guest    = db.students.Where(x => x.StudentEmail == userName).FirstOrDefault();


            var attachments = new List <Attachment>();

            attachments.Add(new Attachment(new MemoryStream(GeneratePDF(eventId)), "Events Booking", "application/pdf"));


            var mailTo = new List <MailAddress>();

            mailTo.Add(new MailAddress(User.Identity.Name, guest.StudentName + guest.StudentSurname));
            var body = $"Hello {guest.StudentName + guest.StudentSurname}, Please see attached receipt for the recent rental you made. <br/>Make sure you bring along your receipt when you pick up your car.<br/>";

            DGSappSem2.Models.Events.EmailService emailService = new DGSappSem2.Models.Events.EmailService();
            emailService.SendEmail(new EmailContent()
            {
                mailTo          = mailTo,
                mailCc          = new List <MailAddress>(),
                mailSubject     = "Application Statement | Ref No.:" + èvent.RefNum,
                mailBody        = body,
                mailFooter      = "<br/> Many Thanks, <br/> <b>Explorer</b>",
                mailPriority    = MailPriority.High,
                mailAttachments = attachments
            });
            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details

            onceOffRequest.email_address = "*****@*****.**";
            //onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            //onceOffRequest.m_payment_id = "";
            onceOffRequest.m_payment_id         = èvent.RefNum;
            onceOffRequest.amount               = Convert.ToDouble(èvent.getEventPrice());
            onceOffRequest.item_name            = "Car Rental payment";
            onceOffRequest.item_description     = "Some details about the once off payment";
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #12
0
        public async Task <object> CreatepayFastOrder(string email, int deliveryMethodId, string basketId, CustomerBasket basket)
        {
            // get the basket
            // get items from the product repo
            var items = new List <OrderItem>();

            foreach (var item in basket.Items)
            {
                var productItem = await _unitOfWork.Repository <Product>().GetByIdAsync(item.Id);

                string photo = productItem.Photos.FirstOrDefault(x => x.IsMain)?.PictureUrl;
                string save  = item.PictureUrl.Split("Content/")[1];
                photo = (photo != null) ? photo : save;
                var itemOrdered = new ProductItemOrdered(productItem.Id, productItem.Name, photo
                                                         );
                var orderItem = new OrderItem(itemOrdered, productItem.Price, item.Quantity);
                items.Add(orderItem);
            }

            // get delivery method from repo
            var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId);

            // calc subtotal
            var subtotal = items.Sum(item => item.Price * item.Quantity);

            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase)
            {
                // Merchant Details
                merchant_id  = this.payFastSettings.MerchantId,
                merchant_key = this.payFastSettings.MerchantKey,
                return_url   = this.payFastSettings.ReturnUrl,
                cancel_url   = this.payFastSettings.CancelUrl,
                notify_url   = this.payFastSettings.NotifyUrl,

                // Buyer Details
                email_address = email,

                // Transaction Details
                m_payment_id     = Guid.NewGuid().ToString(),
                amount           = 3000,// (double)subtotal,
                item_name        = "Payment",
                item_description = "Some details about the once off payment",

                // Transaction Options
                email_confirmation   = false,
                confirmation_address = email
            };

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            var data = new { PaymentLink = redirectUrl, CallbackLink = this.payFastSettings.ReturnUrl };

            return(data);
        }
예제 #13
0
        public void Can_Handle_Defaults()
        {
            // Arrange
            var defaultStringContent = "amount=0&signature=8e0abf3d0916134016b922eb9ed3f4fe";
            var payFastViewModel     = new PayFastRequest();

            // Act
            var queryString = payFastViewModel.ToString();

            // Assert
            Assert.Equal(defaultStringContent, queryString);
        }
예제 #14
0
        public ActionResult ContractPayment()
        {
            var uid = User.Identity.GetUserId();

            var camount = (from i in db.Contracts
                           where i.Bookings.Client_ID == uid && i.Co_Status == "Unpaid"
                           select i.Co_Amount).Sum();

            var unpaidC = (from i in db.Contracts
                           where i.Bookings.Client_ID == uid && i.Co_Status == "Unpaid"
                           select i);

            foreach (var i in unpaidC)
            {
                i.Co_Status       = "Paid";
                db.Entry(i).State = EntityState.Modified;
            }

            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;
            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            double amount = (double)camount;

            //var products = db.Items.Select(x => x.Item_Name).ToList();
            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = amount;
            onceOffRequest.item_name        = "Contract Payment";
            onceOffRequest.item_description = "You are now paying your Contract Amount";
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            //remove when deployed



            db.SaveChanges();


            return(Redirect(redirectUrl));
        }
예제 #15
0
        public ActionResult OnceOff(int?id)
        {
            Booking booking = db.Bookings.Find(id);

            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;
            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            double amount = (double)booking.Book_TotalCost;

            //var products = db.Items.Select(x => x.Item_Name).ToList();
            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = amount;
            onceOffRequest.item_name        = "Your Order number is: " + id;
            onceOffRequest.item_description = "You are now paying your rental fee";
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            //remove when deployed
            booking.paymentstatus = true;


            var uid  = User.Identity.GetUserId();
            var spin = (from b in db.Spins
                        where b.Client_ID == uid
                        select b).FirstOrDefault();



            spin.No_Spins += 1;

            db.Entry(spin).State = EntityState.Modified;

            db.Entry(booking).State = EntityState.Modified;

            db.SaveChanges();


            return(Redirect(redirectUrl));
        }
예제 #16
0
        public ActionResult OnceOff(int id)
        {
            var         onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);
            Application application    = db.Applications.Where(a => a.ApplicationID == id).FirstOrDefault();

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            double amount   = 20 /* Convert.ToDouble(db.Items.Select(x => x.CostPrice).FirstOrDefault())*/;
            var    products = "Gold" /*db.Items.Select(x => x.Name).ToList()*/;
            // Transaction Details
            decimal?PackagePrice = (from p in db.Applications
                                    where p.ApplicationID == id
                                    select p.Amount).FirstOrDefault();

            var PackageName = (from p in db.Applications
                               where p.ApplicationID == id
                               select p.Package.PackageType.PackageName).FirstOrDefault();

            var Description = (from p in db.Applications
                               where p.ApplicationID == id
                               select p.Package.PackageDescription).FirstOrDefault();

            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = Convert.ToDouble(PackagePrice);
            onceOffRequest.item_name        = PackageName;
            onceOffRequest.item_description = Description;


            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            application.PaymentStatus   = "Approved";
            application.Status          = "Active";
            application.StartDate       = DateTime.Parse(DateTime.Now.ToString("yyy.MM.dd")).Date;
            application.ExpiryDateDate  = DateTime.Parse(DateTime.Now.ToString("yyy.MM.dd")).Date.AddMonths(1);
            db.Entry(application).State = EntityState.Modified;
            db.SaveChanges();
            return(Redirect(redirectUrl));
        }
        public ActionResult OnceOff(double amount, int idd)
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;

            onceOffRequest.cancel_url = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url = this.payFastSettings.NotifyUrl;

            onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            onceOffRequest.m_payment_id     = idd.ToString();
            onceOffRequest.amount           = amount;
            onceOffRequest.amount           = 10;
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Auction-prop Regestrasion fees.";

            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "";
            string rI = "";

            if (idd != 0)
            {
                rI = idd.ToString();
            }
            if (amount >= 5000)
            {
                try
                {
                    rI += "-5000";
                }
                catch { }
            }


            onceOffRequest.return_url = this.payFastSettings.ReturnUrl + rI;
            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";


            return(Redirect(redirectUrl));
        }
예제 #18
0
        public IActionResult OnceOff()
        {
            TempData["Product"] = TempData["Product"];
            TempData["Price"]   = TempData["Price"];
            TempData["NoxID"]   = TempData["NoxID"];
            TempData["Name"]    = TempData["Name"];
            TempData.Keep();
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            //onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            onceOffRequest.m_payment_id     = repo.GenerateCustomerPaymentID((int)TempData["CustomerID"]);
            onceOffRequest.amount           = Convert.ToDouble(TempData["Price"]);
            onceOffRequest.item_name        = TempData["Product"].ToString();
            onceOffRequest.item_description = "Once off payment for " + TempData["Name"] + TempData["Product"];
            // Transaction Options
            //onceOffRequest.email_confirmation = true;
            //onceOffRequest.confirmation_address = "*****@*****.**";

            StringBuilder str = new StringBuilder();

            str.Append("merchant_id=" + HttpUtility.UrlEncode(onceOffRequest.merchant_id));
            str.Append("&merchant_key=" + HttpUtility.UrlEncode(onceOffRequest.merchant_key));
            str.Append("&return_url=" + HttpUtility.UrlEncode(onceOffRequest.return_url));
            str.Append("&cancel_url=" + HttpUtility.UrlEncode(onceOffRequest.cancel_url));
            str.Append("&notify_url=" + HttpUtility.UrlEncode(onceOffRequest.notify_url));

            str.Append("&m_payment_id=" + HttpUtility.UrlEncode(onceOffRequest.m_payment_id));
            str.Append("&amount=" + HttpUtility.UrlEncode(onceOffRequest.amount.ToString("G", CultureInfo.InvariantCulture)));
            str.Append("&item_name=" + HttpUtility.UrlEncode(onceOffRequest.item_name));
            str.Append("&item_description=" + HttpUtility.UrlEncode(onceOffRequest.item_description));
            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{str.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #19
0
        //public byte[] GeneratePDF(string orderID)
        //{
        //    MemoryStream memoryStream = new MemoryStream();
        //    Document document = new XDocument(PageSize.A5, 0, 0, 0, 0);
        //    PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
        //    document.Open();

        //    Order order = db.Orders.Find(orderID);
        //    var userName = User.Identity.GetUserName();
        //    /* Find the details of the customer placing the order*/
        //    var customer = db.Customers.Where(x => x.Email == userName).FirstOrDefault();
        //    Order_Item order_Item = db.Order_Items.Find(orderID);

        //    //var reservation = _iReservationService.Get(Convert.ToInt64(ReservationID));
        //    //var user = _iUserService.Get(reservation.UserID);

        //    iTextSharp.text.Font font_heading_3 = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.RED);
        //    iTextSharp.text.Font font_body = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 9, iTextSharp.text.BaseColor.BLUE);

        //    // Create the heading paragraph with the headig font
        //    PdfPTable table1 = new PdfPTable(1);
        //    PdfPTable table2 = new PdfPTable(5);
        //    PdfPTable table3 = new PdfPTable(1);

        //    iTextSharp.text.pdf.draw.VerticalPositionMark seperator = new iTextSharp.text.pdf.draw.LineSeparator();
        //    seperator.Offset = -6f;
        //    // Remove table cell
        //    table1.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
        //    table3.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER;

        //    table1.WidthPercentage = 80;
        //    table1.SetWidths(new float[] { 100 });
        //    table2.WidthPercentage = 80;
        //    table3.SetWidths(new float[] { 100 });
        //    table3.WidthPercentage = 80;

        //    PdfPCell cell = new PdfPCell(new Phrase(""));
        //    cell.Colspan = 3;
        //    table1.AddCell("\n");
        //    table1.AddCell(cell);
        //    table1.AddCell("\n\n");
        //    table1.AddCell(
        //        "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" +
        //        "Alliance Properties SA \n" +
        //        "Email :[email protected]" + "\n" +
        //        "\n" + "\n");
        //    table1.AddCell("------------Customer Details--------------!");

        //    table1.AddCell("First Name : \t" + customer.FirstName);
        //    table1.AddCell("Last Name : \t" + customer.LastName);
        //    table1.AddCell("Phone Number : \t" + customer.phone);
        //    table1.AddCell("Address : \t" + customer.Address);

        //    table1.AddCell("\n------------Order details--------------!\n");

        //    table1.AddCell("Order # : \t" + orderID);
        //    table1.AddCell("Price : \t" + order_Item.price);
        //    table1.AddCell("Qauntity : \t" + order_Item.quantity);
        //    table1.AddCell("Items : \t" + order_Item.Item.Name);
        //    //table1.AddCell("Building name : \t" + roomBooking.BuildingId);
        //    //table1.AddCell("Building Address : \t" + roomBooking.BuildingAddress);

        //    table1.AddCell("\n");

        //    table3.AddCell("------------Looking forward to hear from you soon--------------!");

        //    //////Intergrate information into 1 document
        //    //var qrCode = iTextSharp.text.Image.GetInstance(roomBooking.QrCodeImage);
        //    //qrCode.ScaleToFit(200, 200);
        //    table1.AddCell(cell);
        //    document.Add(table1);
        //    //document.Add(qrCode);
        //    document.Add(table3);
        //    document.Close();

        //    byte[] bytes = memoryStream.ToArray();
        //    memoryStream.Close();
        //    return bytes;
        //}



        public ActionResult OnceOff(string id)
        {
            var order          = order_Service.GetOrder(id);
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);
            var payment        = new Payment();

            payment.AmountPaid    = order_Service.GetOrderTotal(order.Order_ID);
            payment.PaymentFor    = order.Order_ID;
            payment.PaymentMethod = "Pay Fast Payment";
            payment.Email         = User.Identity.GetUserName();
            payment.Order_ID      = order.Order_ID;
            payment.Date          = DateTime.Now;
            payment_Service.AddPayment(payment);
            order_Service.MarkOrderAsPaid(id);

            //SendMail(id);

            //var order=
            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            //double amount = Convert.ToDouble(db.Items.Select(x => x.CostPrice).FirstOrDefault());
            //var products = db.Items.Select(x => x.Name).ToList();
            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = order_Service.GetOrderTotal(order.Order_ID);
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Some details about the once off payment";


            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
        public ActionResult OnceOff()
        {
            var Delivery = (from x in db.Maps
                            where x.Email == User.Identity.Name
                            orderby x.Id descending
                            select x.Distance).First().ToString();
            double del            = Convert.ToDouble(Delivery);
            var    onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details

            List <Cart> listCart = (List <Cart>)Session[strCart];

            foreach (var cart in listCart)
            {
                double total = Convert.ToDouble(listCart.Sum(x => x.Quantity * x.ItemsHire.Price) + listCart.Sum(x => x.Quantity * x.ItemsHire.Price / 2)) + del;
                //string name = cart.ItemsHire.ProductName;
                string Desc = cart.ItemsHire.Description;
                onceOffRequest.m_payment_id = "8d00bf49-e979-4004-228c-08d452b86380";
                onceOffRequest.item_name    = ".";
                onceOffRequest.amount       = Convert.ToDouble(total);
            }
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            //return View("OrderSuccess");
            return(Redirect(redirectUrl));
        }
예제 #21
0
        public ActionResult OnceOff()
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            List <EventCart> listCart = (List <EventCart>)Session[stCart];

            foreach (var cart in listCart)
            {
                //var deposit = String.Format("{0:C}", listCart.Sum(x => x.Quantity * x.Package.Price / 3));
                //var total = String.Format("{0:C}", listCart.Sum(x => x.Quantity * x.Package.Price) + deposit);

                //double fTotal = Convert.ToDouble(deposit + total);
                double total = Convert.ToDouble(listCart.Sum(x => x.Quantity * x.Package.Price) + listCart.Sum(x => x.Quantity * x.Package.Price / 3));
                string name  = cart.Package.packageName;
                string Desc  = cart.Package.Description;
                onceOffRequest.m_payment_id = "8d00bf49-e979-4004-228c-08d452b86380";
                onceOffRequest.amount       = total;
                onceOffRequest.item_name    = cart.Quantity + "x" + name;
                //onceOffRequest.item_description ="sdfdsvc";
            }
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            /*return View("OrderSuccess");*/ //enable for local testing
            return(Redirect(redirectUrl));
        }
예제 #22
0
        public void Can_Generate_Correct_Signature_With_Passphrase()
        {
            // Arrange
            var passPhrase       = "salt";
            var payFastViewModel = new PayFastRequest(passPhrase);

            // Merchant Details
            payFastViewModel.merchant_id  = "10004241";
            payFastViewModel.merchant_key = "132ncgdwrh2by";
            payFastViewModel.return_url   = "http://f32149e3.ngrok.io/processing/successful";
            payFastViewModel.cancel_url   = "http://f32149e3.ngrok.io/processing/cancel";
            payFastViewModel.notify_url   = "http://f32149e3.ngrok.io/processing/notify";

            // Buyer Details
            payFastViewModel.email_address = "*****@*****.**";

            // Transaction Details
            payFastViewModel.m_payment_id     = "8d00bf49-e979-4004-228c-08d452b86380";
            payFastViewModel.amount           = 20;
            payFastViewModel.item_name        = "Option 2";
            payFastViewModel.item_description = "Some details about option 2";

            // Transaction Options
            payFastViewModel.email_confirmation   = true;
            payFastViewModel.confirmation_address = "*****@*****.**";

            // Recurring Billing Details
            payFastViewModel.subscription_type = SubscriptionType.Subscription;
            payFastViewModel.billing_date      = new DateTime(2017, 02, 14);
            payFastViewModel.recurring_amount  = 20;
            payFastViewModel.frequency         = BillingFrequency.Monthly;
            payFastViewModel.cycles            = 0;

            // Act
            var signature = payFastViewModel.signature;

            // Assert
            Assert.Equal("e11880438cdc68addba56f65d80d27a6", signature);
        }
예제 #23
0
        public ActionResult OnceOff(double amount, int?id)
        {
            var dbRecord = db.Bookings.Find(id);

            dbRecord.BookingStatus   = "Paid";
            db.Entry(dbRecord).State = EntityState.Modified;
            db.SaveChanges();
            EmailSender.SendBookingEmail(dbRecord);
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";
            //double amount = Convert.ToDouble(db.Items.Select(x => x.CostPrice).FirstOrDefault());
            //var products = db.Items.Select(x => x.Name).ToList();
            // Transaction Details
            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = amount;
            onceOffRequest.item_name        = "Once off option";
            onceOffRequest.item_description = "Some details about the once off payment";


            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";



            return(Redirect(redirectUrl));
        }
예제 #24
0
        public async Task <object> CreateOrderAsync(string buyerEmail, int deliveryMethodId, string basketId, Address shippingAddress)
        {
            // get basket from the repo
            var basket = await _basketRepo.GetBasketAsync(basketId); //working

            // get items from the product repo
            var items = new List <OrderItem>();

            foreach (var item in basket.Items)
            {
                var productItem = await _unitOfWork.Repository <Product>().GetByIdAsync(item.Id);

                string photo = productItem.Photos.FirstOrDefault(x => x.IsMain)?.PictureUrl;
                string save  = item.PictureUrl.Split("Content/")[1];
                photo = (photo != null) ? photo : save;
                var itemOrdered = new ProductItemOrdered(productItem.Id, productItem.Name, photo
                                                         );
                var orderItem = new OrderItem(itemOrdered, productItem.Price, item.Quantity);
                items.Add(orderItem);
            }

            // get delivery method from repo
            var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId);

            // calc subtotal
            var subtotal = items.Sum(item => item.Price * item.Quantity);

            // check to see if order exists
            //var spec = new OrderByPaymentIntentIdSpecification(basket.PaymentIntentId);
            //var existingOrder = await _unitOfWork.Repository<Order>().GetEntityWithSpec(spec);

            //if (existingOrder != null)
            //{
            //    _unitOfWork.Repository<Order>().Delete(existingOrder);
            //    await _paymentService.CreateOrUpdatePaymentIntent(basket.PaymentIntentId);
            //}

            // create order
            var order = new Order(items, buyerEmail, shippingAddress, deliveryMethod, subtotal, basket.PaymentIntentId);

            _unitOfWork.Repository <Order>().Add(order);

            // save to db
            var result = await _unitOfWork.Complete();

            //clear the cart
            basket.Items = new List <BasketItem>();
            var basketUpdate = await _basketRepo.UpdateBasketAsync(basket);

            if (result <= 0)
            {
                return(null);
            }


            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase)
            {
                // Merchant Details
                merchant_id  = this.payFastSettings.MerchantId,
                merchant_key = this.payFastSettings.MerchantKey,
                return_url   = this.payFastSettings.ReturnUrl,
                cancel_url   = this.payFastSettings.CancelUrl,
                notify_url   = this.payFastSettings.NotifyUrl,

                // Buyer Details
                email_address = buyerEmail,

                // Transaction Details
                m_payment_id     = Guid.NewGuid().ToString(),
                amount           = (double)subtotal,
                item_name        = "Payment",
                item_description = "Some details about the once off payment",

                // Transaction Options
                email_confirmation   = false,
                confirmation_address = buyerEmail
            };

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            OrderRet orderRet = new OrderRet()
            {
                PaymentURl      = redirectUrl,
                BuyerEmail      = order.BuyerEmail,
                DeliveryMethod  = order.DeliveryMethod,
                Id              = order.Id,
                OrderDate       = order.OrderDate,
                OrderItems      = order.OrderItems,
                PaymentIntentId = order.PaymentIntentId,
                ShipToAddress   = order.ShipToAddress,
                Status          = order.Status,
                Subtotal        = order.Subtotal
            };

            // return order
            return(orderRet);
        }
        //public ActionResult pay(int? id)
        //{
        //    StudentApplication studentApplication = db.Studentapplications.Find(id);
        //    var priceId = db.ClassFees.Where(p => p.ClassNameId == studentApplication.ClassNameId).Select(p => p.FeeTypeId).FirstOrDefault();
        //    var price = db.FeeTypes.Where(p => p.Id == priceId).Select(p => p.FeeAmount).FirstOrDefault();
        //    studentApplication.Status = "Paid";
        //    db.Entry(studentApplication).State = EntityState.Modified;

        //    // db.Studentapplications.Add(studentApplication);
        //    db.SaveChanges();
        //    return RedirectToAction("Index2");

        //}
        public ActionResult OnceOff(int?id)
        {
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details

            onceOffRequest.email_address = "*****@*****.**";
            //onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details
            CarHiring carHiring = db.CarHirings.Find(id);

            carHiring.status          = "Paid";
            db.Entry(carHiring).State = EntityState.Modified;
            db.SaveChanges();

            Car car = db.Cars.ToList().Find(x => x.CarId == carHiring.CarId);

            car.Status          = "Not Available";
            db.Entry(car).State = EntityState.Modified;
            db.SaveChanges();

            onceOffRequest.m_payment_id     = "";
            onceOffRequest.amount           = Convert.ToDouble(carHiring.Deposit);
            onceOffRequest.item_name        = "Car Hire Payment";
            onceOffRequest.item_description = "Some details about the once off payment";
            var userName = User.Identity.GetUserName();

            var mailTo = new List <MailAddress>();

            mailTo.Add(new MailAddress(userName, carHiring.CustomerName));
            var body = $"Dear {carHiring.CustomerName} {carHiring.CustomerSurname} <br/><br/>" +
                       $"Your car hiring was successful, please see details below: <br/><br/>" +
                       $"Hire Date:{System.DateTime.Now.Date} \n" +
                       $"Pick-Up Date: {carHiring.PickUpDate}\n" +
                       $"Return-Date: {carHiring.ReturnDate}\n" +
                       $"Number Of Days: {carHiring.numOfDays}\n" +
                       $"Deposit: {carHiring.Deposit}\n" +
                       $"Daily Cost: {carHiring.car.Cost_Per_Day}\n" +
                       $"Vehicle: {carHiring.car.carMake.CarMakeType} {carHiring.car.carModel.CarModelType}\n" +
                       $"Transmission: {carHiring.car.transmission.TransmissionType}\n" +
                       $"Fuel: {carHiring.car.fuel.FuelType}<br/>" +
                       $"Regards,<br/><br/> Bright Ideas <br/> .";

            LindaniDrivingSchool.Logic.EmailService emailService = new LindaniDrivingSchool.Logic.EmailService();
            emailService.SendEmail(new EmailContent()
            {
                mailTo          = mailTo,
                mailCc          = new List <MailAddress>(),
                mailSubject     = "Application Statement | Ref No.:" + carHiring.BookingId,
                mailBody        = body,
                mailFooter      = "<br/> Many Thanks, <br/> <b>Bright Ideas</b>",
                mailPriority    = MailPriority.High,
                mailAttachments = new List <Attachment>()
            });
            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";

            return(Redirect(redirectUrl));
        }
예제 #26
0
        public string CreateOncePaymentUrl(OnceOffPaymentModel onceOffPaymentModel)
        {
            PayFastRequest payFastRequest = payFastRequestMapper.MappToPayFastRequest(onceOffPaymentModel);

            return($"{onceOffPaymentModel.Merchant.ProcessUrl}{payFastRequest.ToString()}");
        }
예제 #27
0
        public async Task <IActionResult> SummaryPost()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);


            detailsCart.listCart = await _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value).ToListAsync();

            detailsCart.OrderHeader.PaymentStatus    = SD.PaymentStatusPending;
            detailsCart.OrderHeader.OrderDate        = SharedMethods.GetDateTime();
            detailsCart.OrderHeader.UserId           = claim.Value;
            detailsCart.OrderHeader.Status           = SD.PaymentStatusPending;
            detailsCart.OrderHeader.PickUpTime       = Convert.ToDateTime(detailsCart.OrderHeader.PickUpDate.ToShortDateString() + " " + detailsCart.OrderHeader.PickUpTime.ToShortTimeString());
            detailsCart.OrderHeader.StartDateTime    = null;
            detailsCart.OrderHeader.PickedUpOrder    = null;
            detailsCart.OrderHeader.CompleteDateTime = null;
            detailsCart.OrderHeader.Duration         = "";
            detailsCart.OrderHeader.OrderStartedBy   = "";
            detailsCart.OrderHeader.OrderCompletedBy = "";

            int CalcMins = 0;

            foreach (var item in detailsCart.listCart)
            {
                MenuItems objM = await _db.MenuItems.FindAsync(item.MenuItemId);

                int ETA = objM.ETAEstimate;
                CalcMins += ETA * item.Count;
            }

            TimeSpan tempTime = TimeSpan.FromMinutes(CalcMins);
            double   Hours    = Math.Abs(tempTime.Hours);
            double   Min      = Math.Abs(tempTime.Minutes);

            if (Hours > 0)
            {
                if (Min == 0)
                {
                    detailsCart.OrderHeader.EstimatedTimeComplete = Hours.ToString() + " hours";
                }
                else
                {
                    detailsCart.OrderHeader.EstimatedTimeComplete = Hours.ToString() + " h " + Min.ToString();
                }
            }
            else if (Min > 0)
            {
                detailsCart.OrderHeader.EstimatedTimeComplete = Min.ToString() + " mins";
            }
            else
            {
                detailsCart.OrderHeader.EstimatedTimeComplete = "0 mins";
            }


            List <OrderDetails> orderDetailsList = new List <OrderDetails>();

            _db.OrderHeader.Add(detailsCart.OrderHeader);
            await _db.SaveChangesAsync();

            detailsCart.OrderHeader.OrderTotalOriginal = 0;


            foreach (var item in detailsCart.listCart)
            {
                MenuItems objMenuItem = await _db.MenuItems.FirstOrDefaultAsync(m => m.Id == item.MenuItemId);

                item.MenuItems = await _db.MenuItems.FirstOrDefaultAsync(m => m.Id == item.MenuItemId);

                OrderDetails orderDetails = new OrderDetails
                {
                    MenuItemId  = item.MenuItemId,
                    OrderId     = detailsCart.OrderHeader.Id,
                    Description = item.MenuItems.Descriptions,
                    Name        = item.MenuItems.Name,
                    Price       = item.MenuItems.Price,
                    Count       = item.Count
                };
                objMenuItem.AvaQuantity -= item.Count;
                detailsCart.OrderHeader.OrderTotalOriginal += orderDetails.Count * orderDetails.Price;
                _db.OrderDetails.Add(orderDetails);
            }

            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                detailsCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == detailsCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                detailsCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailsCart.OrderHeader.OrderTotalOriginal);
            }
            else
            {
                detailsCart.OrderHeader.OrderTotal = detailsCart.OrderHeader.OrderTotalOriginal;
            }
            detailsCart.OrderHeader.CouponCodeDiscount = detailsCart.OrderHeader.OrderTotalOriginal - detailsCart.OrderHeader.OrderTotal;

            _db.ShoppingCart.RemoveRange(detailsCart.listCart);
            HttpContext.Session.SetInt32(SD.ssShoppingCartCount, 0);
            await _db.SaveChangesAsync();



            //------------ PAYFAST ------------
            //Gets passsword from appsettings
            var onceOffRequest = new PayFastRequest(this.payFastSettings.PassPhrase);

            // Merchant Details, getting various keys,IDs,URLs
            onceOffRequest.merchant_id  = this.payFastSettings.MerchantId;
            onceOffRequest.merchant_key = this.payFastSettings.MerchantKey;
            onceOffRequest.return_url   = this.payFastSettings.ReturnUrl + detailsCart.OrderHeader.Id;
            onceOffRequest.cancel_url   = this.payFastSettings.CancelUrl + detailsCart.OrderHeader.Id;
            onceOffRequest.notify_url   = this.payFastSettings.NotifyUrl;

            // Buyer Details
            onceOffRequest.email_address = "*****@*****.**";

            // Transaction Details, details for the order
            onceOffRequest.m_payment_id = detailsCart.OrderHeader.Id.ToString();
            onceOffRequest.amount       = detailsCart.OrderHeader.OrderTotal;

            onceOffRequest.item_name  = $"Order Number:{detailsCart.OrderHeader.Id}.";
            onceOffRequest.item_name += $"Order Pickup name:{detailsCart.OrderHeader.PickUpName}";


            /*
             * Order #13
             * Order Items  Quantity
             * Medium Rare    5
             */



            onceOffRequest.item_description = "Some details about the once off payment";

            // Transaction Options
            onceOffRequest.email_confirmation   = true;
            onceOffRequest.confirmation_address = "*****@*****.**";

            var redirectUrl = $"{this.payFastSettings.ProcessUrl}{onceOffRequest.ToString()}";


            // Moved Payment Approved to Confirm Action method

            return(Redirect(redirectUrl));
            //------------ PAYFAST ------------

            //Return
            //return RedirectToAction("Confirm", "Order", new { id = detailCart.OrderHeader.Id });
        }