MishkaPay.Payment (Mishka Pay v0.0.1)

Copy Markdown View Source

One payment as the provider sees it, read with MishkaPay.fetch_payment/3. A guarded_struct the provider fills in; the provider is the source of truth, so read it again rather than keep it.

  • :id: the provider's id (pi_... at Stripe).
  • :amount: what was asked, a Money; :amount_refunded: what went back so far.
  • :amount_captured: what the provider took, once paid; less than :amount when a held payment was captured in part (MishkaPay.capture_payment/4).
  • :status: :pending (not paid yet), :requires_action (the buyer must do something, such as 3-D Secure), :authorized (the money is held on the card and waits for MishkaPay.capture_payment/4 or MishkaPay.cancel_payment/3), :paid, :partially_refunded, :refunded, :failed or :canceled.
  • :reference: the caller's own id given at checkout; :owner: who the sale is for, as the checkout named them (MishkaPay.Checkout).
  • :customer_id, :customer_email, :customer_name: the buyer, as far as the provider knows them.
  • :description: the provider's description of the payment; :metadata: the extra pairs kept with it (Mishka Pay's own reference left out).
  • :payment_method: how it was paid, such as "card"; for a card, :card_brand ("visa") and :card_last4.
  • :receipt_url: the provider's receipt page for the buyer, once paid.
  • :failure_code, :failure_message: why the last try failed, such as "insufficient_funds".
  • :disputed: the buyer's bank has asked for it back (MishkaPay.Dispute).
  • :refunds: every MishkaPay.Refund made on it, newest first.
  • :checkout_id, :items: the checkout that took it and what it sold, each a MishkaPay.Price with its provider :id, :product_id, :name, unit :amount and :quantity; what a shop delivers. Read by MishkaPay.fetch_payment/3; a payment made outside a checkout (a subscription's renewal, a bill) has none, and list_payments/3 leaves them out.
  • :created_at: when the provider made it, a DateTime.

Summary

Types

t()

The struct that builder/1 returns.

Functions

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

Types

t()

@type t() :: %MishkaPay.Payment{
  amount: Money.t(),
  amount_captured: Money.t() | nil,
  amount_refunded: Money.t() | nil,
  card_brand: String.t() | nil,
  card_last4: String.t() | nil,
  checkout_id: String.t() | nil,
  created_at: DateTime.t() | nil,
  customer_email: String.t() | nil,
  customer_id: String.t() | nil,
  customer_name: String.t() | nil,
  description: String.t() | nil,
  disputed: boolean() | nil,
  failure_code: String.t() | nil,
  failure_message: String.t() | nil,
  fraud_review: MishkaPay.Payment.FraudReview.t() | nil,
  fraud_warning: MishkaPay.Payment.FraudWarning.t() | nil,
  id: String.t(),
  items: [MishkaPay.Price.t()] | nil,
  metadata: map() | nil,
  owner: String.t() | nil,
  payment_method: String.t() | nil,
  provider: String.t(),
  receipt_url: String.t() | nil,
  reference: String.t() | nil,
  refunds: [MishkaPay.Refund.t()] | nil,
  status: atom()
}

The struct that builder/1 returns.

FieldTypeRequiredDefaultDescriptionDerives
:providerString.t()yesvalidate(not_nil_value, string)
:idString.t()yesvalidate(not_nil_value, string, not_empty)
:amountMoney.t()yesvalidator {MishkaPay.Money, :field}
:amount_refundedMoney.t() | nilnovalidator {MishkaPay.Money, :field}
:amount_capturedMoney.t() | nilnovalidator {MishkaPay.Money, :field}
:statusatom()yesvalidate(not_nil_value, enum=Atom[pending::requires_action::authorized::paid::partially_refunded::refunded::failed::canceled])
:referenceString.t() | nilnovalidate(string)
:ownerString.t() | nilnovalidate(string)
:customer_idString.t() | nilnovalidate(string)
:customer_emailString.t() | nilnovalidate(string)
:customer_nameString.t() | nilnovalidate(string)
:descriptionString.t() | nilnovalidate(string)
:metadatamap() | nilno%{}validate(map)
:payment_methodString.t() | nilnovalidate(string)
:card_brandString.t() | nilnovalidate(string)
:card_last4String.t() | nilnovalidate(string)
:receipt_urlString.t() | nilnovalidate(string)
:failure_codeString.t() | nilnovalidate(string)
:failure_messageString.t() | nilnovalidate(string)
:disputedboolean() | nilnofalsevalidate(boolean)
:refunds[MishkaPay.Refund.t()] | nilno[]
:checkout_idString.t() | nilnovalidate(string)
:items[MishkaPay.Price.t()] | nilno[]
:created_atDateTime.t() | nilnovalidate(struct)
:fraud_reviewMishkaPay.Payment.FraudReview.t() | nilnoA payment the provider's fraud rules held for the seller to look at before it goes on (a review, prv_... at Stripe Radar). A guarded_struct the provider fills in, read with MishkaPay.fetch_fraud_review/3 and MishkaPay.list_fraud_reviews/3, and let through with MishkaPay.approve_fraud_review/3. Refunding the payment closes it the other way.
:fraud_warningMishkaPay.Payment.FraudWarning.t() | nilnoA card issuer's early warning that a payment looks like fraud (an early fraud warning, issfr_... at Stripe Radar), often days before the buyer's bank opens a dispute. A guarded_struct the provider fills in, read with MishkaPay.fetch_fraud_warning/3 and MishkaPay.list_fraud_warnings/3.

Functions

builder(attrs_or_input, error \\ false)

enforce_keys()

enforce_keys(field)

example()

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

keys()

keys(field)