View Source Gringotts.Gateways.Openpay (gringotts v1.1.1)
openpay gateway implementation. For reference see openpay documentation. The following features of openpay are implemented:
Action | Method |
---|---|
Pre-authorize | authorize/3 |
Capture | capture/3 |
Purchase | purchase/3 |
Reversal | void/2 |
Refund | refund/3 |
the-opts-argument
The opts
argument
Most Gringotts
API calls accept an optional keyword
list opts
to supply
optional arguments for transactions with the mercadopago
gateway. The following keys are supported:
Key | Remark |
---|---|
email | Email of the customer. Type - string |
device_session_id | Identifier of the device generated by the antifraud tool. Type- string |
method | It must contain the card value in order to specify the charge will be made from card. Type- string |
address | Address of the card owner. Type object |
phone_number | Customer phone number. Type- integer |
registering-your-openpay-account-at-gringotts
Registering your openpay account at Gringotts
After making an account on openpay, find
your account "secrets" in the home page
Here's how the secrets map to the required configuration parameters for openpay:
Config parameter openpay secret :merchant_id
MerchantId :public_key
PublicKey
Your Application config must include the
[:merchant_id, :public_key]
field(s) and would look something like this:config :gringotts, Gringotts.Gateways.Openpay, merchant_id: "your_secret_merchant_id" public_key: "your_secret_public_key"
note
Note
mercadopago processes money with upto two decimal places.
supported-currencies-and-countries
Supported currencies and countries
openpay support mexico country and :MXN currency.
following-the-examples
Following the examples
- First, set up a sample application and configure it to work with openpay.
- 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.
- To save you time, we recommend cloning our example
repo that gives you a pre-configured sample app ready-to-go.
- Run an
iex
session withiex -S mix
and add some variable bindings and aliases to it (to save some time):
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
@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.
openpay returns an ID string which can be used to:
example
Example
The following example shows how one would (pre) authorize a payment of $42 on
a sample card
.
iex> amount = Money.new(42, :MXN)
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.Openpay, amount, card, opts)
iex> auth_result.id # This is the authorization ID
@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 openpay when it is smaller or
equal to the amount used in the pre-authorization referenced by payment_id
.
note
Note
openpay 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
.
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, :MXN)
iex> {:ok, capture_result} = Gringotts.capture(Gringotts.Gateways.Openpay, amount, auth_result.id, opts)
@spec purchase(Gringotts.Money.t(), Gringotts.CreditCard.t(), keyword()) :: {:ok | :error, Gringotts.Response}
Transfers amount
from the customer to the merchant.
openpay 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 worth $42 in one-shot, without (pre) authorization.
iex> amount = Money.new(42, :MXN)
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.Openpay, amount, card, opts)
@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.
openpay processes a full or partial refund worth amount
, referencing a
previous purchase/3
or capture/3
.
example
Example
The following example shows how one would (completely) refund a previous purchase (and similarily for captures).
iex> amount = Money.new(42, :MXN)
iex> {:ok, refund_result} = Gringotts.refund(Gringotts.Gateways.Openpay, purchase_result.id, 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.
Voids the referenced payment.
This method attempts a reversal of a previous transaction referenced by
payment_id
.
As a consequence, the customer will never see any booking on his statement.
note
Note
Only pending or in_process payments can be cancelled. Cancelled coupon payments, deposits and/or transfers will be deposited in the buyer’s Openpay account.
example
Example
The following example shows how one would void
iex> {:ok, void_result} = Gringotts.void(Gringotts.Gateways.Openpay, auth_result.id, opts)