spreedly v2.2.0 Spreedly

An Elixir client implementation of the Spreedly API.

For more info visit the Spreedly API docs for a detailed listing of available API methods.

Usage

API interactions happen with a Spreedly.Environment.

iex> env = Spreedly.Environment.new(environment_key, access_secret)

Once you have an environment, you can use it to interact with the API.

Run a purchase using a credit card

You can pattern match on the response.

iex> case Spreedly.purchase(env, "R8AKGmYwkZrrj2BpWcPge", "RjTFFZQp4MrH2HJNfPwK", 2344) do
        {:ok, %{succeeded: true}} ->
          IO.puts "Success!"
        {:ok, %{succeeded: false, message: msg}} ->
          IO.puts "Declined!"
        {:error, reason} ->
          IO.inspect reason
      end

Show a Transaction

iex> Spreedly.show_transaction(env, "7f6837d1d22e049f8a47a8cc1fa9")
{:ok,
%{created_at: "2016-01-10T16:36:14Z", currency_code: nil, description: nil,
  ...
  state: "gateway_processing_failed", succeeded: false,
  token: "7f6837d1d22e049f8a47a8cc1fa9", transaction_type: "Verification",
  updated_at: "2016-01-10T16:36:14Z"}}

iex> Spreedly.find_transaction(env, "NonExistentToken")
{:error, "Unable to find the transaction NonExistentToken."}

Summary

Functions

Authorize a payment method to be charged a specific amount for the provided gateway token with optional request body data specified as a keyword list

Retrieve a list of created gateways in the environment with optional query params specified as a keyword list

List transactions for the provided gateway token with optional query params specified as a keyword list

List transactions for the provided payment method token with optional query params specified as a keyword list

Retrieve a list of all gateways, and their properties, supported by Spreedly

Retrieve a list of all transactions for the authenticated environment

Make a purchase for the provided gateway token and payment method token with optional request body data specified as a keyword list

Determine if a credit card is a chargeable card and available for purchases, with optional request body data specified as a keyword list

Functions

add_credit_card(env, options)
add_credit_card(Spreedly.Environment.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}
add_gateway(env, gateway_type, gateway_params \\ %{})
add_gateway(Spreedly.Environment.t, String.t, map) ::
  {:ok, any} |
  {:error, any}
add_receiver(env, receiver_type, options \\ [])
add_receiver(Spreedly.Environment.t, String.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}
authorization(env, gateway_token, payment_method_token, amount, currency_code \\ "USD", options \\ [])
authorization(Spreedly.Environment.t, String.t, String.t, pos_integer, String.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

Authorize a payment method to be charged a specific amount for the provided gateway token with optional request body data specified as a keyword list.

Amount should be provided as a positive integer in cents.

Examples

authorization(env, "gateway_token", "payment_method_token", 100)
authorization(env, "gateway_token", "payment_method_token", 100, "USD", [order_id: "44", description: "My auth"])
capture(env, transaction_token)
capture(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
credit(env, transaction_token)
credit(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
credit(env, transaction_token, amount, currency_code)
credit(Spreedly.Environment.t, String.t, pos_integer, String.t) ::
  {:ok, any} |
  {:error, any}
dispatch(env, gateway_token, payment_method_token, amount, currency_code \\ "USD", options \\ [])
list_created_gateways(env, params \\ [])
list_created_gateways(Spreedly.Environment.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

Retrieve a list of created gateways in the environment with optional query params specified as a keyword list.

Examples

list_created_gateways(env)
list_created_gateways(env, [order: :desc, since_token: "token"])
list_gateway_transactions(env, gateway_token, params \\ [])
list_gateway_transactions(Spreedly.Environment.t, String.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

List transactions for the provided gateway token with optional query params specified as a keyword list.

Examples

list_gateway_transactions(env, "token")
list_gateway_transactions(env, "token", order: :desc, since_token: "token"])
list_payment_method_transactions(env, payment_method_token, params \\ [])
list_payment_method_transactions(Spreedly.Environment.t, String.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

List transactions for the provided payment method token with optional query params specified as a keyword list.

Examples

list_payment_method_transactions(env, "token")
list_payment_method_transactions(env, "token", [order: :desc, since_token: "token"])
list_supported_gateways()

Retrieve a list of all gateways, and their properties, supported by Spreedly.

list_transactions(env, params \\ [])
list_transactions(Spreedly.Environment.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

Retrieve a list of all transactions for the authenticated environment.

The list of transactions can be ordered and paginated by providing optional query params specified as a keyword list.

Params

  • :order - The order of the returned list. Default is asc, which returns the oldest records first. To list newer records first, use desc.

  • :since_token - The token of the item to start from (e.g., the last token received in the previous list if iterating through records).

  • :count - The number of transactions to return. By default returns 20, maximum allowed is 100.

Examples

list_transactions(env)
list_transactions(env, order: :desc, since_token: "token", count: 100])
purchase(env, gateway_token, payment_method_token, amount, currency_code \\ "USD", options \\ [])
purchase(Spreedly.Environment.t, String.t, String.t, pos_integer, String.t, Keyword.t) ::
  {:ok, any} |
  {:error, any}

Make a purchase for the provided gateway token and payment method token with optional request body data specified as a keyword list.

Amount should be provided as a positive integer in cents.

Examples

purchase(env, "gateway_token", "payment_method_token", 100)
purchase(env, "gateway_token", "payment_method_token", 100, "USD", [order_id: "44", description: "My purchase"])
redact_gateway(env, token)
redact_gateway(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
redact_payment_method(env, token)
redact_payment_method(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
retain_payment_method(env, token)
retain_payment_method(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_dispatch(env, dispatch_token)
show_dispatch(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_gateway(env, gateway_token)
show_gateway(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_payment_method(env, payment_method_token)
show_payment_method(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_receiver(env, receiver_token)
show_receiver(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_transaction(env, transaction_token)
show_transaction(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
show_transcript(env, transaction_token)
show_transcript(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}
store_payment_method(env, gateway_token, payment_method_token)
store_payment_method(Spreedly.Environment.t, String.t, String.t) ::
  {:ok, any} |
  {:error, any}
verify(env, gateway_token, payment_method_token, currency_code \\ nil, options \\ [])
verify(Spreedly.Environment.t, String.t, String.t, String.t | nil, Keyword.t) ::
  {:ok, any} |
  {:error, any}

Determine if a credit card is a chargeable card and available for purchases, with optional request body data specified as a keyword list.

Examples

verify(env, "gateway_token", "payment_method_token")
verify(env, "gateway_token", "payment_method_token", "USD", [retain_on_success: true])
void(env, transaction_token)
void(Spreedly.Environment.t, String.t) ::
  {:ok, any} |
  {:error, any}