Giter Club home page Giter Club logo

braintree-elixir's Introduction

Braintree

Build Status Coverage Status Hex version Hex downloads Inline docs

A native Braintree client library for Elixir. Only a subset of the API is supported and this is a work in progress. That said, it is production ready and any modules that have been implemented can be used.

Installation

Add braintree to your list of dependencies in mix.exs:

def deps do
  [{:braintree, "~> 0.7"}]
end

Once that is configured you are all set. Braintree is a library, not an application, but it does rely on hackney, which must be started:

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

Within your application you will need to configure the merchant id and authorization keys. You do not want to put this information in your config.exs file! Either put it in a {prod,dev,test}.secret.exs file which is sourced by config.exs, or read the values in from the environment:

config :braintree,
  environment: :sandbox,
  merchant_id: System.get_env("BRAINTREE_MERCHANT_ID"),
  public_key:  System.get_env("BRAINTREE_PUBLIC_KEY"),
  private_key: System.get_env("BRAINTREE_PRIVATE_KEY")

Furthermore, the environment defaults ot :sandbox, so you'll want to configure it with :production in prod.exs.

You can optionally configure Hackney options with:

config :braintree,
  http_options: [
    timeout: 8000,     # default, in milliseconds
    recv_timeout: 5000 # default, in milliseconds
  ]

Usage

The online documentation for Ruby/Java/Python etc. will give you a general idea of the modules and available functionality. Where possible, which is everywhere so far, the namespacing has been matched.

The CRUD functions for each action module break down like this:

alias Braintree.Customer
alias Braintree.ErrorResponse, as: Error

case Customer.create(%{company: "Whale Corp"}) do
  {:ok, %Customer{} = customer} -> do_stuff_with_customer(customer)
  {:error, %Error{} = error}    -> do_stuff_with_error(error)
end

Testing

You'll need a Braintree sandbox account to run the integration tests. Also, be sure that your account has Duplicate Transaction Checking disabled.

Your environment needs to have the following:

  • Add-ons with ids: "bronze", "silver" and "gold"
  • Plans with ids: "starter", "business"
  • "business" plan needs to include the following Add-ons: "bronze" and "silver"

License

MIT License, see LICENSE.txt for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.