Shopifex v0.6.1 Shopifex.PaymentGuard behaviour View Source

Context behaviour responsible for fetching and using payment grants.

Link to this section Summary

Callbacks

After payment has been accepted, this function is meant to persist the payment. Default behaviour is to create a grant schema record. charge_id is the external id for the Shopify charge record.

Gets a plan with a given identifier

Returns a payment record which grants access to the payment guard. Default behaviour filters where remaining_usages is greater than 0 or has a nil value (unlimited usage).

Display the available payment plans for the user to select.

Updates the grant to reflect the usage of it in some way. Defaults to decrementing the remaining_usages property if it's not nil. If it is nil, the grant has unlimited usages

Link to this section Types

Specs

grant() :: %{
  charge_id: pos_integer(),
  grants: [String.t()],
  remaining_usages: pos_integer(),
  total_usages: pos_integer()
}

Specs

guard() :: String.t()

Specs

plan() :: %{
  id: String.t() | pos_integer(),
  name: String.t(),
  price: String.t(),
  type: String.t(),
  test: boolean()
}

Specs

shop() :: %{access_token: String.t(), scope: String.t(), url: String.t()}

Link to this section Callbacks

Link to this callback

create_grant(shop, plan, charge_id)

View Source (optional)

Specs

create_grant(shop :: shop(), plan :: plan(), charge_id :: pos_integer()) ::
  {:ok, any()}

After payment has been accepted, this function is meant to persist the payment. Default behaviour is to create a grant schema record. charge_id is the external id for the Shopify charge record.

Link to this callback

get_plan(plan_id)

View Source (optional)

Specs

get_plan(plan_id :: String.t() | pos_integer()) :: plan()

Gets a plan with a given identifier

Link to this callback

grant_for_guard(shop, guard)

View Source (optional)

Specs

grant_for_guard(shop(), guard()) :: grant() | boolean()

Returns a payment record which grants access to the payment guard. Default behaviour filters where remaining_usages is greater than 0 or has a nil value (unlimited usage).

Link to this callback

show_plans(conn, guard_identifier, redirect_after)

View Source (optional)

Specs

show_plans(
  conn :: Plug.Conn.t(),
  guard_identifier :: String.t(),
  redirect_after :: String.t()
) :: Plug.Conn.t()

Display the available payment plans for the user to select.

Link to this callback

use_grant(shop, grant)

View Source (optional)

Specs

use_grant(shop(), grant()) :: grant()

Updates the grant to reflect the usage of it in some way. Defaults to decrementing the remaining_usages property if it's not nil. If it is nil, the grant has unlimited usages