View Source Gringotts.Gateways.Monei (gringotts v1.1.1)
MONEI gateway implementation.
For reference see MONEI's API (v1) documentation.
The following features of MONEI are implemented:
Action | Method | type |
---|---|---|
Pre-authorize | authorize/3 | PA |
Capture | capture/3 | CP |
Refund | refund/3 | RF |
Reversal | void/2 | RV |
Debit | purchase/3 | DB |
Tokenization / Registrations | store/2 |
What's this last column
type
?That's the
paymentType
of the request, which you can ignore unless you'd like to contribute to this module. Please read the MONEI Guides.
the-opts-argument
The opts
argument
Most Gringotts
API calls accept an optional keyword
list opts
to supply
optional arguments for transactions with the MONEI
gateway. The following keys are supported:
Key | Remark |
---|---|
billing | Address of the customer, which can be used for AVS risk check. |
cart | Not Implemented |
custom | It's a map of "name"-"value" pairs, and all of it is echoed back in the response. |
customer | Annotate transactions with customer info on your Monei account, and helps in risk management. |
invoice_id | Merchant provided invoice identifier, must be unique per transaction with Monei. |
transaction_id | Merchant provided token for a transaction, must be unique per transaction with Monei. |
category | The category of the transaction. |
merchant | Information about the merchant, which overrides the cardholder's bank statement. |
register | Also store payment data included in this request for future use. |
shipping | Location of recipient of goods, for logistics. |
shipping_customer | Recipient details, could be different from customer . |
registering-your-monei-account-at-gringotts
Registering your MONEI account at Gringotts
After making an account on MONEI, head to the dashboard and find
your account "secrets" in the Sub-Accounts > Overview
section.
Here's how the secrets map to the required configuration parameters for MONEI:
Config parameter | MONEI secret |
---|---|
:userId | User ID |
:entityId | Channel ID |
:password | Password |
Your Application config must include the :userId
, :entityId
, :password
fields and would look something like this:
config :gringotts, Gringotts.Gateways.Monei,
userId: "your_secret_user_id",
password: "your_secret_password",
entityId: "your_secret_channel_id"
scope-of-this-module
Scope of this module
- 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.
- MONEI does not process money in cents, and the
amount
is rounded to 2 decimal places. - Although MONEI supports payments from various cards, banks and virtual accounts (like some wallets), this library only accepts payments by (supported) cards.
supported-countries
Supported countries
MONEI supports the countries listed here
supported-currencies
Supported currencies
MONEI supports the currecncies listed here, and this module supports a subset of those:
:AED, :AFN, :ANG, :AOA, :AWG, :AZN, :BAM, :BGN, :BRL, :BYN, :CDF, :CHF, :CUC,
:EGP, :EUR, :GBP, :GEL, :GHS, :MDL, :MGA, :MKD, :MWK, :MZN, :NAD, :NGN, :NIO,
:NOK, :NPR, :NZD, :PAB, :PEN, :PGK, :PHP, :PKR, :PLN, :PYG, :QAR, :RSD, :RUB,
:RWF, :SAR, :SCR, :SDG, :SEK, :SGD, :SHP, :SLL, :SOS, :SRD, :STD, :SYP, :SZL,
:THB, :TJS, :TOP, :TRY, :TTD, :TWD, :TZS, :UAH, :UGX, :USD, :UYU, :UZS, :VND,
:VUV, :WST, :XAF, :XCD, :XOF, :XPF, :YER, :ZAR, :ZMW, :ZWL
Please raise an issue if you'd like us to add support for more currencies
following-the-examples
Following the examples
First, set up a sample application and configure it to work with MONEI.
- 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 you see in
Dashboard > Sub-accounts
as described above.
- You could use the same config or update it the with your "secrets"
that you see in
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.
todo
TODO
- Backoffice operations
- Credit
- Rebill
- Recurring payments
- Reporting
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.
Stores the payment-source data for later use.
Catches gateway configuration errors.
Voids the referenced payment.
Link to this section Functions
@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.
MONEI returns an ID string which can be used to:
note
Note
- The
:register
option when set totrue
will store this card for future use, and you will recieve a registrationtoken
in the:token
field of theResponse
struct. - A stand-alone pre-authorization expires in 72hrs.
example
Example
The following example shows how one would (pre) authorize a payment of $42 on
a sample card
.
iex> amount = Money.new(42, :USD)
iex> card = %Gringotts.CreditCard{first_name: "Harry", last_name: "Potter", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> {:ok, auth_result} = Gringotts.authorize(Gringotts.Gateways.Monei, amount, card, opts)
iex> auth_result.id # This is the authorization ID
iex> auth_result.token # This is the registration ID/token
@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 MONEI when it is smaller or
equal to the amount used in the pre-authorization referenced by payment_id
.
note
Note
MONEI allows partial captures and unlike many other gateways, does not release the remaining amount back to the payment source. Thus, the same pre-authorisation ID can be used to perform multiple captures, till:
- all the pre-authorized amount is captured or,
- the remaining amount is explicitly "reversed" via
void/2
. [citation-needed]
example
Example
The following example shows how one would (partially) capture a previously
authorized a payment worth $35 by referencing the obtained authorization id
.
iex> amount = Money.new(35, :USD)
iex> {:ok, capture_result} = Gringotts.capture(Gringotts.Gateways.Monei, amount, auth_result.id, opts)
@spec purchase(Gringotts.Money.t(), Gringotts.CreditCard.t(), keyword()) :: {:ok | :error, Gringotts.Response.t()}
Transfers amount
from the customer to the merchant.
MONEI attempts to process a purchase on behalf of the customer, by debiting
amount
from the customer's account by charging the customer's card
.
note
Note
- The
:register
option when set totrue
will store this card for future use, and you will recieve a registrationtoken
in the:token
field of theResponse
struct.
example
Example
The following example shows how one would process a payment worth $42 in one-shot, without (pre) authorization.
iex> amount = Money.new(42, :USD)
iex> card = %Gringotts.CreditCard{first_name: "Harry", last_name: "Potter", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> {:ok, purchase_result} = Gringotts.purchase(Gringotts.Gateways.Monei, amount, card, opts)
iex> purchase_result.token # This is the registration ID/token
@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.
MONEI processes a full or partial refund worth amount
, referencing a
previous purchase/3
or capture/3
.
The end customer will always see two bookings/records on his statement. Refer MONEI's Backoffice Operations guide.
example
Example
The following example shows how one would (completely) refund a previous purchase (and similarily for captures).
iex> amount = Money.new(42, :USD)
iex> {:ok, refund_result} = Gringotts.refund(Gringotts.Gateways.Monei, purchase_result.id, amount)
@spec store( Gringotts.CreditCard.t(), keyword() ) :: {:ok | :error, Gringotts.Response.t()}
Stores the payment-source data for later use.
MONEI can store the payment-source details, for example card or bank details which can be used to effectively process One-Click and Recurring payments, and return a registration token for reference.
The registration token is available in the Response.id
field.
It is recommended to associate these details with a "Customer" by passing
customer details in the opts
.
note
Note
- One-Click and Recurring payments are currently not implemented.
- Payment details can be saved during a
purchase/3
orcapture/3
.
example
Example
The following example shows how one would store a card (a payment-source) for future use.
iex> card = %Gringotts.CreditCard{first_name: "Harry", last_name: "Potter", number: "4200000000000000", year: 2099, month: 12, verification_code: "123", brand: "VISA"}
iex> {:ok, store_result} = Gringotts.store(Gringotts.Gateways.Monei, card)
iex> store_result.id # This is the registration token
@spec unstore( String.t(), keyword() ) :: {:ok | :error, Gringotts.Response.t()}
WIP
MONEI unstore does not seem to work. MONEI always returns a 403
Deletes previously stored payment-source data.
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 payment.
This method attempts a reversal of the either a previous purchase/3
,
capture/3
or authorize/3
referenced by payment_id
.
As a consequence, the customer will never see any booking on his statement. Refer MONEI's Backoffice Operations guide.
voiding-a-previous-authorization
Voiding a previous authorization
MONEI will reverse the authorization by sending a "reversal request" to the payment source (card issuer) to clear the funds held against the authorization. If some of the authorized amount was captured, only the remaining amount is cleared. [citation-needed]
voiding-a-previous-purchase
Voiding a previous purchase
MONEI 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 example shows how one would void a previous (pre)
authorization. Remember that our capture/3
example only did a partial
capture.
iex> {:ok, void_result} = Gringotts.void(Gringotts.Gateways.Monei, auth_result.id, opts)