MishkaPay.Refund (Mishka Pay v0.0.1)

Copy Markdown View Source

Money given back on a payment, in full or in part, made with MishkaPay.refund/1. A guarded_struct.

How often a payment may be refunded is the tenant's choice, read at runtime from its MishkaPay.Credentials (:refunds):

  • :once (the default): one refund, whole or in part. Another one on that payment is refused, and a buyer who wants it again makes a new purchase. The idempotency key comes from the payment, so a refund sent again after a lost answer is the same refund.
  • :many: part refunds until the payment is used up. Each refund needs its own :reference, which makes its idempotency key, so the same reference never refunds twice.

What the caller gives:

  • :provider, :tenant: as for a checkout.
  • :payment_id: the payment to refund.
  • :amount: how much, a Money; left out, the whole payment.
  • :reason: :requested_by_customer, :duplicate or :fraudulent.
  • :reference: the caller's own id for this refund; needed when the tenant allows many.

What the provider fills in: :id, :status (:pending, :succeeded, :failed, :canceled, :requires_action) and :created_at, and :amount when it was left out.

Summary

Types

t()

The struct that builder/1 returns.

Functions

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

Types

t()

@type t() :: %MishkaPay.Refund{
  amount: Money.t() | nil,
  created_at: DateTime.t() | nil,
  id: String.t() | nil,
  payment_id: String.t(),
  provider: String.t(),
  reason: atom() | nil,
  reference: String.t() | nil,
  status: atom() | nil,
  tenant: term() | nil
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:tenantterm() | nilno
:payment_idString.t()yessanitize(trim) validate(not_nil_value, string, not_empty)
:amountMoney.t() | nilnovalidator {MishkaPay.Refund, :amount}
:reasonatom() | nilnovalidate(enum=Atom[requested_by_customer::duplicate::fraudulent])
:referenceString.t() | nilnosanitize(trim) validate(string, not_empty, max_len=200)
:idString.t() | nilnovalidate(string)
:statusatom() | nilnovalidate(enum=Atom[pending::succeeded::failed::canceled::requires_action])
:created_atDateTime.t() | nilnovalidate(struct)

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)