Exemplo n.º 1
0
        public void BuyItem(VendingItem item, IPaymentSystem paymentSystem)
        {
            if (!_catalogue.ContainsValue(item))
            {
                string message = $"Catalogue does not contain item {item}. Aborting.";
                LogError(message);
                throw new Exception(message);
            }

            if (!_deliverySystem.IsItemPresent(item.Id.Value))
            {
                string message = $"Item with ID {item.Id.Value} is not present. Aborting.";
                LogError(message);
                throw new Exception(message);
            }

            if (!paymentSystem.TryWithholdPayment(item.Price))
            {
                string message = "Payment failed or was canceled by user. Aborting.";
                LogError(message);
                throw new Exception(message);
            }

            if (!_deliverySystem.TryDeliverItem(item.Id.Value))
            {
                string message = "Error in delivery system. Aborting.";
                LogError(message);
                paymentSystem.RevokeTransaction();

                throw new Exception(message);
            }

            paymentSystem.CompleteTransaction();
        }
        public PaymentSystemTesting()
        {
            _random        = new Random();
            _paymentSystem = new PaymentSystem();

            SetInitialProducts();
        }
Exemplo n.º 3
0
        protected void submitPayment_Click(object sender, EventArgs e)
        {
            IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();



            PaymentRequest payment = new PaymentRequest();


            payment.CardName    = "Arthur Anderson";
            payment.CardNumber  = "4444333322221111";
            payment.CVC         = 123;
            payment.Expiry      = new DateTime(2020, 11, 1);
            payment.Amount      = 200;
            payment.Description = "test";
            var task = paymentSystem.MakePayment(payment);



            if (task.IsCompleted)

            {
                Label1.Text = task.Result.ToString();;
            }



            //Response.Redirect("/Application Layer/MainSite/OrderConfirmation.aspx");
        }
        public void CanScanProduct()
        {
            // Assert
            _terminal = new PointOfSaleTerminal();
            var product = SellerClient.CreateProduct("A", 1.25m, 3, 3m);

            // Act
            _terminal.SetPricing(product);
            var returnedProduct = _terminal.Scan("A");

            // Arrange
            Assert.NotNull(returnedProduct);
            Assert.Equal(1.25m, returnedProduct.Price);
        }
        public void CanCalculateTotal()
        {
            // Assert
            _terminal = new PointOfSaleTerminal();

            SetUpPricing();

            // Act
            _terminal.Scan("A");
            _terminal.Scan("A");
            _terminal.Scan("A");
            _terminal.Scan("A");

            var result = _terminal.CalculateTotal();

            // Arrange
            Assert.Equal(4.25m, result);
        }
        public void TestAbcdSequence()
        {
            // Assert
            _terminal = new PointOfSaleTerminal();

            SetUpPricing();

            // Act
            _terminal.Scan("A");
            _terminal.Scan("B");
            _terminal.Scan("C");
            _terminal.Scan("D");

            var result = _terminal.CalculateTotal();

            // Arrange
            Assert.Equal(7.25m, result);
        }
