stripity_stripe v1.6.0 Stripe.Charges

Functions for working with charges at Stripe. Through this API you can:

  • create a charge,
  • update a charge,
  • get a charge,
  • list charges,
  • count charges,
  • refund a charge,
  • partially refund a charge.

Stripe API reference: https://stripe.com/docs/api#charges

Summary

Functions

Capture a charge

Capture a charge. Accepts Stripe API key

Update a charge

Update a charge. Accepts Stripe API key

Get total number of charges

Get total number of charges. Accepts Stripe API key

Create a charge

Create a charge. Accepts Stripe API key

Get a charge

Get a charge. Accepts Stripe API key

Get a list of charges

Get a list of charges. Accepts Stripe API key

Refund a charge

Refund a charge. Accepts Stripe API key

Partially refund a charge

Partially refund a charge. Accepts Stripe API key

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} = Stripe.Charges.capture("charge_id")
capture(id, key)

Capture a charge. Accepts Stripe 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} = Stripe.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 and shipping.

Returns a {:ok, charge} tuple.

Examples

params = [
  description: "Changed charge"
]

{:ok, charge} = Stripe.Charges.change("charge_id", params)
change(id, params, key)

Update a charge. Accepts Stripe 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 and shipping.

Returns a {:ok, charge} tuple.

Examples

params = [
  description: "Changed charge"
]

{:ok, charge} = Stripe.Charges.change("charge_id", params, "my_key")
count()

Get total number of charges.

Gets total number of charges.

Returns {:ok, count} tuple.

Examples

{:ok, count} = Stripe.Charges.count()
count(key)

Get total number of charges. Accepts Stripe API key.

Gets total number of charges.

Returns {:ok, count} tuple.

Examples

{:ok, count} = Stripe.Charges.count("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

params = [
  source: [
    object: "card",
    number: "4111111111111111",
    exp_month: 10,
    exp_year: 2020,
    country: "US",
    name: "Ducky Test",
    cvc: 123
  ],
  description: "1000 Widgets"
]

{:ok, charge} = Stripe.Charges.create(1000, params)
create(amount, params, key)

Create a charge. Accepts Stripe 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} = Stripe.Charges.create(1000, params, key)
get(id)

Get a charge.

Gets a charge.

Returns a {:ok, charge} tuple.

Examples

{:ok, charge} = Stripe.Charges.get("charge_id")
get(id, key)

Get a charge. Accepts Stripe API key.

Gets a charge.

Returns a {:ok, charge} tuple.

Examples

{:ok, charge} = Stripe.Charges.get("charge_id", "my_key")
list(params \\ [])

Get a list of charges.

Gets a list of charges.

Accepts the following parameters:

  • params - a list of params supported by Stripe (optional; defaults to []). Available parameters are: customer, ending_before, limit and source.

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

Examples

{:ok, charges} = Stripe.Charges.list(source: "card") # Get a list of charges for cards
list(key, limit)

Get a list of charges. Accepts Stripe API key.

Gets a list of charges.

Accepts the following parameters:

  • params - a list of params supported by Stripe (optional; defaults to []). Available parameters are: customer, ending_before, limit and source.

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

Examples

{:ok, charges} = Stripe.Charges.list("my_key", source: "card") # Get a list of charges for cards
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} = Stripe.Charges.refund("charge_id")
refund(id, key)

Refund a charge. Accepts Stripe 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} = Stripe.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} = Stripe.Charges.refund_partial("charge_id", 500)
refund_partial(id, amount, key)

Partially refund a charge. Accepts Stripe API key.

Refunds a charge partially.

Accepts the following parameters:

  • amount - amount to be refunded (required).

Returns a {:ok, charge} tuple.

Examples

{:ok, charge} = Stripe.Charges.refund_partial("charge_id", 500, "my_key")