Paidy for Elixir
An Elixir library for working with Paidy.
Features
Payments
- create a payment
- retrieve a payment
- update a payment
- capture a payment
- refund/partially refund a payment
- close a payment
Tokens
- retrieve a token
- retrieve all tokens
- suspend a token
- resume a token
- delete a token
Installation
def deps do
[{:paidy, "~> 0.2.0"}]
endUsage
Create a payment
params = %{
amount: 12500,
shipping_address: %{
line1: "AXIS building 10F",
line2: "roppongi 4-22-1",
state: "Minato-ku",
city: "Tokyo",
zip: "106-2004"
},
order: %{
order_ref: "your_order_ref",
items: [%{
quantity: 1,
id: "PDI001",
title: "Paidy shoes",
description: "Paidy shoes",
unit_price: 12000
}],
tax: 300,
shipping: 200
},
store_name: "Paidy sample store",
buyer_data: %{
age: 29,
order_count: 1000,
ltv: 250000,
last_order_amount: 20000,
last_order_at: 20
},
description: "hoge",
token_id: "tok_foobar",
currency: "JPY",
metadata: %{}
}
{:ok, payment} = Paidy.Payment.create(params)Retrieve a payment
{:ok, payment} = Paidy.Payment.get("payment_id")Update a payment
params = %{
description: "Changed payment"
}
{:ok, payment} = Paidy.Payment.change("payment_id", params)Capture a payment
{:ok, captured} = Paidy.Payment.capture("payment_id")Refund a payment
{:ok, payment} = Paidy.Payment.capture("payment_id")
capture_id = payment.captures |> List.first |> Map.get("id")
{:ok, payment} = Paidy.Payment.refund("payment_id", capture_id)Partially refund a payment
{:ok, payment} = Paidy.Payment.capture("payment_id")
capture_id = payment.captures |> List.first |> Map.get("id")
{:ok, payment} = Paidy.Payment.refund("payment_id", capture_id, 500)Close a payment
{:ok, payment} = Paidy.Payment.close("payment_id")Retrieve a token
{:ok, token} = Paidy.Token.get "token_id"Retrieve all tokens
{:ok, tokens} = Paidy.Token.allSuspend a token
params = %{
reason: %{
code: "fraud.suspected",
description: "Token suspended because fraud suspected."
}
}
{:ok, token} = Paidy.Token.suspend "token_id", paramsResume a token
params = %{
reason: %{
code: "merchant.requested",
description: "Token is being resumed because the subscription item is back in stock"
}
}
{:ok, token} = Paidy.Token.resume "token_id", paramsDelete a token
{:ok, token} = Paidy.Token.delete "token_id", paramsTesting
If you start contributing and you want to run mix test, first you need to export PAIDY_SECRET_KEY environment variable in the same shell as the one you will be running mix test in.
export PAIDY_SECRET_KEY="yourkey"
mix testContributing
- 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