PayJP for Elixir
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
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
License
MIT