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

Trexle Payment Gateway implementation.

For further details, please refer Trexle API documentation.

Following are the features that have been implemented for the Trexle Gateway:

ActionMethod
Authorizeauthorize/3
Purchasepurchase/3
Capturecapture/3
Refundrefund/3
Storestore/2

pci-compliance-is-mandatory

PCI compliance is mandatory!

You, the merchant needs to be PCI-DSS Compliant if you wish to use this module! Your server will recieve sensitive card and customer information.

the-opts-argument

The opts argument

Most Gringotts API calls accept an optional keyword list opts to supply optional arguments for transactions with Trexle. The following keys are supported:

  • email
  • ip_address
  • description

registering-your-trexle-account-at-gringotts

Registering your Trexle account at Gringotts

After creating your account successfully on Trexle, head to the dashboard and find your account "secrets" in the API keys section.

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

Config parameterTrexle secret
:api_keyAPI key

Your Application config must look something like this:

config :gringotts, Gringotts.Gateways.Trexle,
    api_key: "your-secret-API-key"

scope-of-this-module

Scope of this module

  • Trexle processes money in cents.citation-needed.

supported-gateways

Supported Gateways

Find the official list here.

following-the-examples

Following the examples

  1. First, set up a sample application and configure it to work with Trexle.
  • You could do that from scratch by following our Getting Started guide.
    • To save you time, we recommend cloning our example repo that gives you a pre-configured sample app ready-to-go.
      • You could use the same config or update it the with your "secrets" that as described above.
  1. To save a lot of time, create a .iex.exs file as shown in this gist to introduce a set of handy bindings and aliases.

We'll be using these bindings in the examples below.

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 card information for future use.

Catches gateway configuration errors.

Link to this section Functions

Link to this function

authorize(amount, payment, opts)

View Source
@spec authorize(Gringotts.Money.t(), Gringotts.CreditCard.t(), keyword()) ::
  {:ok | :error, Gringotts.Response}

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.

Trexle returns a "charge token", avaliable in the Response.id field, which can be used in future to perform a capture/3.

example

Example

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

iex> amount = Money.new(100, :USD)
iex> card = %CreditCard{
             first_name: "Harry",
             last_name: "Potter",
             number: "5200828282828210",
             year: 2099, month: 12,
             verification_code: "123",
             brand: "VISA"}
iex> address = %Address{
                street1: "301, Gryffindor",
                street2: "Hogwarts School of Witchcraft and Wizardry, Hogwarts Castle",
                city: "Highlands",
                region: "SL",
                country: "GB",
                postal_code: "11111",
                phone: "(555)555-5555"}
iex> options = [email: "masterofdeath@ministryofmagic.gov",
                ip_address: "127.0.0.1",
                billing_address: address,
                description: "For our valued customer, Mr. Potter"]
iex> Gringotts.authorize(Gringotts.Gateways.Trexle, amount, card, options)
Link to this function

capture(charge_token, amount, opts)

View Source
@spec capture(String.t(), Gringotts.Money.t(), keyword()) ::
  {:ok | :error, Gringotts.Response}

Captures a pre-authorized amount.

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

Trexle returns a "charge token", avaliable in the Response.id field, which can be used in future to perform a refund/2.

note

Note

Multiple captures cannot be performed on the same "charge token". If the captured amount is smaller than the (pre) authorized amount, the "un-captured" amount is released.citation-needed

example

Example

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

iex> amount = Money.new(10, :USD)
iex> token = "some-real-token"
iex> Gringotts.capture(Gringotts.Gateways.Trexle, token, amount)
Link to this function

purchase(amount, payment, opts)

View Source
@spec purchase(Gringotts.Money.t(), Gringotts.CreditCard.t(), keyword()) ::
  {:ok | :error, Gringotts.Response}

Transfers amount from the customer to the merchant.

Trexle 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 worth $100 in one-shot, without (pre) authorization.

iex> amount = Money.new(100, :USD)
iex> card = %CreditCard{
             first_name: "Harry",
             last_name: "Potter",
             number: "5200828282828210",
             year: 2099, month: 12,
             verification_code: "123",
             brand: "VISA"}
iex> address = %Address{
                street1: "301, Gryffindor",
                street2: "Hogwarts School of Witchcraft and Wizardry, Hogwarts Castle",
                city: "Highlands",
                region: "SL",
                country: "GB",
                postal_code: "11111",
                phone: "(555)555-5555"}
iex> options = [email: "masterofdeath@ministryofmagic.gov",
                ip_address: "127.0.0.1",
                billing_address: address,
                description: "For our valued customer, Mr. Potter"]
iex> Gringotts.purchase(Gringotts.Gateways.Trexle, amount, card, options)
Link to this function

refund(amount, charge_token, opts)

View Source
@spec refund(Gringotts.Money.t(), String.t(), keyword()) ::
  {:ok | :error, Gringotts.Response}

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

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

Trexle returns a "refund token", avaliable in the Response.id field.

Multiple, partial refunds can be performed on the same "charge token" referencing a previous purchase/3 or capture/3 till the cumulative refunds equals the capture/3d or purchase/3d amount.

example

Example

The following session shows how one would refund $100 of a previous purchase/3 (and similarily for capture/3s).

iex> amount = Money.new(100, :USD)
iex> token = "some-real-token"
iex> Gringotts.refund(Gringotts.Gateways.Trexle, amount, token)
@spec store(
  Gringotts.CreditCard.t(),
  keyword()
) :: {:ok | :error, Gringotts.Response}

Stores the card information for future use.

example

Example

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

iex> card = %CreditCard{
             first_name: "Harry",
             last_name: "Potter",
             number: "5200828282828210",
             year: 2099, month: 12,
             verification_code: "123",
             brand: "VISA"}
iex> address = %Address{
                street1: "301, Gryffindor",
                street2: "Hogwarts School of Witchcraft and Wizardry, Hogwarts Castle",
                city: "Highlands",
                region: "SL",
                country: "GB",
                postal_code: "11111",
                phone: "(555)555-5555"}
iex> options = [email: "masterofdeath@ministryofmagic.gov",
                ip_address: "127.0.0.1",
                billing_address: address,
                description: "For our valued customer, Mr. Potter"]
iex> Gringotts.store(Gringotts.Gateways.Trexle, card, options)

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.