I have a booking process for tours that looks like this:
booking_process:
if_date_time_exists_in_bookings_table and there are still spaces available
make_payment
update_table
send_confirmation_email_to_user
## no need to update google calendar here
else if date_time hasn't been booked yet
make_payment
make_closed_event_in_google_calendar
insert_record_in_db
send_confirmation_email_to_user
In this project I would like to integrate Google Calendar api for events, and as a central place for all of my tours. I have following requirements:
I want each block code to either completely succeed or fail. ( for exampleI don't want to make a payment and then fail to update table and vice versa).
I want to make this operation ( if/else block code ) atomic. So no overbooking should happen.
And finally how do I test that? I guess unit testing is not meant for this. In block code 2 (else is part) I don't have update, so does that mean I can't be using database locks? That doesn't seem like an operation suitable for cache and consequently cache locks either. Also is it possible mixing non atomic services ( I believe Google Calendar is not atomic ) in atomic operations?
I am using Laravel and absolutely have no idea how to do this.