An Elixir library for working with PAY.JP.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
fixture/vcr_cassettes
lib
test
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
mix.exs
mix.lock

README.md

PayJP for Elixir

Travis Hex.pm Hex Docs Coverage Status

An Elixir library for working with PAY.JP.

Features:

  • manage accounts (your own)
  • manage customers
  • manage subscriptions
  • manage plans
  • manage tokens for credit card
  • list and retrieve events
  • manage/capture charges with or without an existing Customer

TODO

  • Transfer
  • OAuth

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

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

Payjp.Tokens.create(params)

Customer

  • create a customer with default card
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

  • create a card for customer
new_card = [
  number: "4242424242424242",
  cvc: 123,
  exp_month: 12,
  exp_year: 2020
]

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

Charge

  • create a 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