public void ProcessPayment(UIInfo info) { Payment p; float tprice = t.price; switch (info.Payment) { default: case UIPayment.Cash: p = new CashPayment(); break; case UIPayment.CreditCard: p = new CreditPayment(); tprice += 0.5f; break; case UIPayment.DebitCard: p = new DebitPayment(); break; } p.BeginTransaction(t.price); bool b = p.EndTransaction(); if (b) { MessageBox.Show("Your payment has been processed succesfully."); } else { MessageBox.Show("Your payment was not processed."); } WriteToLog(); PrintReceipt(date, tprice); }
/// <summary> /// Handles the payment after all information has been put into the UIInfo object. /// TODO: Maybe add a return bool indicating succes or failure. /// </summary> /// <param name="info"></param> public static string[] handlePayment(Ticket info) { PaymentMethods strategy; string[] log = new string[8]; float price = PricingServer.getPrice(info); switch (info.Payment) { case Payment.CreditCard: strategy = new CreditCardPayment(price); break; case Payment.DebitCard: strategy = new DebitCardPayment(price); break; default: // We default to a cash payment strategy = new CashPayment(price); break; } strategy.Pay(); return(log); }
public void HandleCash(float price) { CashPayment coin = new CashPayment(); coin.Connect(); int a = coin.BeginTransaction(price); coin.EndTransaction(a); }
private Ticket getUIInfo() { UIClass cls; if (firstClass.Checked) cls = UIClass.FirstClass; else cls = UIClass.SecondClass; int way; if (oneWay.Checked) way = 1; else way = 2; float dis; if (noDiscount.Checked) dis = 0; else if (twentyDiscount.Checked) dis = 0.20f; else dis = 0.40f; Payment pment; ICard c; switch ((string)payment.SelectedItem) { case "Credit card": pment = new CardPayment(c = new CreditCard()); break; case "Debit card": pment = new CardPayment(c = new DebitCard()); break; default: pment = new CashPayment(); break; } return new Ticket ((string)fromBox.SelectedItem, (string)toBox.SelectedItem, cls, way, dis, pment); }