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

GlobalCollect gateway implementation.

For further details, please refer GlobalCollect API documentation.

Following are the features that have been implemented for GlobalCollect:

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

optional-parameters

Optional parameters

Most Gringotts API calls accept an optional Keyword list opts to supply optional arguments for transactions with the gateway.

KeyRemark
merchantCustomerIdIdentifier for the consumer that can be used as a search criteria in the Global Collect Payment Console
descriptionDescriptive text that is used towards to consumer, either during an online checkout at a third party and/or on the statement of the consumer
dobThe date of birth of the consumer Format: YYYYMMDD
companyName of company, as a consumer
emailEmail address of the consumer
phonePhone number of the consumer
invoiceObject containing additional invoice data
billingAddressObject containing billing address details
shippingAddressObject containing shipping address details
nameObject containing the name details of the consumer
skipAuthentication3D Secure Authentication will be skipped for this transaction if set to true

For more details of the required keys refer this.

registering-your-globalcollect-account-at-gringotts

Registering your GlobalCollect account at Gringotts

After creating your account successfully on GlobalCollect open the dashboard to fetch the secret_api_key, api_key_id and merchant_id from the menu.

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

Config parameterGlobalCollect secret
:secret_api_keySecretApiKey
:api_key_idApiKeyId
:merchant_idMerchantId

Your Application config must include the :secret_api_key, :api_key_id, :merchant_id field(s) and would look something like this:

 config :gringotts, Gringotts.Gateways.GlobalCollect,
     secret_api_key: "your_secret_secret_api_key"
     api_key_id: "your_secret_api_key_id"
     merchant_id: "your_secret_merchant_id"

## Scope of this module

supported-currencies-and-countries

Supported currencies and countries

The GlobalCollect platform supports payments in over 150 currencies.

following-the-examples

Following the examples

  1. First, set up a sample application and configure it to work with GlobalCollect.

    • 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" as described above.
  2. Run an iex session with iex -S mix and add some variable bindings and aliases to it (to save some time):

    iex> alias Gringotts.{Response, CreditCard, Gateways.GlobalCollect}
    iex> shippingAddress = %{
    street: "Desertroad",
    houseNumber: "1",
    additionalInfo: "Suite II",
    zip: "84536",
    city: "Monument Valley",
    state: "Utah",
    countryCode: "US"
    }
    
    iex> billingAddress = %{
    street: "Desertroad",
    houseNumber: "13",
    additionalInfo: "b",
    zip: "84536",
    city: "Monument Valley",
    state: "Utah",
    countryCode: "US"
    }
    
    iex> invoice = %{
    invoiceNumber: "000000123",
    invoiceDate: "20140306191500"
    }
    
    iex> name = %{
    title: "Miss",
    firstName: "Road",
    surname: "Runner"
    }
    
    iex> card = %CreditCard{
    number: "4567350000427977",
    month: 12,
    year: 43,
    first_name: "John",
    last_name: "Doe",
    verification_code: "123",
    brand: "VISA"
    }
    
    iex> opts = [
    description: "Store Purchase 1437598192",
    merchantCustomerId: "234", dob: "19490917",
    company: "asma", email: "johndoe@gmail.com",
    phone: "7765746563", invoice: invoice,
    billingAddress: billingAddress,
    shippingAddress: shippingAddress,
    name: name, skipAuthentication: "true"
    ]

We'll be using these 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 account with reference to a prior transfer.

Catches gateway configuration errors.

Voids the referenced payment.

Link to this section Functions

Link to this function

authorize(amount, card, 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.

GlobalCollect returns a payment id which can be further used to:

example

Example

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

iex> card = %CreditCard{
    number: "4567350000427977",
    month: 12,
    year: 43,
    first_name: "John",
    last_name: "Doe",
    verification_code: "123",
    brand: "VISA"
}

iex> amount = Money.new(100, :USD)

iex> {:ok, auth_result} = Gringotts.authorize(Gringotts.Gateways.GlobalCollect, amount, card, opts)
Link to this function

capture(payment_id, amount, opts)

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

Captures a pre-authorized amount.

amount used in the pre-authorization referenced by payment_id is transferred to the merchant account by GlobalCollect.

note

Note

Authorized payment with PENDING_APPROVAL status only allow a single capture whereas the one with PENDING_CAPTURE status is used for payments that allow multiple captures.

example

Example

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

iex> amount = Money.new(100, :USD)

iex> {:ok, capture_result} = Gringotts.capture(Gringotts.Gateways.GlobalCollect, auth_result.authorization, amount, opts)
Link to this function

purchase(amount, card, opts)

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

Transfers amount from the customer to the merchant.

GlobalCollect 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 example shows how one would process a payment in one-shot, without (pre) authorization.

iex> card = %CreditCard{
    number: "4567350000427977",
    month: 12,
    year: 43,
    first_name: "John",
    last_name: "Doe",
    verification_code: "123",
    brand: "VISA"
  }

iex> amount = Money.new(100, :USD)

iex> {:ok, purchase_result} = Gringotts.purchase(Gringotts.Gateways.GlobalCollect, amount, card, opts)
Link to this function

refund(amount, payment_id, opts)

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

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

You always have the option to refund just a portion of the payment amount. It is also possible to submit multiple refund requests on one payment as long as the total amount to be refunded does not exceed the total amount that was paid.

example

Example

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

iex> amount = Money.new(100, :USD)

iex> {:ok, refund_result} = Gringotts.refund(Gringotts.Gateways.GlobalCollect, auth_result.authorization, amount)

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()
) :: {:ok | :error, Gringotts.Response}

Voids the referenced payment.

This makes it impossible to process the payment any further and will also try to reverse an authorization on a card. Reversing an authorization that you will not be utilizing will prevent you from having to pay a fee/penalty for unused authorization requests.

example

Example

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

iex> {:ok, void_result} = Gringotts.void(Gringotts.Gateways.GlobalCollect, auth_result.authorization, opts)