0

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:

  1. 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).

  2. 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.

Idiot
  • 75
  • 2
  • 7
  • 1
    Does this answer your question? [Laravel: Using try...catch with DB::transaction()](https://stackoverflow.com/questions/22906844/laravel-using-try-catch-with-dbtransaction) – Don't Panic Jan 12 '21 at 09:31
  • As far as I understand some things are atomic, (db, cache..), but some are not, like payment and google calendar, so let s say that db operation is rolled back, how do you roll back ( revert ) non atomic operations ( google calendar and payment in this case )? – Idiot Jan 12 '21 at 13:09
  • Try catch will throw exception on first error, but it wont on operation that was successfull and prior the error, so payment can be made but google calendar not to be updated – Idiot Jan 12 '21 at 13:12

0 Answers0