Skip to content

Instantly share code, notes, and snippets.

@AndrewDryga
Created June 3, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewDryga/59f84c57d00dcf645d8a3f40a86e3b98 to your computer and use it in GitHub Desktop.
Save AndrewDryga/59f84c57d00dcf645d8a3f40a86e3b98 to your computer and use it in GitHub Desktop.
Sage: Booking Happy-Case
def book_trip(attrs) do
with {:ok, exchange_rates} <- BillingAPI.fetch_currency_exchange_rates(attrs),
{:ok, card_authorization} <- BillingAPI.authorize_card(exchange_rates, attrs),
{:ok, hotel_booking} <- HotelBookingAPI.book_hotel(attrs),
:ok <- Mailer.send_email_confirmation(card_authorization, hotel_booking, attrs),
{:ok, charge} <- BillingAPI.charge_card(card_authorization) do
{:ok, %{charge: charge, bookings: [hotel_booking]}}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment