gringotts v1.0.0 Gringotts.Gateways.Stripe

Functions for working with Stripe payment gateway. Through this API you can:

  • Authorize payment source and use it later for payment.
  • Purchase with payment source.
  • Capture a payment for already authorized payment source.
  • Void the payment for payment source.
  • Refund amount to payment source.
  • Store payment source for making purchases later.
  • Unstore payment source.

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

Link to this section Summary

Functions

Authorize payment source

Captures a payment

Purchase with payment source

Refunds the amount

Stores the payment source

Unstore the stored payment source

Validates the config dynamically depending on what is the value of required_config

Voids the payment

Link to this section Functions

Link to this function authorize(amount, payment, opts)
authorize(Float, Map, List) :: Map

Authorize payment source.

Authorize the payment source for a customer or card using amount and opts. opts must include the default currency.

Examples

payment = %{
  expiration: {2018, 12}, number: "4242424242424242", cvc:  "123", name: "John Doe",
  street1: "123 Main", street2: "Suite 100", city: "New York", region: "NY", country: "US",
  postal_code: "11111"
}

opts = [currency: "usd"]
amount = 5

iex> Gringotts.authorize(:payment_worker, Gringotts.Gateways.Stripe, amount, payment, opts)
Link to this function capture(id, amount, opts)
capture(String.t(), Float, List) :: Map

Captures a payment.

Captures a payment with already authorized payment source. Once the charge is captured, it cannot be captured again. Amount less than or equal to authorized amount can be captured but not more than that. If less amount is captured than the authorized amount, then remaining amount will be refunded back to the authorized paymet source.

Examples

id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
amount = 5
opts = []

iex> Gringotts.capture(:payment_worker, Gringotts.Gateways.Stripe, id, amount, opts)
Link to this function purchase(amount, payment, opts)
purchase(Float, Map, List) :: Map

Purchase with payment source.

Purchase with the payment source using amount and opts. opts must include the default currency.

Examples

payemnt = %{
  expiration: {2018, 12}, number: "4242424242424242", cvc:  "123", name: "John Doe",
  street1: "123 Main", street2: "Suite 100", city: "New York", region: "NY", country: "US",
  postal_code: "11111"
}

opts = [currency: "usd"]
amount = 5

iex> Gringotts.purchase(:payment_worker, Gringotts.Gateways.Stripe, amount, payment, opts)
Link to this function refund(amount, id, opts)
refund(Float, String.t(), List) :: Map

Refunds the amount.

Returns the captured amount to the authorized payment source. Less than or equal to the captured amount can be refunded. If the refunded amount is less than the captured amount, then remaining amount can be refunded again.

Examples

amount = 5
id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
opts = []

iex> Gringotts.refund(:payment_worker, Gringotts.Gateways.Stripe, amount, id, opts)
Link to this function store(payment, opts)
store(Map, List) :: Map

Stores the payment source.

Store the payment source, so that it can be used for capturing the amount at later stages.

Examples

payment = %{
  expiration: {2018, 12}, number: "4242424242424242", cvc:  "123", name: "John Doe",
  street1: "123 Main", street2: "Suite 100", city: "New York", region: "NY", country: "US",
  postal_code: "11111"
}

opts = []

iex> Gringotts.store(:payment_worker, Gringotts.Gateways.Stripe, payment, opts)
Link to this function unstore(id, opts)

Unstore the stored payment source.

Unstore the already stored payment source, so that it cannot be used again for capturing payments.

Examples

id = "cus_BwpLX2x4ecEUgD"

iex> Gringotts.unstore(:payment_worker, Gringotts.Gateways.Stripe, id, opts)
Link to this function validate_config(config)

Validates the config dynamically depending on what is the value of required_config

Link to this function void(id, opts)
void(String.t(), List) :: Map

Voids the payment.

Returns the captured amount to the authorized payment source.

Examples

id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
opts = []

iex> Gringotts.void(:payment_worker, Gringotts.Gateways.Stripe, id, opts)