public async Task <IActionResult> OnPaymentNotified(string notificationId) { var payment = await _mp.GetPaymentAsync(notificationId); if (payment["status"]?.ToString() == "200") { PaymentNotice paymentInfo = new PaymentNotice(((payment["response"] as Hashtable)["collection"] as Hashtable), _config.GetSection("LocalZone").Value); if (string.IsNullOrEmpty(paymentInfo.Merchant_Order_Id)) { return(Ok()); } var merchantOrder = await _mp.GetMerchantOrderAsync(paymentInfo.Merchant_Order_Id); if (merchantOrder["status"]?.ToString() == "200") { paymentInfo.User_Id = (merchantOrder["response"] as Hashtable)["additional_info"]?.ToString(); } if (!String.IsNullOrWhiteSpace(paymentInfo.BookingId)) { await _paymentNoticeRepository.CreatePayment(paymentInfo); } } return(Ok()); }
/// <summary> /// Deserialize JSON into a FHIR PaymentNotice /// </summary> public static void DeserializeJson(this PaymentNotice current, ref Utf8JsonReader reader, JsonSerializerOptions options) { string propertyName; while (reader.Read()) { if (reader.TokenType == JsonTokenType.EndObject) { return; } if (reader.TokenType == JsonTokenType.PropertyName) { propertyName = reader.GetString(); if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug) { Console.WriteLine($"PaymentNotice >>> PaymentNotice.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } reader.Read(); current.DeserializeJsonProperty(ref reader, options, propertyName); } } throw new JsonException($"PaymentNotice: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); }
private static PaymentNotice createPaymentNotice(FormCollection formCollection) { log.Info(ToJSON(formCollection)); var paymentNotice = new PaymentNotice(); var paymentRef = formCollection["merchantReference"]; paymentNotice.success = (formCollection["success"] == "true"); paymentNotice.reason = formCollection["reason"]; paymentNotice.paymentRef = paymentRef; paymentNotice.type = formCollection["eventCode"]; paymentNotice.transactionId = (formCollection["eventCode"] == "AUTHORISATION") ? formCollection["pspReference"] : formCollection["originalReference"]; return(paymentNotice); }
private static PaymentNotice buildPaymentNotice(PaymentResult paymentresult) { var transResultCode = paymentresult.resultCode.Replace("Authorised", "AUTHORISATION").Replace("Refused", "REFUSED"); var paymentNotice = new PaymentNotice { paymentRef = paymentRef, reason = paymentresult.refusalReason, transactionId = paymentresult.pspReference, type = transResultCode, success = true }; return(paymentNotice); }
public void FromEmail() { string emailBody = File.ReadAllText("PaymentNoties\\Payment Received - Ernst Handel.txt"); MailMessage email = new MailMessage { Subject = "Payment Received", Body = emailBody }; //PaymentAmount, OrderDate, OrderNumber, CheckNumber PaymentNotice notice = PaymentNotice.FromEmail(email); Assert.AreEqual(5080.08M, notice.PaymentAmount); Assert.AreEqual(3 - 9 - 2019, notice.OrderDate); Assert.AreEqual(11008, notice.OrderNumber); Assert.AreEqual(2293, notice.CheckNumber); }
public void TestAllEmail() { foreach (string fpath in Directory.GetFiles("PaymentNotices", "*.txt")) { MailMessage msg = new MailMessage { Subject = "Payment Notie", Body = File.ReadAllText(fpath) }; Console.WriteLine(fpath); PaymentNotice notice = PaymentNotice.FromEmail(msg); Assert.IsTrue(notice.PaymentAmount > 0); Assert.IsNotNull(notice.OrderNumber); Assert.IsNotNull(notice.CheckNumber); Assert.IsNotNull(notice.OrderDate); } }
public static void save(PaymentNotice paymentNotice) { try { var orm = new Orm(); var result = orm.execObject <Result>(paymentNotice, "api.user_add_payment_notice"); if (result.errorMessage != null) { throw new DivideByZeroException(); } } catch (DivideByZeroException exp) { log.Error("Error saving payment notice to DB" + exp.Message); throw; } }
public string paymentResult(AdyenResult adyenResult) { try { //here we map the fields var paymentNotice = new PaymentNotice { success = true, paymentRef = adyenResult.merchantReference, type = (adyenResult.authResult == "A") ? "AUTHORISATION" : "REFUSED", transactionId = adyenResult.pspReference }; //then we create thepayment notice CreatePaymentNotice.save(paymentNotice); //then we result a payment status result.PaymentStatus = new PaymentStatus { paymentRef = adyenResult.merchantReference, success = (adyenResult.authResult == "A"), }; if (result.PaymentStatus.success) { //pay.paymentRef, pay.amount, pay.currency, pay.shopperEmail, pay.accountHolderName var paramPayment = new Payment { paymentRef = adyenResult.merchantReference }; result.Payment = orm.execObject <Result>(paramPayment, "api.user_payment_get").Payment; result.Payment.sendReceiptEmail(); } } catch (Exception exp) { errorResult(exp); } return(formattedResult(result)); }
//PaymentNotice är tänkt att användas i vidare utbyggnad av programmet. public PaymentNotice CheckoutGuest(int roomNumber) { PaymentNotice paymentNotice = PaymentNotice.NotPaid; foreach (Booking booking in bookingsList) { if (roomNumber == booking.RoomNumber) { SetRoomAvailable(booking.RoomNumber); if (booking.IsPaid == true) { paymentNotice = PaymentNotice.Paid; } } } AddToListOfAvailableRooms(); return(paymentNotice); }
public async Task CreatePayment(PaymentNotice paymentNotification) { _appDbContext.PaymentNotices.Add(paymentNotification); _appDbContext.SaveChanges(); if (_orderRespository.ValidBookingId(paymentNotification.BookingId)) { await _orderRespository.PaymentNotifiedAsync(paymentNotification); } /* * pending - The user has not yet completed the payment process * approved - The payment has been approved and accredited * authorized - The payment has been authorized but not captured yet * in_process - Payment is being reviewed * in_mediation - Users have initiated a dispute * rejected - Payment was rejected. The user may retry payment. * cancelled - Payment was cancelled by one of the parties or because time for payment has expired * refunded - Payment was refunded to the user * charged_back - Was made a chargeback in the buyer’s credit card */ }
static void Main(string[] args) { bool isGuestUserValid = false; bool isStaffUserValid = false; int loginTry = 1; string firstName = ""; string lastName = ""; int guestId = 0; ConsoleKeyInfo guestOrStaff; HotelManager hotelManager = new HotelManager(); UserAuthentication userAuthentication = new UserAuthentication(); AddRoom(); userAuthentication.AddStaffUser("username", "password", "firstname", "lastname"); userAuthentication.AddGuestUser("Kalle", "Johansson", "guestuser", "password", "*****@*****.**", 0703556585, "Göstasväg 2", 50762, "Borås", 5960660045456500); hotelManager.BookRoom(1, 1); // HÅRDKOD KS while (true) { Console.WriteLine("\n\nWelcome to hotel Push n Pull"); Console.WriteLine("Make a choice"); Console.WriteLine("Press [1]: Guest"); Console.WriteLine("Press [2]: Staff"); Console.WriteLine("Press [Esc]: Exit program"); Console.Write("Choice: "); guestOrStaff = Console.ReadKey(); switch (guestOrStaff.Key) { case ConsoleKey.D1: //Guest login Console.Clear(); ChoiceForGuest(hotelManager); break; case ConsoleKey.D2: //Staff Login Console.Clear(); Console.WriteLine("\nStaff login"); TryLogin(); ChoiceForStaff(hotelManager, userAuthentication); break; case ConsoleKey.Escape: ExitProgram(); break; default: Console.WriteLine("Wrong input. You can only press [1], [2] or [Esc]"); Console.ReadKey(); break; } } //Här kommer alla metoder till main //CHOICE FOR GUEST void ChoiceForGuest(HotelManager hotelManager) { ConsoleKeyInfo bookingMenuChoice; Console.Clear(); Console.WriteLine("Welcome guest"); bool getNumberOfBedsLoop = true; do { int numberOfBeds = GetNumberOfBeds(); Console.Clear(); Console.WriteLine("Rooms that are avalible for you\n"); do { string rooms = PrintAvailableRooms(numberOfBeds); Console.WriteLine(rooms); Console.WriteLine("[1] - Book a room\n[2] - Change number of beds \n[Esc] - Return to main menu"); Console.Write("Choice: "); bookingMenuChoice = Console.ReadKey(); switch (bookingMenuChoice.Key) { case ConsoleKey.D1: Console.WriteLine("\n- Book room -\n"); int chosenRoomNumber = GetRoomChoice(hotelManager.AddToListOfAvailableRooms(numberOfBeds)); Console.WriteLine("\nLogin or create a new account to continue\n"); Console.WriteLine("[1] - Login \n[2] - Create new account"); Console.Write("Choice: "); ConsoleKeyInfo inputKey = Console.ReadKey(); switch (inputKey.Key) { case ConsoleKey.D1: Console.Clear(); TryLogin(); break; case ConsoleKey.D2: Console.Clear(); Console.WriteLine("New user"); Console.WriteLine("Please, fill in the fields below\n"); SetFirstName(); SetLastName(); CreateAccount(firstName, lastName, guestOrStaff); break; default: Console.WriteLine("Wrong input.Make a chioce between [1] or [2]"); break; } hotelManager.BookRoom(chosenRoomNumber, guestId); Console.WriteLine("\nYour booking is confirmed!\n"); Console.Write("Press any key to exit"); Console.ReadKey(); ExitProgram(); break; case ConsoleKey.D2: //Breakar loop och återgår till välja antalet bäddar break; case ConsoleKey.Escape: getNumberOfBedsLoop = false; break; default: Console.WriteLine("\nWrong input. You can only press [1], [2] or [Esc]"); Console.Write("Press any key to continue"); Console.ReadKey(); break; } break; } while (true); } while (getNumberOfBedsLoop); } // FOR STAFF void ChoiceForStaff(HotelManager hotelManager, UserAuthentication userAuthentication) { ConsoleKeyInfo input; do { Console.Clear(); Console.WriteLine("STAFF\n"); Console.WriteLine("Make a choice below"); Console.WriteLine("[1] - Checkout guest\n[2] - View all rooms\n[3] - View all available rooms\n[4] - Add new staff useraccount\n[5] - Add new room \n[6] - Exit program"); Console.Write("Choice: "); input = Console.ReadKey(); switch (input.Key) { case ConsoleKey.D1: StaffCheckOut(); break; case ConsoleKey.D2: // View all rooms Console.Clear(); Console.WriteLine(hotelManager.ViewAllRooms()); Console.Write("Press any key to return"); Console.ReadKey(); break; case ConsoleKey.D3: //View all Avalible rooms Console.Clear(); string allAvailableRooms = PrintAllAvailableRooms(); Console.WriteLine(allAvailableRooms); Console.Write("Press any key to return"); Console.ReadKey(); break; case ConsoleKey.D4: //Add staff Console.Clear(); Console.WriteLine("ADD NEW STAFF USERACCOUNT\n"); SetFirstName(); SetLastName(); CreateAccount(firstName, lastName, guestOrStaff); break; case ConsoleKey.D5: //add new room Console.Clear(); SetRoomDetails(); break; case ConsoleKey.D6: //Exit ExitProgram(); break; case ConsoleKey.Escape: // Återgå till main menu break; default: Console.WriteLine("Wrong input. You can only make a choice between 1-6"); Console.Write("Press any key to continue"); Console.ReadKey(); break; } } while (input.Key != ConsoleKey.Escape); } // LOG IN void TryLogin() { string userName; string password; do { Console.Write("Username: "******"Password: "******"Login succeded"); Thread.Sleep(1500); loginTry = 0; break; } else { Console.WriteLine($"Wrong username or password. Do another try.\nTry {loginTry++} of 3"); if (loginTry == 4) { Console.WriteLine("Number of tries overriden"); Console.ReadKey(); ExitProgram(); } } }while (true); } // CREATE NEW ACCOUNT void CreateAccount(string firstName, string lastName, ConsoleKeyInfo guestOrStaff) { bool isUserExisting = false; string password; string userName; do { userName = GetUserName(); password = GetPassword(); if (guestOrStaff.Key == ConsoleKey.D2) { string newStaffUser = userAuthentication.AddStaffUser(userName, password, firstName, lastName); Console.WriteLine(newStaffUser); Console.WriteLine("STAFF ADDED"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { GetGuestDetails(firstName, lastName, userName, password); } break; } while (isUserExisting == true); } void GetGuestDetails(string firstName, string lastName, string userName, string password) { string email = SetEmail(); long phoneNumber = SetPhoneNumber(); string streetAddress = SetStreetAddress(); int postalCode = SetPostalCode(); string city = SetCity(); long creditCardNumber = SetCreditcardNumber(); var output = userAuthentication.AddGuestUser(firstName, lastName, userName, password, email, phoneNumber, streetAddress, postalCode, city, creditCardNumber); Console.Clear(); Console.WriteLine("New account created!\n"); Console.WriteLine($"Your guest id is: {output.GuestId}. \nPlease save your guest id for further use in the booking system."); } // PRINT AVALIBLE ROOMS string PrintAvailableRooms(int numberOfBeds) { string printSpecificAvailableRooms = ""; int index = 1; List <Room> availableRooms = hotelManager.AddToListOfAvailableRooms(numberOfBeds); for (int i = 0; i < availableRooms.Count; i++) { printSpecificAvailableRooms += "[" + index + "] Number of beds: " + availableRooms[i].NumberOfBeds + "\n" + "Square meters: " + availableRooms[i].SquareMeters + "\n" + "Price per night: " + availableRooms[i].PricePerNight + "\n\n"; index++; } return(printSpecificAvailableRooms); } string PrintAllAvailableRooms() { string printAvailableRooms = ""; List <Room> availableRooms = hotelManager.AddToListOfAvailableRooms(); foreach (Room room in availableRooms) { printAvailableRooms += room.RoomNumber + "\n" + "Number of beds: " + room.NumberOfBeds + "\n" + "Square meters: " + room.SquareMeters + "\n" + "Price per night: " + room.PricePerNight + "\n\n"; } return(printAvailableRooms); } void AddRoom() { hotelManager.AddNewRoom(101, 65, 4, 2233); hotelManager.AddNewRoom(102, 63, 3, 1933); hotelManager.AddNewRoom(103, 62, 4, 2133); hotelManager.AddNewRoom(201, 45, 3, 3233); hotelManager.AddNewRoom(202, 67, 2, 2233); hotelManager.AddNewRoom(203, 17, 2, 3233); hotelManager.AddNewRoom(401, 14, 1, 2233); hotelManager.AddNewRoom(402, 21, 2, 4333); hotelManager.AddNewRoom(501, 20, 2, 2333); hotelManager.AddNewRoom(502, 20, 1, 2133); } void SetFirstName() { do { Console.Clear(); Console.Write("Firstname: "); firstName = Console.ReadLine(); if (string.IsNullOrEmpty(firstName)) { Console.WriteLine("You must fill in a firstname"); Console.Write("Press any key to do another try"); Console.ReadKey(); } else { break; } } while (true); } void SetLastName() { do { Console.Clear(); Console.Write("Lastname: "); lastName = Console.ReadLine(); if (string.IsNullOrEmpty(lastName)) { Console.WriteLine("You must fill in a lastname"); Console.Write("Press any key to do another try"); Console.ReadKey(); } else { break; } } while (true); } string GetUserName() { string userName; bool isUserExisting; do { Console.Clear(); Console.Write("Type in a username with 6 to 16 characters \nUsername: "******"Username must contain 6 to 16 characters"); Console.Write("Press any key to do another try"); Console.ReadKey(); } else if (isUserExisting == true) { Console.WriteLine("Username already exists"); Console.Write("Press any key to do another try"); Console.ReadKey(); } } while (userName.Length < 6 || userName.Length > 16 || isUserExisting == true); return(userName); } string GetPassword() { string password; do { Console.Write("Type in a password with 6 to 16 characters \nPassword: "******"Password must contain 6 to 16 characters"); Console.Write("Press any key to do another try"); Console.ReadKey(); } } while (password.Length < 6 || password.Length > 16); return(password); } void ExitProgram() { Console.WriteLine("\nProgram exits"); Environment.Exit(0); } int GetNumberOfBeds() { int numberOfBeds = 0; do { Console.Clear(); Console.Write("We have rooms for 1-6 persons. \nHow many persons? : "); try { numberOfBeds = Convert.ToInt16(Console.ReadLine()); if (numberOfBeds > 0 && numberOfBeds < 7) { break; } else if (numberOfBeds > 6 || numberOfBeds <= 0) { Console.WriteLine("You may only choose a number between 1 and 6."); Console.Write("Press any key to continue"); Console.ReadKey(); } } catch { Console.WriteLine("You may only choose a number between 1 and 6."); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (true); return(numberOfBeds); } int GetRoomChoice(List <Room> availableRooms) { int roomChoice = 0; do { Console.Write("Which room do you want to book : "); try { roomChoice = Convert.ToInt32(Console.ReadLine()); { if (roomChoice < 0 || roomChoice > availableRooms.Count) { Console.WriteLine("You may only choose a room number that exists in the list of available rooms.\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } } catch { Console.WriteLine("You may only choose a room number that exists in the list of available rooms.\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (true); return(roomChoice); } void StaffCheckOut() { int roomNumberToCheckOut = 0; bool isBooked = false; do { Console.Clear(); Console.Write("Which room do you want to checkout : "); do { try { roomNumberToCheckOut = Convert.ToInt32(Console.ReadLine()); break; } catch { System.Console.WriteLine("Wrong input"); Console.WriteLine("Please do another try.\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (true); isBooked = hotelManager.IsBooked(roomNumberToCheckOut); if (isBooked == true) { PaymentNotice paymentNotice = hotelManager.CheckoutGuest(roomNumberToCheckOut); Console.WriteLine("\nCheckout succeded!"); Console.WriteLine("\nDon't forget to charge the creditcard.\n"); //hotelManager.PayRoom(roomNumber); //För senare version av programmet. Console.WriteLine($"Room {roomNumberToCheckOut} is now avalible!"); Console.Write("Press any key to continue the checkout"); Console.ReadKey(); break; } else { Console.WriteLine("The room number you entered isn't booked!"); Console.WriteLine("Please do another try \n"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (true); } void SetRoomDetails() { Console.WriteLine("Add a new room to the hotel\n"); int roomNumber = SetRoomNumber(); int squareMeters = SetSquareMeters(); int numberOfBeds = SetNumberOfBeds(); int pricePerNight = SetPricePerNight(); hotelManager.AddNewRoom(roomNumber, squareMeters, numberOfBeds, pricePerNight); Console.Write("\nRoom successfully added\nPress any key to continue"); Console.ReadKey(); } int SetRoomNumber() { bool roomExists = false; int roomNumber = 0; do { do { Console.Clear(); Console.Write("Room number: "); try { roomNumber = Convert.ToInt32(Console.ReadLine()); break; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (true); roomExists = hotelManager.CheckIfRoomExists(roomNumber); if (roomExists == true) { Console.WriteLine("The room number you have chosen already exists.\nPlease choose another.\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } else if (roomNumber <= 0) { Console.WriteLine("You must choose a number above 0.\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (roomNumber <= 0 || roomExists == true); return(roomNumber); } int SetSquareMeters() { int squareMeters = 0; do { bool sqmLoop = true; do { Console.Clear(); Console.Write("Square meters: "); try { squareMeters = Convert.ToInt32(Console.ReadLine()); sqmLoop = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (sqmLoop); if (squareMeters < 10 || squareMeters > 100) { Console.WriteLine("You can only type in numbers between 10 and 100\n"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (squareMeters < 10 || squareMeters > 100); return(squareMeters); } int SetNumberOfBeds() { int numberOfBeds = 0; do { bool numberOfBedsLoop = true; do { Console.Clear(); Console.Write("Number of beds: "); try { numberOfBeds = Convert.ToInt32(Console.ReadLine()); numberOfBedsLoop = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (numberOfBedsLoop); if (numberOfBeds <= 0) { Console.WriteLine("You must choose a number above 0"); Console.Write("Press any key to continue"); Console.ReadKey(); } else if (numberOfBeds > 6) { Console.WriteLine("You must choose a number below 7"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (numberOfBeds < 1 || numberOfBeds > 6); return(numberOfBeds); } int SetPricePerNight() { int pricePerNight = 0; do { bool setPricePerNightLoop = true; do { Console.Clear(); Console.Write("Price per night: "); try { pricePerNight = Convert.ToInt32(Console.ReadLine()); setPricePerNightLoop = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (setPricePerNightLoop); if (pricePerNight < 1) { Console.WriteLine("You must set a price above 0"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (pricePerNight < 1); return(pricePerNight); } string SetEmail() { string email = ""; do { Console.Clear(); Console.Write("Email: "); email = Console.ReadLine(); if (string.IsNullOrEmpty(email)) { Console.WriteLine("You must insert something as your email address!"); } else { break; } } while (true); return(email); } string SetStreetAddress() { string streetAddress = ""; do { Console.Clear(); Console.Write("Street address: "); streetAddress = Console.ReadLine(); if (string.IsNullOrEmpty(streetAddress)) { Console.WriteLine("You must insert something as your street address!"); } else { break; } } while (true); return(streetAddress); } string SetCity() { string city = ""; do { Console.Clear(); Console.Write("City: "); city = Console.ReadLine(); if (string.IsNullOrEmpty(city)) { Console.WriteLine("You must insert something as your City!"); } else { break; } } while (true); return(city); } long SetPhoneNumber() { long phoneNumber = 0; do { bool setPhoneNumberLoop = true; do { Console.Clear(); Console.Write("Phone number: "); try { phoneNumber = Convert.ToInt64(Console.ReadLine()); setPhoneNumberLoop = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (setPhoneNumberLoop); if (phoneNumber < 099999999 || phoneNumber > 0999999999) { Console.WriteLine("You must type in a valid phone number"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (phoneNumber < 099999999 || phoneNumber > 0999999999); return(phoneNumber); } int SetPostalCode() { int postalCode = 0; do { bool setPostalCodeLoop = true; do { Console.Clear(); Console.Write("Postal code: "); try { postalCode = Convert.ToInt32(Console.ReadLine()); setPostalCodeLoop = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (setPostalCodeLoop); if (postalCode < 9999 || postalCode > 99999) { Console.WriteLine("You must type in 5 digit number"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (postalCode < 9999 || postalCode > 99999); return(postalCode); } long SetCreditcardNumber() { long creditcardNumber = 0; do { bool setcreditCardNumber = true; do { Console.Clear(); Console.Write("Creditcard number: "); try { creditcardNumber = Convert.ToInt64(Console.ReadLine()); setcreditCardNumber = false; } catch { Console.WriteLine("You can only type in numbers"); Console.Write("Press any key to continue"); Console.ReadKey(); } } while (setcreditCardNumber); if (creditcardNumber < 999999999999999 || creditcardNumber > 999999999999999999) { Console.WriteLine("You must type in a valid creditcard number"); Console.Write("Press any key to continue"); Console.ReadKey(); } else { break; } } while (creditcardNumber < 999999999999999 || creditcardNumber > 999999999999999999); return(creditcardNumber); } }
/// <summary> /// Serialize a FHIR PaymentNotice into JSON /// </summary> public static void SerializeJson(this PaymentNotice current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true) { if (includeStartObject) { writer.WriteStartObject(); } writer.WriteString("resourceType", "PaymentNotice"); // Complex: PaymentNotice, Export: PaymentNotice, Base: DomainResource (DomainResource) ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false); if ((current.Identifier != null) && (current.Identifier.Count != 0)) { writer.WritePropertyName("identifier"); writer.WriteStartArray(); foreach (Identifier val in current.Identifier) { val.SerializeJson(writer, options, true); } writer.WriteEndArray(); } writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value)); if (current.Request != null) { writer.WritePropertyName("request"); current.Request.SerializeJson(writer, options); } if (current.Response != null) { writer.WritePropertyName("response"); current.Response.SerializeJson(writer, options); } writer.WriteString("created", current.CreatedElement.Value); if (current.Provider != null) { writer.WritePropertyName("provider"); current.Provider.SerializeJson(writer, options); } writer.WritePropertyName("payment"); current.Payment.SerializeJson(writer, options); if (current.PaymentDateElement != null) { if (!string.IsNullOrEmpty(current.PaymentDateElement.Value)) { writer.WriteString("paymentDate", current.PaymentDateElement.Value); } if (current.PaymentDateElement.HasExtensions() || (!string.IsNullOrEmpty(current.PaymentDateElement.ElementId))) { JsonStreamUtilities.SerializeExtensionList(writer, options, "_paymentDate", false, current.PaymentDateElement.Extension, current.PaymentDateElement.ElementId); } } if (current.Payee != null) { writer.WritePropertyName("payee"); current.Payee.SerializeJson(writer, options); } writer.WritePropertyName("recipient"); current.Recipient.SerializeJson(writer, options); writer.WritePropertyName("amount"); current.Amount.SerializeJson(writer, options); if (current.PaymentStatus != null) { writer.WritePropertyName("paymentStatus"); current.PaymentStatus.SerializeJson(writer, options); } if (includeStartObject) { writer.WriteEndObject(); } }
/// <summary> /// Deserialize JSON into a FHIR PaymentNotice /// </summary> public static void DeserializeJsonProperty(this PaymentNotice current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName) { switch (propertyName) { case "identifier": if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read())) { throw new JsonException($"PaymentNotice error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } current.Identifier = new List <Identifier>(); while (reader.TokenType != JsonTokenType.EndArray) { Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier(); v_Identifier.DeserializeJson(ref reader, options); current.Identifier.Add(v_Identifier); if (!reader.Read()) { throw new JsonException($"PaymentNotice error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}"); } if (reader.TokenType == JsonTokenType.EndObject) { reader.Read(); } } if (current.Identifier.Count == 0) { current.Identifier = null; } break; case "status": if (reader.TokenType == JsonTokenType.Null) { current.StatusElement = new Code <Hl7.Fhir.Model.FinancialResourceStatusCodes>(); reader.Skip(); } else { current.StatusElement = new Code <Hl7.Fhir.Model.FinancialResourceStatusCodes>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.FinancialResourceStatusCodes>(reader.GetString())); } break; case "_status": if (current.StatusElement == null) { current.StatusElement = new Code <Hl7.Fhir.Model.FinancialResourceStatusCodes>(); } ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options); break; case "request": current.Request = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Request).DeserializeJson(ref reader, options); break; case "response": current.Response = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Response).DeserializeJson(ref reader, options); break; case "created": if (reader.TokenType == JsonTokenType.Null) { current.CreatedElement = new FhirDateTime(); reader.Skip(); } else { current.CreatedElement = new FhirDateTime(reader.GetString()); } break; case "_created": if (current.CreatedElement == null) { current.CreatedElement = new FhirDateTime(); } ((Hl7.Fhir.Model.Element)current.CreatedElement).DeserializeJson(ref reader, options); break; case "provider": current.Provider = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Provider).DeserializeJson(ref reader, options); break; case "payment": current.Payment = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Payment).DeserializeJson(ref reader, options); break; case "paymentDate": if (reader.TokenType == JsonTokenType.Null) { current.PaymentDateElement = new Date(); reader.Skip(); } else { current.PaymentDateElement = new Date(reader.GetString()); } break; case "_paymentDate": if (current.PaymentDateElement == null) { current.PaymentDateElement = new Date(); } ((Hl7.Fhir.Model.Element)current.PaymentDateElement).DeserializeJson(ref reader, options); break; case "payee": current.Payee = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Payee).DeserializeJson(ref reader, options); break; case "recipient": current.Recipient = new Hl7.Fhir.Model.ResourceReference(); ((Hl7.Fhir.Model.ResourceReference)current.Recipient).DeserializeJson(ref reader, options); break; case "amount": current.Amount = new Hl7.Fhir.Model.Money(); ((Hl7.Fhir.Model.Money)current.Amount).DeserializeJson(ref reader, options); break; case "paymentStatus": current.PaymentStatus = new Hl7.Fhir.Model.CodeableConcept(); ((Hl7.Fhir.Model.CodeableConcept)current.PaymentStatus).DeserializeJson(ref reader, options); break; // Complex: PaymentNotice, Export: PaymentNotice, Base: DomainResource default: ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName); break; } }