payjp v0.1.1 Payjp.Cards

Functions for working with cards at Payjp. Through this API you can:

  • create a card,
  • update a card,
  • get a card,
  • delete a card,
  • delete all cards,
  • list cards,
  • list all cards,

All requests require owner_type and owner_id parameters to be specified.

owner_type must be one of the following:

  • customer

owner_id must be the ID of the owning object.

Payjp API reference: https://pay.jp/docs/api/#顧客のカードを作成

Summary

Functions

all(owner_type, owner_id, accum \\ [], opts \\ [limit: 100])

List all cards.

Lists all cards for a given owner.

Accepts the following parameters:

  • accum - a list to start accumulating cards to (optional; defaults to []).,
  • since - an offset (optional; defaults to "").

Returns {:ok, cards} tuple.

Examples

{:ok, cards} = Payjp.Cards.all(:customer, customer_id, accum, since)
all(owner_type, owner_id, key, accum, opts)

List all cards. Accepts Payjp API key.

Lists all cards for a given owner.

Accepts the following parameters:

  • accum - a list to start accumulating cards to (optional; defaults to []).,
  • since - an offset (optional; defaults to "").

Returns {:ok, cards} tuple.

Examples

{:ok, cards} = Payjp.Cards.all(:customer, customer_id, accum, since, key)
create(owner_type, owner_id, params)

Create a card.

Creates a card for given owner type, owner ID using params.

params must contain a “card” object. Inside the “card” object, the following parameters are required:

  • number,
  • cvs,
  • exp_month,
  • exp_year.

Returns a {:ok, card} tuple.

Examples

params = [
  card: [
    number: "4242424242424242",
    cvc: 123,
    exp_month: 12,
    exp_year: 2020,
  ],
  metadata: [
    test_field: "test val"
  ]
]

{:ok, card} = Payjp.Cards.create(:customer, customer_id, params)
create(owner_type, owner_id, params, key)

Create a card. Accepts Payjp API key.

Creates a card for given owner using params.

params must contain a “card” object. Inside the “card” object, the following parameters are required:

  • number,
  • cvs,
  • exp_month,
  • exp_year.

Returns a {:ok, card} tuple.

Examples

{:ok, card} = Payjp.Cards.create(:customer, customer_id, params, key)
delete(owner_type, owner_id, id)

Delete a card.

Deletes a card for given owner using card ID.

Returns a {:ok, card} tuple.

Examples

{:ok, deleted_card} = Payjp.Cards.delete("card_id")
delete(owner_type, owner_id, id, key)

Delete a card. Accepts Payjp API key.

Deletes a card for given owner using card ID.

Returns a {:ok, card} tuple.

Examples

{:ok, deleted_card} = Payjp.Cards.delete("card_id", key)
delete_all(owner_type, owner_id)

Delete all cards.

Deletes all cards from given owner.

Returns :ok atom.

Examples

:ok = Payjp.Cards.delete_all(:customer, customer_id)
delete_all(owner_type, owner_id, key)

Delete all cards. Accepts Payjp API key.

Deletes all cards from given owner.

Returns :ok atom.

Examples

:ok = Payjp.Cards.delete_all(:customer, customer_id, key)
endpoint_for_entity(entity_type, entity_id)
get(owner_type, owner_id, id)

Get a card.

Gets a card for given owner using card ID.

Returns a {:ok, card} tuple.

Examples

{:ok, card} = Payjp.Cards.get(:customer, customer_id, card_id)
get(owner_type, owner_id, id, key)

Get a card. Accepts Payjp API key.

Gets a card for given owner using card ID.

Returns a {:ok, card} tuple.

Examples

{:ok, card} = Payjp.Cards.get(:customer, customer_id, card_id, key)
list(owner_type, owner_id, opts \\ [])

Get a list of cards.

Gets a list of cards for given owner.

Accepts the following parameters:

  • limit - a limit of items to be returned (optional; defaults to 10).
  • offset - an offset (optional),
  • since - a timestamp for returning subsequent data specified here (optional),
  • until - a timestamp for returning the previous data specified here (optional),

Returns a {:ok, cards} tuple, where cards is a list of cards.

Examples

{:ok, cards} = Payjp.Cards.list(:customer, customer_id, offset: 5) # Get a list of up to 10 cards, skipping first 5 cards
{:ok, cards} = Payjp.Cards.list(:customer, customer_id, offset: 5, limit: 20) # Get a list of up to 20 cards, skipping first 5 cards
list(owner_type, owner_id, key, opts)

Get a list of cards. Accepts Payjp API key.

Gets a list of cards for a given owner.

Accepts the following parameters:

  • limit - a limit of items to be returned (optional; defaults to 10).
  • offset - an offset (optional),
  • since - a timestamp for returning subsequent data specified here (optional),
  • until - a timestamp for returning the previous data specified here (optional),

Returns a {:ok, cards} tuple, where cards is a list of cards.

Examples

{:ok, cards} = Payjp.Cards.list(:customer, customer_id, offset: 5) # Get a list of up to 10 cards, skipping first 5 cards {:ok, cards} = Payjp.Cards.list(:customer, customer_id, offset: 5, limit: 20) # Get a list of up to 20 cards, skipping first 5 cards

update(owner_type, owner_id, id, params)

Update a card.

Updates a card for given owner using card ID and params.

  • owner_type must be one of the following:

    • customer,
  • owner_id must be the ID of the owning object.

Returns a {:ok, card} tuple.

Examples

{:ok, card} = Payjp.Cards.update(:customer, customer_id, card_id, params)
update(owner_type, owner_id, id, params, key)

Update a card. Accepts Payjp API key.

Updates a card for given owner using card ID and params.

Returns a {:ok, card} tuple.

Examples

{:ok, card} = Payjp.Cards.update(:customer, customer_id, card_id, params, key)