Packages
shopifex
1.1.0
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.20
2.1.19
2.1.18
2.1.17
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
1.1.1
1.1.0
1.0.1
1.0.0
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Phoenix boilerplate for Shopify Embedded App SDK
Current section
Files
Jump to
Current section
Files
lib/mix/shopifex/controller.ex
defmodule Mix.Shopifex.Controller do
@moduledoc false
alias Mix.Generator
@template """
defmodule <%= inspect app_base %>Web.<%= controller_module %> do
use <%= inspect app_base %>Web, :controller
use ShopifexWeb.<%= uses %>
@moduledoc \"\"\"
For available callbacks, see https://hexdocs.pm/shopifex/ShopifexWeb.<%= uses %>.html
\"\"\"
<%= extra_funs %>
end
"""
@webhook_boilerplate """
# add as many handle_topic/3 functions here as you like! This basic one handles app uninstallation
def handle_topic(conn, shop, "app/uninstalled") do
Shopifex.Shops.delete_shop(shop)
conn
|> send_resp(200, "success")
end
# Mandatory Shopify shop data erasure GDPR webhook. Simply delete the shop record
def handle_topic(conn, shop, "shop/redact") do
Shopifex.Shops.delete_shop(shop)
conn
|> send_resp(204, "")
end
# Mandatory Shopify customer data erasure GDPR webhook. Simply delete the shop (customer) record
def handle_topic(conn, shop, "customers/redact") do
Shopifex.Shops.delete_shop(shop)
conn
|> send_resp(204, "")
end
# Mandatory Shopify customer data request GDPR webhook.
def handle_topic(conn, _shop, "customers/data_request") do
# Send an email of the shop data to the customer.
conn
|> send_resp(202, "Accepted")
end
"""
@controllers [
{"auth_controller", ""},
{"webhook_controller", @webhook_boilerplate},
{"payment_controller", ""}
]
@spec create_controller_files(atom(), binary(), keyword()) :: any()
def create_controller_files(context_app, namespace, _opts) do
for {controller, extra_funs} <- @controllers do
app_base = Mix.Shopifex.app_base(context_app)
controller_module = Macro.camelize("#{namespace}_#{controller}")
file = "#{Macro.underscore(controller_module)}.ex"
uses = Macro.camelize(controller)
content =
EEx.eval_string(@template,
namespace: namespace,
controller_module: controller_module,
app_base: app_base,
uses: uses,
extra_funs: extra_funs
)
dir = "lib/#{context_app}_web/controllers/"
File.mkdir_p!(dir)
dir
|> Path.join(file)
|> Generator.create_file(content)
end
end
end