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

CAMS gateway implementation.

CAMS provides a sandbox account with documentation under the integration tab. The login credentials are:

KeyCredentials
usernametestintegrationc
passwordpassword9

The video tutorials (on vimeo) are excellent.

The following features of CAMS are implemented:

ActionMethod
Authorizeauthorize/3
Capturecapture/3
Purchasepurchase/3
Refundrefund/3
Cancelvoid/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 CAMS gateway. The following keys are supported:

KeyTypeRemark
billing_addressmapThe address of the customer
order_idString.tMerchant provided identifier
descriptionString.tMerchant provided description of the transaction

CAMS supports more optional keys and you can raise an issue if this is important to you.

schema

Schema

  • billing_address is a map from atoms to String.t, and can include any of the keys from: :name, :address1, :address2, :company, :city, :state, :zip, :country, :phone, :fax]

registering-your-cams-account-at-gringotts

Registering your CAMS account at Gringotts

Config parameterCAMS secret
:usernameUsername
:passwordPassword

Your Application config must include the :username, :password fields and would look something like this:

config :gringotts, Gringotts.Gateways.Cams,
    username: "your_secret_user_name",
    password: "your_secret_password",

scope-of-this-module

Scope of this module

  • CAMS does not process money in cents.
  • Although CAMS supports payments from electronic check & various cards this module only accepts payments via VISA, MASTER, AMERICAN EXPRESS and DISCOVER.

supported-countries

Supported countries

citation-needed

supported-currencies

Supported currencies

citation-needed

following-the-examples

Following the examples

  1. First, set up a sample application and configure it to work with CAMS.
  • You could do that from scratch by following our Getting Started guide.
  • To save you time, we recommend cloning our example 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 you get after registering with CAMS.
  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.

integrating-with-phoenix

Integrating with phoenix

Refer the GringottsPay website for an example of how to integrate CAMS with phoenix. The source is available here.

todo

TODO

  • Operations using Credit Card

    • Credit
  • Operations using electronic checks

    • Sale
    • Void
    • Refund

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 account with reference to a prior transfer.

Validates the card

Catches gateway configuration errors.

Voids the referenced payment.

Link to this section Functions

Link to this function

authorize(money, card, options)

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

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.

When followed up with a capture/3 transaction, funds will be transferred to the merchant's account upon settlement.

CAMS returns a Transaction ID (available in the Response.authorization field) which can be used later to:

optional-fields

Optional Fields

options[
  order_id: String,
  description: String
]

examples

Examples

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

iex> card = %CreditCard{first_name: "Harry",
                        last_name: "Potter",
                        number: "4111111111111111",
                        year: 2099,
                        month: 12,
                        verification_code: "999",
                        brand: "VISA"}
iex> money = Money.new(20, :USD)
iex> {:ok, auth_result} = Gringotts.authorize(Gringotts.Gateways.Cams, money, card)
Link to this function

capture(money, transaction_id, options)

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

Captures a pre-authorized amount.

Captures can be submitted for an amount equal to or less than the originally authorized amount in an authorize/3ation referenced by transaction_id.

Partial captures are allowed, and the remaining amount is released back to the payment source (video).

Multiple, partial captures on the same authorization token are not supported.

CAMS returns a Transaction ID (available in the Response.authorization field) which can be used later to:

examples

Examples

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

iex> card = %CreditCard{first_name: "Harry",
                        last_name: "Potter",
                        number: "4111111111111111",
                        year: 2099,
                        month: 12,
                        verification_code: "999",
                        brand: "VISA"}
iex> money = Money.new(10, :USD)
iex> authorization = auth_result.authorization
# authorization = "some_authorization_transaction_id"
iex> {:ok, capture_result} = Gringotts.capture(Gringotts.Gateways.Cams, money, authorization)
Link to this function

purchase(money, card, options)

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

Transfers amount from the customer to the merchant.

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

Returns a Transaction ID (available in the Response.authorization field) which can be used later to:

examples

Examples

The following example shows how one would process a payment worth $20 in one-shot, without (pre) authorization.

iex> card = %CreditCard{first_name: "Harry",
                        last_name: "Potter",
                        number: "4111111111111111",
                        year: 2099,
                        month: 12,
                        verification_code: "999",
                        brand: "VISA"}
iex> money = Money.new(20, :USD)
iex> Gringotts.purchase(Gringotts.Gateways.Cams, money, card)
Link to this function

refund(money, transaction_id, options)

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

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

It's better to void/2 a transaction if it has not been settled yet! Refunds lead to to two entries on the customer's bank statement, one for the original purchase/3 or capture/3 and another for the refund/3.

Multiple, partial refunds on the same Transaction ID are allowed till all the captured amount is refunded.

examples

Examples

The following example shows how one would completely refund a previous capture (and similarily for purchases).

iex> capture_id = capture_result.authorization
# capture_id = "some_capture_transaction_id"
iex> money = Money.new(20, :USD)
iex> Gringotts.refund(Gringotts.Gateways.Cams, money, capture_id)
@spec validate(
  Gringotts.CreditCard.t(),
  keyword()
) :: {:ok | :error, Gringotts.Response.t()}

Validates the card

Verifies the credit card without authorizing any amount.

examples

Examples

iex> card = %CreditCard{first_name: "Harry",
                        last_name: "Potter",
                        number: "4111111111111111",
                        year: 2099,
                        month: 12,
                        verification_code: "999",
                        brand: "VISA"}
iex> Gringotts.validate(Gringotts.Gateways.Cams, card)

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.

Link to this function

void(transaction_id, options)

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

Voids the referenced payment.

Cancel a transaction referenced by transaction_id that is not settled yet. This will erase any entries from the customer's bank statement.

authorize/3 can be void/2ed to prevent captures.

examples

Examples

The following example shows how one would void a previous (pre) authorization.

iex> auth_id = auth_result.id
# auth_id = "aome_authorisation_transaction_id"
iex> Gringotts.void(Gringotts.Gateways.Cams, auth_id)