Stripe.Converter (stripity_stripe v2.17.3) View Source

Link to this section Summary

Functions

Takes a result map or list of maps from a Stripe response and returns a struct (e.g. %Stripe.Card{}) or list of structs.

Returns a list of structs to be used for providing JSON-encoders.

Link to this section Functions

Specs

convert_result(%{required(String.t()) => any()}) :: struct()

Takes a result map or list of maps from a Stripe response and returns a struct (e.g. %Stripe.Card{}) or list of structs.

If the result is not a supported Stripe object, it just returns a plain map with atomized keys.

Returns a list of structs to be used for providing JSON-encoders.

Examples

Say you are using Jason to encode your JSON, you can provide the following protocol, to directly encode all structs of this library into JSON.

for struct <- Stripe.Converter.structs() do
  defimpl Jason.Encoder, for: struct do
    def encode(value, opts) do
      Jason.Encode.map(Map.delete(value, :__struct__), opts)
    end
  end
end