Triple (triple v1.0.0)

Copy Markdown View Source

Elixir client for the Triple transaction data enrichment API.

Quick start

client = Triple.new(api_key: System.fetch_env!("TRIPLE_API_KEY"))

{:ok, enriched} =
  Triple.enrich_transaction(client, %{
    merchant_name: "AMZN MKTP UK",
    transaction_type: :CARD_TRANSACTION,
    transaction_id: Triple.Util.generate_transaction_id(),
    transaction_amount: 24.99,
    transaction_currency: "GBP"
  })

client is a plain Triple.Config struct — pass it explicitly everywhere. There's no global or process-dictionary state, which keeps the library safe to use with multiple Triple accounts/environments (e.g. sandbox and production) side by side in the same application.

Configuration

Every option can be passed to new/1 directly, or set application-wide:

config :triple, api_key: System.fetch_env!("TRIPLE_API_KEY")

See Triple.Config for the full list of options (timeouts, retries, custom Req options, an optional client-side rate limiter, etc).

Error handling

Every call returns {:ok, result} | {:error, %Triple.Error{}}. Each function also has a ! counterpart that raises Triple.Error instead — e.g. enrich_transaction!/2. See Triple.Error for the fields available on failure (HTTP status, field-level validation errors, retry-after, etc).

Context modules

Every resource also has its own module if you'd rather call it directly: Triple.Enrich, Triple.Brands, Triple.Feedback, Triple.Stocks, Triple.Cryptos, Triple.TLS.

Summary

Types

client()

@type client() :: Triple.Config.t()

Functions

enrich_transaction(client, attrs)

@spec enrich_transaction(client(), map() | keyword()) ::
  {:ok, Triple.Types.Enrich.V1.Response.t()} | {:error, Triple.Error.t()}

See Triple.Enrich.transaction/2.

enrich_transaction!(client, attrs)

@spec enrich_transaction!(client(), map() | keyword()) ::
  Triple.Types.Enrich.V1.Response.t()

See Triple.Enrich.transaction!/2.

enrich_unstructured_transaction(client, attrs)

@spec enrich_unstructured_transaction(client(), map() | keyword()) ::
  {:ok, Triple.Types.Enrich.V2.Response.t()} | {:error, Triple.Error.t()}

See Triple.Enrich.unstructured_transaction/2.

enrich_unstructured_transaction!(client, attrs)

@spec enrich_unstructured_transaction!(client(), map() | keyword()) ::
  Triple.Types.Enrich.V2.Response.t()

See Triple.Enrich.unstructured_transaction!/2.

fetch_brand(client, id)

@spec fetch_brand(client(), String.t()) ::
  {:ok, Triple.Types.Brand.t()} | {:error, Triple.Error.t()}

See Triple.Brands.fetch/2.

fetch_brand!(client, id)

@spec fetch_brand!(client(), String.t()) :: Triple.Types.Brand.t()

See Triple.Brands.fetch!/2.

fetch_crypto(client, slug)

@spec fetch_crypto(client(), String.t()) ::
  {:ok, Triple.Types.Crypto.t()} | {:error, Triple.Error.t()}

See Triple.Cryptos.fetch/2.

fetch_crypto!(client, slug)

@spec fetch_crypto!(client(), String.t()) :: Triple.Types.Crypto.t()

See Triple.Cryptos.fetch!/2.

fetch_stock(client, isin, opts \\ [])

@spec fetch_stock(client(), String.t(), keyword()) ::
  {:ok, Triple.Types.Stock.t()} | {:error, Triple.Error.t()}

See Triple.Stocks.fetch/3.

fetch_stock!(client, isin, opts \\ [])

@spec fetch_stock!(client(), String.t(), keyword()) :: Triple.Types.Stock.t()

See Triple.Stocks.fetch!/3.

issue_tls_certificate(client, attrs)

@spec issue_tls_certificate(client(), map() | keyword()) ::
  {:ok, Triple.Types.TLSCertificate.t()} | {:error, Triple.Error.t()}

See Triple.TLS.issue_certificate/2.

issue_tls_certificate!(client, attrs)

@spec issue_tls_certificate!(client(), map() | keyword()) ::
  Triple.Types.TLSCertificate.t()

See Triple.TLS.issue_certificate!/2.

new(opts \\ [])

@spec new(keyword()) :: client()

Builds a client (a Triple.Config struct). See Triple.Config.new/1 for all options.

report_feedback(client, attrs)

@spec report_feedback(client(), map() | keyword()) ::
  {:ok, :no_content} | {:error, Triple.Error.t()}

See Triple.Feedback.report/2.

report_feedback!(client, attrs)

@spec report_feedback!(client(), map() | keyword()) :: :no_content

See Triple.Feedback.report!/2.