View Source ExCheckout
A general store checkout system
installation
Installation
If available in Hex, the package can be installed
by adding ex_checkout
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_checkout, ">= 0.0.0"}
]
end
example-implementation
Example implementation
defmodule Web.Checkout.Controller do
defp checkout(conn, {customer, items}) do
alias ExCheckout.Server, as: Checkout
alias ExCheckout.Transaction
alias ExCheckout.Transaction.MyPaymentProvider, as: MyPaymentProvider
customer = %{first_name: "mithereal", last_name: "nil", email: "mithereal@gmail.com", phone: "1234567"}
items = [{"sku-123", 11.00}, {"sku-123-456", 15.00}]
adjustments = []
{:ok, pid} = ExCheckout.new()
## {:ok, pid} = ExCheckout.Cache.new("my_checkout")
## {pid, value} = ExCheckout.Cache.lookup("my_checkout")
Checkout.customer(pid, customer)
Checkout.items(pid, items)
Checkout.adjustments(pid, adjustments)
Checkout.scan_items(pid)
_subtotal = Checkout.subtotal(pid)
total = Checkout.total(pid)
_invoice = Checkout.invoice(pid)
#select payment provider to await on the ipn data
Checkout.ipn(pid, MyPaymentProvider)
{:ok, pid}
end
end
defmodule Web.ExCheckout.Transaction.MyPaymentProvider do
@behaviour ExCheckout.Behaviours.Transaction
@impl true
def module_id() do
:my_payment_provider
end
def process(pid, transaction_data) do
transaction_data = %{data: %{id: 12345, response: "JSON"}}
_state = Checkout.payment_transaction(pid, transaction_data)
# _state = Checkout.payment_transaction("my_checkout", transaction_data)
receipt = Checkout.receipt(pid)
## maybe write to db or socket
{:ok, receipt}
end
end
custom-shipping-modules
Custom Shipping Modules
there are 2 ways of setting up your own shipping module either specifying it in the config if its in its own namespace or creating a module in your project with following module naming conventions
defmodule applicationname.ExCheckout.Carrier.Modulename do
end
then set up the config carriers key to match the modules config() return. see the config, carrier/null or payment/null module for syntax examples,
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ex_checkout.