View Source Gringotts.Gateways.Stripe (gringotts v1.1.1)

Stripe gateway implementation. For reference see Stripe's API documentation. The following features of Stripe are implemented:

ActionMethod
Pre-authorizeauthorize/3
Capturecapture/3
Refundrefund/3
Reversalvoid/2
Debitpurchase/3
Storestore/2
Unstoreunstore/2

the-opts-argument

The opts argument

Most Gringotts API calls accept an optional Keyword list opts to supply optional arguments for transactions with the Stripe gateway. The following keys are supported:

KeyStatus
currencyImplemented
captureImplemented
descriptionImplemented
metadataImplemented
receipt_emailImplemented
shippingImplemented
customerImplemented
sourceImplemented
statement_descriptorImplemented
chargeImplemented
reasonImplemented
account_balanceNot implemented
business_vat_idNot implemented
couponNot implemented
default_sourceNot implemented
emailNot implemented
shippingNot implemented

note

Note

This module can be used by both PCI-DSS compliant as well as non-compliant merchants!

i-m-not-pci-dss-compliant

I'm not PCI-DSS compliant

No worries, both authorize/3 and purchase/3 accept a "payment-source-identifier" (a string) instead of a CreditCard.t struct. You'll have to generate this identifier using Stripe.js and Elements client-side.

i-m-pci-dss-compliant

I'm PCI-DSS compliant

In that case, you need not use Stripe.js or Elements and can directly accept the client's card info and pass the CreditCard.t struct to this module's functions.

registering-your-stripe-account-at-gringotts

Registering your Stripe account at Gringotts

After making an account on Stripe, head to the dashboard and find your account secrets in the API section.

here-s-how-the-secrets-map-to-the-required-configuration-parameters-for-stripe

Here's how the secrets map to the required configuration parameters for Stripe:

Config parameterStripe secret
:secret_keySecret key

Your Application config must look something like this:

config :gringotts, Gringotts.Gateways.Stripe,
    secret_key: "your_secret_key",
    default_currency: "usd"

Link to this section Summary

Functions

Performs a (pre) Authorize operation.

Captures a pre-authorized amount.

Transfers amount from the customer to the merchant.

Refunds the amount to the customer's card with reference to a prior transfer.

Stores the payment-source data for later use.

Deletes previously stored payment-source data.

Catches gateway configuration errors.

Voids the referenced payment.

Link to this section Functions

Link to this function

authorize(amount, payment, opts)

View Source
@spec authorize(Gringotts.Money.t(), Gringotts.CreditCard.t() | String.t(), keyword()) ::
  map()

Performs a (pre) Authorize operation.

The authorization validates the card details with the banking network, places a hold on the transaction amount in the customer’s issuing bank and also triggers risk management. Funds are not transferred.

Stripe returns an charge_id which should be stored at your side and can be used later to:

note

Note

Uncaptured charges expire in 7 days. For more information, see authorizing charges and settling later.

example

Example

The following session shows how one would (pre) authorize a payment of $10 on a sample card.

iex> card = %CreditCard{
      first_name: "John",
      last_name: "Smith",
      number: "4242424242424242",
      year: "2017",
      month: "12",
      verification_code: "123"
    }

    address = %Address{
      street1: "123 Main",
      city: "New York",
      region: "NY",
      country: "US",
      postal_code: "11111"
    }

iex> opts = [currency: "usd", address: address]
iex> amount = 10

iex> Gringotts.authorize(Gringotts.Gateways.Stripe, amount, card, opts)
Link to this function

capture(id, amount, opts)

View Source
@spec capture(String.t(), Gringotts.Money.t(), keyword()) :: map()

Captures a pre-authorized amount.

Amount is transferred to the merchant account by Stripe when it is smaller or equal to the amount used in the pre-authorization referenced by charge_id.

note

Note

Stripe allows partial captures and release the remaining amount back to the payment source. Thus, the same pre-authorisation charge_id cannot be used to perform multiple captures.

example

Example

The following session shows how one would (partially) capture a previously authorized a payment worth $10 by referencing the obtained charge_id.

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

iex> Gringotts.capture(Gringotts.Gateways.Stripe, id, amount, opts)
Link to this function

purchase(amount, payment, opts)

View Source
@spec purchase(Gringotts.Money.t(), Gringotts.CreditCard.t() | String.t(), keyword()) ::
  map()

Transfers amount from the customer to the merchant.

Stripe attempts to process a purchase on behalf of the customer, by debiting amount from the customer's account by charging the customer's card.

example

Example

The following session shows how one would process a payment in one-shot, without (pre) authorization.

iex> card = %CreditCard{
      first_name: "John",
      last_name: "Smith",
      number: "4242424242424242",
      year: "2017",
      month: "12",
      verification_code: "123"
    }

    address = %Address{
      street1: "123 Main",
      city: "New York",
      region: "NY",
      country: "US",
      postal_code: "11111"
    }

iex> opts = [currency: "usd", address: address]
iex> amount = 5

iex> Gringotts.purchase(Gringotts.Gateways.Stripe, amount, card, opts)
Link to this function

refund(amount, id, opts)

View Source
@spec refund(Gringotts.Money.t(), String.t(), keyword()) :: map()

Refunds the amount to the customer's card with reference to a prior transfer.

Stripe processes a full or partial refund worth amount, referencing a previous purchase/3 or capture/3.

example

Example

The following session shows how one would refund a previous purchase (and similarily for captures).

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

iex> Gringotts.refund(Gringotts.Gateways.Stripe, amount, id, opts)
@spec store(
  Gringotts.CreditCard.t() | String.t(),
  keyword()
) :: map()

Stores the payment-source data for later use.

Stripe can store the payment-source details, for example card which can be used to effectively to process One-Click and Recurring_ payments, and return a customer_id for reference.

example

Example

The following session shows how one would store a card (a payment-source) for future use.

iex> card = %CreditCard{
      first_name: "John",
      last_name: "Smith",
      number: "4242424242424242",
      year: "2017",
      month: "12",
      verification_code: "123"
    }

    address = %Address{
      street1: "123 Main",
      city: "New York",
      region: "NY",
      country: "US",
      postal_code: "11111"
    }

iex> opts = [address: address]

iex> Gringotts.store(Gringotts.Gateways.Stripe, card, opts)
@spec unstore(
  String.t(),
  keyword()
) :: map()

Deletes previously stored payment-source data.

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

examples

Examples

The following session shows how one would unstore a already stored payment source.

iex> id = "cus_BwpLX2x4ecEUgD"

iex> Gringotts.unstore(Gringotts.Gateways.Stripe, id, opts)

Catches gateway configuration errors.

Raises a run-time ArgumentError if any of the required_config values is not available or missing from the Application config.

@spec void(
  String.t(),
  keyword()
) :: map()

Voids the referenced payment.

This method attempts a reversal of the either a previous purchase/3 or authorize/3 referenced by charge_id. As a consequence, the customer will never see any booking on his statement.

voiding-a-previous-authorization

Voiding a previous authorization

Stripe will reverse the authorization by sending a "reversal request" to the payment source (card issuer) to clear the funds held against the authorization.

voiding-a-previous-purchase

Voiding a previous purchase

Stripe will reverse the payment, by sending all the amount back to the customer. Note that this is not the same as refund/3.

example

Example

The following session shows how one would void a previous (pre) authorization. Remember that our capture/3 example only did a partial capture.

iex> id = "ch_1BYvGkBImdnrXiZwet3aKkQE"
iex> opts = []

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