This file contains 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
def create_subscription(email, plan_id, payment_method_id) do | |
case Repo.get_by(User, email: email) do | |
%User{customer_id: nil, name: name} = user -> | |
params = %{ | |
name: name, | |
email: email, | |
payment_method: payment_method_id, | |
invoice_settings: %{ | |
default_payment_method: payment_method_id | |
} |
This file contains 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
iex(1)> Geolix.lookup("45.50.161.38", [as: :raw, where: :country]) | |
%{ | |
continent: %{ | |
code: "NA", | |
geoname_id: 6255149, | |
names: %{ | |
de: "Nordamerika", | |
en: "North America", | |
es: "Norteamérica", | |
fr: "Amérique du Nord", |
This file contains 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
iex(1)> Geolix.lookup("45.50.161.38", [as: :raw, where: :country]) | |
%{ | |
continent: %{ | |
code: "NA", | |
geoname_id: 6255149, | |
names: %{ | |
de: "Nordamerika", | |
en: "North America", | |
es: "Norteamérica", | |
fr: "Amérique du Nord", |
This file contains 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
iex(1)> Geolix.lookup("45.50.161.38") | |
%{ | |
city: %Geolix.Adapter.MMDB2.Result.City{ | |
city: %Geolix.Adapter.MMDB2.Record.City{ | |
geoname_id: 5368361, | |
name: "Los Angeles", | |
names: %{ | |
de: "Los Angeles", | |
en: "Los Angeles", | |
es: "Los Ángeles", |
This file contains 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
config :geolix, :databases, [ | |
%{ | |
id: :city, | |
adapter: Geolix.Adapter.MMDB2, | |
source: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz" | |
}, | |
%{ | |
id: :country, | |
adapter: Geolix.Adapter.MMDB2, | |
source: "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz" |
This file contains 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 Acme.Tasks.Email do | |
import Bamboo.Email | |
alias Acme.Models.User | |
def welcome_user(%User{first_name: first_name, email: email, state: "ACTIVE"}) | |
when first_name != "" do | |
new_email( | |
to: {first_name, email}, | |
from: {"Acme Products", "hello@acme.com"}, | |
subject: "Welcome to Acme Products", |
This file contains 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 Acme.Tasks.Email do | |
import Bamboo.Email | |
alias Acme.Models.User | |
def welcome_user(%User{first_name: first_name, email: email}) do | |
new_email( | |
to: {first_name, email}, | |
from: {"Acme Products", "hello@acme.com"}, | |
subject: "Welcome to Acme Products", | |
text_body: """ |
This file contains 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 Acme.EmailTest do | |
use ExUnit.Case | |
alias Acme.Models.User | |
test "welcome email" do | |
user = %User{first_name: "John", email: "person@example.com"} | |
email = Acme.Email.welcome_user(user) | |
assert email.to == user |
This file contains 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
Acme.Models.find_by_email("roadrunner@me.com") | |
|> Acme.Tasks.Email.welcome_user() | |
|> Acme.Mailer.deliver_now() |