PayJP for Elixir

TravisHex.pmHex DocsCoverage Status

An Elixir library for working with PAY.JP.

Features:

TODO

Installation

Install the dependency:

def deps do
  [{:payjp, "~> 0.1.0"}]
end

Next, add to your applications:

defp application do
  [applications: [:payjp]]
end

Configuration

To make API calls, it is necessary to configure your PAY.JP secret key.

use Mix.Config

config :payjp, secret_key: "YOUR SECRET KEY"

or add secret key to the environment variables

export PAYJP_SECRET_KEY="yourkey"

Usage

Token

params = [
  card: [
    number: "4242424242424242",
    exp_month: 12,
    exp_year: 2020,
    cvc: "123"
  ]
]

Payjp.Tokens.create(params)

Customer

customer = [
  email: "test@test.com",
  description: "An Elixir Test Account",
  metadata: [
    app_attr1: "xyz"
  ],
  card: [
    number: "4242424242424242",
    exp_month: 01,
    exp_year: 2020,
    cvc: 123,
    name: "Joe Test User"
  ]
]

Payjp.Customers.create(customer)

Card

new_card = [
  number: "4242424242424242",
  cvc: 123,
  exp_month: 12,
  exp_year: 2020
]

Payjp.Cards.create :customer, customer.id, new_card

Charge

with card information.

params = [
  card: [
    number: "4242424242424242",
    exp_month: 12,
    exp_year: 2020,
    cvc: "123"
  ]
]

Payjp.Charges.create(1000, params)

with token

params = [
  card: [
    number: "4242424242424242",
    exp_month: 12,
    exp_year: 2020,
    cvc: "123"
  ]
]

{:ok, token} = Payjp.Tokens.create(params)
Payjp.Charges.create(1000, card: token.id)

with customer id

{:ok, customer} = Payjp.Customers.create(customer)
Payjp.Charges.create(1000, customer: customer.id)

more usage is available at Documentation

Options

You can override the request configuration with HTTPoison options.

config.exs

config :payjp,
  httpoison_options: [
    timeout: 60000, # default: 30000
    recv_timeout: 100000, # default: 80000
  ]

Testing

If you start contributing and you want to run mix test, first you need to export PAYJP_SECRET_KEY environment variable in the same shell as the one you will be running mix test in.

export PAYJP_SECRET_KEY="yourkey"
mix test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT