Skip to content

Cashier is an Elixir library that aims to be an easy to use payment gateway, whilst offering the fault tolerance and scalability benefits of being built on top of Erlang/OTP

License

Notifications You must be signed in to change notification settings

locrianmode/cashier

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cashier

Build Status Deps Status Hex Version Join the chat at https://gitter.im/swelham/cashier

Cashier is an Elixir library that aims to be an easy to use payment gateway, whilst offering the fault tolerance and scalability benefits of being built on top of Erlang/OTP

Usage

The following are basic usage examples on how to use cashier in it's current state. This library is being activily developed and is likely to change as we move towards the first release.

Setup

Add cashier as a dependency

defp deps do
  {:cashier, "~> 0.2.0"}
end

Make sure the cashier application gets started

def application do
  [applications: [:cashier]]
end

Config options

use Mix.Config

# cashier options
config :cashier, :cashier,
  defaults: [
    currency: "USD",
    gateway: :paypal,
    timeout: 20_000 # this option is the OTP timeout setting
  ],
  # this option is passed directly into HTTPoison and can contain any
  # of the valid options listed here - https://hexdocs.pm/httpoison/HTTPoison.html#request/5
  http: [
    recv_timeout: 20_000
  ]

# PayPal specific config
config :cashier, :paypal,
  # Please note the PayPal gateway currently only supports the /v1 endpoint
  # and this is automattically added for you
  url: "https://api.sandbox.paypal.com",
  client_id: "<paypal_client_id>",
  client_secret: "<paypal_client_secret>"

Cashier request examples

alias Cashier.Address
alias Cashier.PaymentCard

address = %Address{
    line1: "123",
    line2: "Main",
    city: "New York",
    state: "New York",
    country_code: "US",
    postal_code: "10004"
}

card = %PaymentCard{
    holder: {"John", "Smith"},
    brand: "visa",
    number: "4032030901103714",
    expiry: {11, 2021},
    cvv: "123"
}

# Note: The result return type for each request is currently the decoded
#       data returned from the payment provider, this will change in the future.

# Purchase request
# the card parameter can be either a %PaymentCard or stored card id 
case Cashier.purchase(9.99, card, [billing_address: address]) do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

# Authorize request
# the card parameter can be either a %PaymentCard or stored card id 
case Cashier.authorize(9.99, card, [billing_address: address]) do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

# Capture request
case Cashier.capture("<capture_id>", 19.45, [final_capture: true]) do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

#Void request
case Cashier.void("<void_id>") do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

#Refund request
case Cashier.refund("<refund_id>", [amount: 9.99]) do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

#Store request
case Cashier.store(card, [billing_address: address]) do
    {:ok, result}     -> IO.inspect result
    {:error, reason}  -> IO.inspect reason
end

#Unstore request
case Cashier.unstore("<card_id>") do
    :ok               -> IO.puts "card unstored"
    {:error, reason}  -> IO.inspect reason
end

Todo

All current todo items are listed on the issues page.

Please add any issues, suggestions or feature requests to this page.

About

Cashier is an Elixir library that aims to be an easy to use payment gateway, whilst offering the fault tolerance and scalability benefits of being built on top of Erlang/OTP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Elixir 100.0%