Exemplo n.º 7
0
        //The super janky payment function. Not sure if this how it's supposed to work but it seems to?
        public static int MakePayment(string name, string cardnum, int cvc, DateTime expiry)
        {
            IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();
            PaymentRequest payment       = new PaymentRequest();

            payment.CardName    = name;
            payment.CardNumber  = cardnum;
            payment.CVC         = cvc;
            payment.Expiry      = expiry;
            payment.Amount      = total;
            payment.Description = "Lotsa Watches";
            var task = paymentSystem.MakePayment(payment);

            System.Threading.Thread.Sleep(5000);
            if (task.IsCompleted)
            {
                var result = Convert.ToInt32(task.Result.TransactionResult);

                switch (result)
                {
                case 0:
                    return(0);

                case 1:
                    return(1);

                case 2:
                    return(2);

                case 3:
                    return(3);

                case 4:
                    return(4);

                default:
                    return(4);
                }
            }
            else
            {
                return(4);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Determines whether transaction can be made on the specified card.
        /// </summary>
        /// <param name="card"></param>
        /// <returns></returns>
        public TransactionResult processPurchase(string[] card)
        {
            IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();
            // Initialise card details
            PaymentRequest pr = new PaymentRequest
            {
                Amount      = Convert.ToDecimal(Cart.Amount + Shipping.Cost),
                CardName    = card[0],
                CardNumber  = card[1],
                CVC         = Convert.ToInt32(card[2]),
                Expiry      = Convert.ToDateTime("01-" + card[3]),
                Description = "BCD Group - JerseySure"
            };

            // Attempt to process order
            Task <PaymentResult> result = paymentSystem.MakePayment(pr);

            return(result.Result.TransactionResult);
        }
Exemplo n.º 9
0
        public TransactionResult processPayment(string[] card)
        {
            IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();
            // Initialise card details
            PaymentRequest paymentRequest = new PaymentRequest();

            paymentRequest.Amount      = Convert.ToDecimal(ShoppingCart.Amount + PostageOption.postageCost);
            paymentRequest.CardName    = card[0];
            paymentRequest.CardNumber  = card[1];
            paymentRequest.CVC         = Convert.ToInt32(card[2]);
            paymentRequest.Expiry      = Convert.ToDateTime("01-" + card[3]);
            paymentRequest.Description = "JerseyZone";


            // Attempt to process order
            Task <PaymentResult> result = paymentSystem.MakePayment(paymentRequest);

            return(result.Result.TransactionResult);
        }
Exemplo n.º 10
0
        protected void btnPayment_Click(object sender, EventArgs e)
        {
            IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();

            PaymentRequest payment = new PaymentRequest();

            payment.CardName    = txtCardName.Text;
            payment.CardNumber  = txtCardNumber.Text;
            payment.CVC         = Convert.ToInt32(txtCVC.Text);
            payment.Expiry      = DateTime.Parse(txtExpiryDate.Text);
            payment.Amount      = 200;
            payment.Description = "test";
            var task = paymentSystem.MakePayment(payment);

            if (task.IsCompleted)
            {
                //showTransactionResult(task.Result);
            }

            cart.Clear();
            Response.Redirect("Confirmation.aspx");
        }
Exemplo n.º 11
0
        protected void BtnConfirmation_Click(object sender, EventArgs e)
        {
            //page will only run payment if page is valid
            if (Page.IsValid)
            {
                //create new payment from payment code
                IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();
                PaymentRequest payment       = new PaymentRequest();

                //take user data from input page
                payment.CardName    = txtbxCardName.Text;
                payment.CardNumber  = txtbxCardNumber.Text;
                payment.CVC         = Convert.ToInt32(txtbxCVC.Text);
                payment.Expiry      = new DateTime(Convert.ToInt32(txtbxYear.Text), Convert.ToInt32(txtbxMonth.Text), Convert.ToInt32(txtbxDay.Text)); //new DateTime(2020, 11, 1);
                payment.Amount      = 200;
                payment.Description = "test";

                //compare input user data for validation
                var task = paymentSystem.MakePayment(payment);

                //return result of data validation
                string result = Convert.ToString(task.Result.TransactionResult);

                //display result
                lblPaymentStatus.Text = result;

                //if result is approve move user to confirmation page
                if (result == "Approved")
                {
                    //display loading bar to simulate processing
                    task.Wait();
                    lblPaymentStatus.Text = result;
                    task.Wait();
                    Response.Redirect("Confirmation.aspx");
                }
            }
        }
Exemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // SSL CODE. COMMENT OUT IF SSL DOESN'T WORK
            // SECURE PATH FOUND IN WEB.CONFIG FILE
            // SECURE PATH WILL DEPEND ON WHAT VS GIVES YOU WHEN ENABLING SSL = TRUE
            // Redirect for SSL if not already secured
            string securePath = (System.Configuration.ConfigurationManager.AppSettings["SecurePath"] + "UL/userPaymentPage.aspx");

            System.Diagnostics.Debug.WriteLine(securePath);
            System.Diagnostics.Debug.WriteLine(HttpContext.Current.Request.Url.AbsoluteUri);
            if (securePath != HttpContext.Current.Request.Url.AbsoluteUri)
            {
                Response.Redirect(securePath);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Already secured");
            }

            // other
            btnPayment.Click += new EventHandler(this.paymentFunc);
            btnOkay.Click    += new EventHandler(this.okayFunc);
            paymentSystem     = INFT3050PaymentFactory.Create();
        }
 public CSPaymentSystem(IPaymentSystem paymentSystem)
 {
     this.paymentSystem = paymentSystem;
 }
Exemplo n.º 14
0
 public override void MakePayment()
 {
     IPaymentSystem.ProcessPayment("Card Payment");
 }
Exemplo n.º 15
0
 public override void MakePayment()
 {
     IPaymentSystem.ProcessPayment("NetBanking Payment");
 }
Exemplo n.º 16
0
        public void StartPayment()
        {
            IPaymentSystem paymentSystem = PaymentFactory.Create();

            ActivePayment = paymentSystem.MakePayment(Request);
        }
Exemplo n.º 17
0
        /// <summary>
        /// take Invoice/customer information
        /// set a paymentRequest corresponding to the subit button used
        /// Wait until end of payment
        /// Display result
        /// </summary>
        /// <param name="realPayment"></param>
        private void Payment(bool realPayment)
        {
            try
            {
                //Invoice recuperation (List of 1 element)
                int     customerID  = Convert.ToInt32(this.Session["CustID"]);
                int     invoiceID   = Convert.ToInt32(this.Session["InvoiceID"]);
                decimal TotalAmount = blInvoice.FindInvoiceByID(customerID, invoiceID)[0].GetTotal();


                //Payment
                //Created the Payment system
                IPaymentSystem paymentSystem = INFT3050PaymentFactory.Create();

                //Making a payment
                PaymentRequest payment = new PaymentRequest();


                if (realPayment == false)
                {
                    //Value to make the payment approved
                    payment.CardName   = "Arthur Anderson";
                    payment.CardNumber = "4444333322221111";
                    payment.CVC        = 123;
                    payment.Expiry     = new DateTime(2020, 11, 1);
                    payment.Amount     = 200;
                }
                else
                {
                    payment.CardName   = TextName.Text;
                    payment.CardNumber = TextCardNumber.Text;
                    payment.CVC        = Convert.ToInt16(TextCSC.Text);
                    payment.Expiry     = new DateTime(Convert.ToInt16(YearExpiration.SelectedValue), Convert.ToInt16(MonthExpiration.SelectedValue), 1);
                    payment.Amount     = TotalAmount;
                }

                payment.Description = "OrderID : " + invoiceID + " for customer : " + customerID;
                var task = paymentSystem.MakePayment(payment);

                while (!task.IsCompleted)
                {
                }                                  //Let time to executing transaction

                //Display result
                if (task.Result.TransactionResult.ToString() == "Approved")
                {
                    lblResult.CssClass = "text-success";
                    lblResult.Text     = "Your paiment is approved !";

                    var urlF = FriendlyUrl.Href("/UL/Customer/checkout", 1);
                    Response.Redirect(ConfigurationManager.AppSettings["SecurePath"] + urlF);
                }
                else if (task.Status.ToString() == "RanToCompletion")
                {
                    lblResult.CssClass = "text-danger";
                    lblResult.Text     = "Issue during the paiment :  " + task.Result.TransactionResult.ToString();
                    lblWait.Visible    = false;
                }
                else
                {
                    lblResult.Text  = "Issue during the paiment procedure, please try later";
                    lblWait.Visible = false;
                }
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                Debug.Write(ex.ToString());
            }
        }
 public PaymentSystemDecorator(IPaymentSystem paymentSystem)
 {
     this.paymentSystem = paymentSystem;
 }
 public PaymentSystemDecorator(IPaymentSystem system)
 {
     paymentSystem = system;
 }
Exemplo n.º 20
0
 public ExternalServicesManager(IPaymentSystem paymentSystem, ISupplySystem supplySystem)
 {
     SupplySystem  = supplySystem;
     PaymentSystem = paymentSystem;
 }
Exemplo n.º 21
0
 public PaymentController(IPaymentSystem system, DataContext context)
 {
     _system  = system;
     _context = context;
 }