MishkaPay.Coupon.PromotionCode (Mishka Pay v0.0.1)

Copy Markdown View Source

A code a buyer types at the checkout (SPRING10) that applies a MishkaPay.Coupon, with its own limits. A guarded_struct. A checkout lets buyers type codes with allow_promotion_codes: true, or applies one itself through discounts (MishkaPay.Checkout.Discounts).

Made with MishkaPay.create_promotion_code/1, read with MishkaPay.fetch_promotion_code/3 and MishkaPay.list_promotion_codes/3, turned off or on again with MishkaPay.update_promotion_code/1 (active: false).

What the caller gives:

  • :provider, :tenant: which provider, with whose keys.
  • :coupon_id: the coupon it applies.
  • :code: what the buyer types; the provider makes one when it is left out.
  • :active: whether it can be used now (true by default).
  • :max_redemptions, :expires_at: its own limits, on top of the coupon's.
  • :first_time_transaction: only for a buyer's first purchase.
  • :minimum_amount: only when the order is at least this Money.
  • :customer_id: only for this customer.
  • :metadata: extra pairs, string keys to string values.

What the provider fills in: :id, :times_redeemed, :created_at.

Summary

Types

t()

The struct that builder/1 returns.

Functions

A sample %MishkaPay.Coupon.PromotionCode{} populated from defaults + type-based fallbacks.

Types

t()

@type t() :: %MishkaPay.Coupon.PromotionCode{
  active: boolean() | nil,
  code: String.t() | nil,
  coupon_id: String.t() | nil,
  created_at: DateTime.t() | nil,
  customer_id: String.t() | nil,
  expires_at: DateTime.t() | nil,
  first_time_transaction: boolean() | nil,
  id: String.t() | nil,
  max_redemptions: pos_integer() | nil,
  metadata: map() | nil,
  minimum_amount: Money.t() | nil,
  provider: String.t() | nil,
  tenant: term() | nil,
  times_redeemed: non_neg_integer() | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t() | nilnosanitize(trim) validate(string, not_empty)
:tenantterm() | nilno
:idString.t() | nilnosanitize(trim) validate(string, not_empty)
:coupon_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:codeString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=200)
:activeboolean() | nilnovalidate(boolean)
:max_redemptionspos_integer() | nilnovalidate(integer, min_len=1)
:expires_atDateTime.t() | nilnovalidate(struct)
:first_time_transactionboolean() | nilnovalidate(boolean)
:minimum_amountMoney.t() | nilnovalidator {MishkaPay.Money, :field}
:customer_idString.t() | nilnosanitize(trim) validate(string, not_empty)
:times_redeemednon_neg_integer() | nilnovalidate(integer)
:created_atDateTime.t() | nilnovalidate(struct)
:metadatamap() | nilno%{}validate(map)<br>validator {MishkaPay.Checkout, :metadata}

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

A sample %MishkaPay.Coupon.PromotionCode{} populated from defaults + type-based fallbacks.

keys()

keys(field)