Created
May 20, 2018 12:19
-
-
Save AndrewDryga/e83ad6c27d11d7bf416be151763c0c40 to your computer and use it in GitHub Desktop.
Sage: Business logic example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Domain.User.SignUp do | |
def create_and_subscribe_user(attrs) do | |
Repo.transaction(fn -> | |
with {:ok, user} <- create_user(attrs), | |
{:ok, plans} <- fetch_subscription_plans(attrs), | |
{:ok, charge} <- charge_card(user, subscription), | |
{:ok, subscription} <- create_subscription(user, plan, attrs), | |
{:ok, _delivery} <- schedule_delivery(user, subscription, attrs), | |
{:ok, _receipt} <- send_email_receipt(user, subscription, attrs), | |
{:ok, user} <- update_user(user, %{subscription: subscription}) do | |
{:ok, user} | |
end | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment