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

PAYMILL gateway implementation.

For refernce see PAYMILL's API (v2.1) documentation.

The following features of PAYMILL are implemented:

ActionMethod
Authorizeauthorize/3
Capturecapture/3
Purchasepurchase/3
Refundrefund/3
Voidvoid/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 PAYMILL gateway. Currently, no optional params are supported.

registering-your-paymill-account-at-gringotts

Registering your PAYMILL account at Gringotts

After making an account on PAYMILL, head to the dashboard and find your account "secrets".

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

Config parameterPAYMILL secret
:private_keyPrivate Key
:public_keyPublic Key

Your Application config must include the :private_key, :public_key fields and would look something like this:

config :gringotts, Gringotts.Gateways.Paymill,
  private_key: "your_secret_private_key",
  public_key: "your_secret_public_key"

scope-of-this-module

Scope of this module

  • PAYMILL processes money in the sub-divided unit of currency (ie, in case of USD it works in cents).
  • This module does not offer direct API integration for PCI DSS compliant merchants. Hence, you can use this module even if your infrastructure (servers) are not PCI-DSS compliant!
  • To use their product, a merchant (aka user of this library) would have to use their Bridge (js integration) (or equivalent) in your application frontend to collect Credit/Debit Card data.
  • This would obtain a unique card_token at the client-side which can be used by this module for various operations like authorize/3 and purchase/3.

supported-countries

Supported countries

As a PAYMILL merchant you can accept payments from around the globe. For more details refer to Paymill country support.

supported-currencies

Supported currencies

Your transactions will be processed in your native currency. For more information refer to Paymill currency support.

following-the-examples

Following the examples

  1. First, set up a sample application and configure it to work with PAYMILL.
  • 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.
  1. 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.Paymill}
    iex> amount = Money.new(4200, :EUR)

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 authorization.

Link to this section Functions

Link to this function

authorize(amount, card_token, opts)

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

Performs a (pre) Authorize operation.

The authorization validates the card details for token 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.

The authorization token is available in the Response.id field.

example

Example

The following example shows how one would (pre) authorize a payment of €42 on a sample token.

iex> amount = Money.new(4200, :EUR)
iex> card_token = "tok_XXXXXXXXXXXXXXXXXXXXXXXXXXXX"

iex> {:ok, auth_result} = Gringotts.authorize(Gringotts.Gateways.Paymill, amount, card_token, opts)
iex> auth_result.id # This is the preauth-id
Link to this function

capture(id, amount, opts)

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

Captures a pre-authorized amount.

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

note

Note

PAYMILL allows partial captures and unlike many other gateways, and releases any remaining amount back to the payment source.

Thus, the same pre-authorisation ID cannot be used to perform multiple captures.

example

Example

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

iex> amount = Money.new(4200, :EUR)
iex> preauth_id = auth_result.id
# preauth_id = "some_authorization_id"
iex> Gringotts.capture(Gringotts.Gateways.Paymill, preauth_id, amount, opts)
Link to this function

purchase(amount, card_token, opts)

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

Transfers amount from the customer to the merchant.

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

example

Example

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

iex> amount = Money.new(4200, :EUR)
iex> token = "tok_XXXXXXXXXXXXXXXXXXXXXXXXXXXX"

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

refund(amount, id, opts)

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.

PAYMILL processes a full or partial refund worth amount, where transaction_id references a previous purchase/3 or capture/3 result.

Multiple partial refunds are allowed on the same transaction_id till all the captured/purchased amount has been refunded.

example

Example

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

iex> transaction_id = purchase_result.id
iex> amount = Money.new(4200, :EUR)
iex> Gringotts.refund(Gringotts.Gateways.Paymill, amount, transaction_id)

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.t()}

Voids the referenced authorization.

Attempts a reversal of the a previous authorize/3 referenced by preauth_id.

example

Example

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

iex> preauth_id = auth_result.id
iex> Gringotts.void(Gringotts.Gateways.Paymill, preauth_id)