Paidy for Elixir

TravisHex.pmHex DocsCoverage Status

An Elixir library for working with Paidy.

Features

Payments

Tokens

Installation

def deps do
[{:paidy, "~> 0.2.0"}]
end

Usage

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.all

Suspend a token

params = %{
reason: %{
code: "fraud.suspected",
description: "Token suspended because fraud suspected."
}
}
{:ok, token} = Paidy.Token.suspend "token_id", params

Resume 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", params

Delete a token

{:ok, token} = Paidy.Token.delete "token_id", params

Testing

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 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