An Elixir library for working with Paidy
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
.editorconfig
.formatter.exs
.gitignore
.probot.js
.travis.yml
LICENSE
README.md
mix.exs
mix.lock

README.md

Paidy for Elixir

Travis Hex.pm Hex Docs Coverage Status

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"}]
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