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(Spreedly.Environment.t, Keyword.t) :: {:ok, any} | {:error, any}
add_gateway(Spreedly.Environment.t, String.t, map) :: {:ok, any} | {:error, any}
add_receiver(Spreedly.Environment.t, String.t, Keyword.t) :: {:ok, any} | {:error, any}
capture(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
credit(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
credit(Spreedly.Environment.t, String.t, pos_integer, String.t) :: {:ok, any} | {:error, any}
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(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(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"])
Retrieve a list of all gateways, and their properties, supported by Spreedly.
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 isasc
, which returns the oldest records first. To list newer records first, usedesc
.: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(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(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
redact_payment_method(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
retain_payment_method(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_dispatch(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_gateway(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_payment_method(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_receiver(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_transaction(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
show_transcript(Spreedly.Environment.t, String.t) :: {:ok, any} | {:error, any}
store_payment_method(Spreedly.Environment.t, String.t, String.t) :: {:ok, any} | {:error, any}
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])