Payjp.Charges (payjp v0.1.6)
Functions for working with charges at Payjp. Through this API you can:
- create a charge,
- update a charge,
- get a charge,
- list charges,
- refund a charge,
- partially refund a charge.
Payjp API reference: https://pay.jp/docs/api/#charge-支払い
Link to this section Summary
Functions
Capture a charge.
Capture a charge. Accepts Payjp API key.
Update a charge.
Update a charge. Accepts Payjp API key.
Create a charge.
Create a charge. Accepts Payjp API key.
Get a charge.
Get a charge. Accepts Payjp API key.
Get a list of charges.
Get a list of charges. Accepts Payjp API key.
Refund a charge.
Refund a charge. Accepts Payjp API key.
Partially refund a charge.
Partially refund a charge. Accepts Payjp API key.
Link to this section Functions
capture(id)
Capture a charge.
Captures a charge that is currently pending.
Note: you can default a charge to be automatically captured by setting capture: true
in the charge create params.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.capture("charge_id")
capture(id, key)
Capture a charge. Accepts Payjp API key.
Captures a charge that is currently pending.
Note: you can default a charge to be automatically captured by setting capture: true
in the charge create params.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.capture("charge_id", "my_key")
change(id, params)
Update a charge.
Updates a charge with changeable information.
Accepts the following parameters:
params
- a list of params to be updated (optional; defaults to[]
). Available parameters are:description
,metadata
,receipt_email
,fraud_details
andshipping
.
Returns a {:ok, charge}
tuple.
Examples
params = [
description: "Changed charge"
]
{:ok, charge} = Payjp.Charges.change("charge_id", params)
change(id, params, key)
Update a charge. Accepts Payjp API key.
Updates a charge with changeable information.
Accepts the following parameters:
params
- a list of params to be updated (optional; defaults to[]
). Available parameters are:description
,metadata
,receipt_email
,fraud_details
andshipping
.
Returns a {:ok, charge}
tuple.
Examples
params = [
description: "Changed charge"
]
{:ok, charge} = Payjp.Charges.change("charge_id", params, "my_key")
create(amount, params)
Create a charge.
Creates a charge for a customer or card using amount and params. params
must include a source.
Returns {:ok, charge}
tuple.
Examples
Create a charge with card object
params = [
card: [
number: "4242424242424242",
exp_month: 10,
exp_year: 2020,
country: "JP",
name: "Ducky Test",
cvc: 123
],
description: "1000 Widgets"
]
{:ok, charge} = Payjp.Charges.create(1000, params)
Create a charge with card token
params = [
card: [
number: "4242424242424242",
exp_month: 8,
exp_year: 2016,
cvc: "314"
]
]
{:ok, token} = Payjp.Tokens.create params
params = [
card: token.id
]
{:ok, charge} = Payjp.Charges.create(1000, params)
Create a charge with customer ID
new_customer = [
email: "test@test.com",
description: "An Test Account",
metadata:[
app_order_id: "ABC123"
app_state_x: "xyz"
],
card: [
number: "4111111111111111",
exp_month: 01,
exp_year: 2018,
cvc: 123,
name: "Joe Test User"
]
]
{:ok, customer} = Payjp.Customers.create new_customer
params = [
customer: customer.id
]
{:ok, charge} = Payjp.Charges.create(1000, params)
create(amount, params, key)
Create a charge. Accepts Payjp API key.
Creates a charge for a customer or card using amount and params. params
must include a source.
Returns {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.create(1000, params, key)
get(id)
Get a charge.
Gets a charge.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.get("charge_id")
get(id, key)
Get a charge. Accepts Payjp API key.
Gets a charge.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.get("charge_id", "my_key")
list(opts \\ [])
Get a list of charges.
Gets a list of charges.
Accepts the following parameters:
opts
- a list of params supported by Payjp (optional; defaults to []). Available parameters are:customer
,since
,until
,subscription
,limit
andoffset
.
Returns a {:ok, charges}
tuple, where charges
is a list of charges.
Examples
{:ok, charges} = Payjp.Charges.list(limit: 20) # Get a list of charges up to 20 items (default: 10)
{:ok, charges} = Payjp.Charges.list(customer: "customer_id") # Get a list of charges for customer
{:ok, charges} = Payjp.Charges.list(subscription: "subscription_id") # Get a list of charges for given subscription id
{:ok, charges} = Payjp.Charges.list(since: 1487473464) # Get a list of charges created after specified time stamp
list(key, opts)
Get a list of charges. Accepts Payjp API key.
Gets a list of charges.
Accepts the following parameters:
opts
- a list of params supported by Payjp (optional; defaults to []). Available parameters are:customer
,since
,until
,subscription
,limit
andoffset
.
Returns a {:ok, charges}
tuple, where charges
is a list of charges.
Examples
{:ok, charges} = Payjp.charges.list("my_key") # Get a list of up to 10 charges
{:ok, charges} = Payjp.charges.list("my_key", limit: 20) # Get a list of up to 20 charges
refund(id)
Refund a charge.
Refunds a charge completely.
Note: use refund_partial
if you just want to perform a partial refund.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.refund("charge_id")
refund(id, key)
Refund a charge. Accepts Payjp API key.
Refunds a charge completely.
Note: use refund_partial
if you just want to perform a partial refund.
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.refund("charge_id", "my_key")
refund_partial(id, amount)
Partially refund a charge.
Refunds a charge partially.
Accepts the following parameters:
amount
- amount to be refunded (required).
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.refund_partial("charge_id", 500)
refund_partial(id, amount, key)
Partially refund a charge. Accepts Payjp API key.
Refunds a charge partially.
Accepts the following parameters:
amount
- amount to be refunded (required).
Returns a {:ok, charge}
tuple.
Examples
{:ok, charge} = Payjp.Charges.refund_partial("charge_id", 500, "my_key")