MPP.Discovery.PaymentInfo (mpp v0.14.0)

Copy Markdown View Source

Parser and normalizer for the discovery specification's x-payment-info extension.

Both the single-offer shorthand and the multi-offer form are accepted. The normalized result always uses the multi-offer offers array recommended for newly published discovery documents.

API Functions

FunctionArityDescriptionParam Kinds
parse1Parse x-payment-info and normalize single-offer shorthand into the multi-offer array form.payment_info: value

Summary

Functions

Parse x-payment-info and normalize single-offer shorthand into the multi-offer array form.

Types

offer()

@type offer() :: %{required(String.t()) => String.t() | nil}

reason()

@type reason() ::
  :empty_offers
  | :invalid_payment_info
  | :mixed_offer_forms
  | {:invalid_offer, non_neg_integer(), term()}

t()

@type t() :: %{required(String.t()) => [offer()]}

Functions

parse(payment_info)

@spec parse(term()) :: {:ok, t()} | {:error, reason()}

Parse x-payment-info and normalize single-offer shorthand into the multi-offer array form.

Parameters

  • payment_info - JSON-compatible x-payment-info map (value)

Returns

{:ok, %{"offers" => offers}} or {:error, reason} (tagged_tuple)

Errors

  • :invalid_payment_info
  • :mixed_offer_forms
  • :empty_offers
  • :invalid_offer
# descripex:contract
%{
  params: %{
    payment_info: %{
      description: "JSON-compatible x-payment-info map",
      kind: :value
    }
  },
  errors: [:invalid_payment_info, :mixed_offer_forms, :empty_offers,
   :invalid_offer],
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, %{\"offers\" => offers}}` or `{:error, reason}`"
  }
}