gringotts v1.0.2 Gringotts.Gateways.AuthorizeNet
A module for working with the Authorize.net payment gateway.
The module provides a set of functions to perform transactions via this gateway for a merchant.
The following set of functions for Authorize.Net have been provided:
| Action | Method |
|---|---|
| Authorize a Credit Card | authorize/3 |
| Capture a Previously Authorized Amount | capture/3 |
| Charge a Credit Card | purchase/3 |
| Refund a transaction | refund/3 |
| Void a Transaction | void/2 |
| Create Customer Profile | store/2 |
| Create Customer Payment Profile | store/2 |
| Delete Customer Profile | unstore/2 |
Most Gringotts API calls accept an optional Keyword list opts to supply
optional arguments for transactions with the Authorize.Net gateway. The following keys
are supported:
| Key | Remark | Status |
|---|---|---|
currency | not Implemented | |
customer | implemented | |
invoice | implemented | |
bill_to | implemented | |
ship_to | implemented | |
customer_ip | implemented | |
order | implemented | |
lineitems | implemented | |
ref_id | implemented | |
tax | implemented | |
duty | implemented | |
shipping | implemented | |
po_number | implemented | |
customer_type | implemented | |
customer_profile_id | implemented | |
profile | implemented |
To know more about these keywords visit Request and Response key sections for each function.
To use this module you need to create an account with the Authorize.Net
gateway
which will provide you with a name and a transactionKey.
Configuring your AuthorizeNet account at Gringotts
Your Application config must include the name and transaction_key
fields and would look something like this:
config :gringotts, Gringotts.Gateways.AuthorizeNet,
adapter: Gringotts.Gateways.AuthorizeNet,
name: "name_provided_by_authorize_net",
transaction_key: "transactionKey_provided_by_authorize_net"
Scope of this module, and quirks
- Although Authorize.Net supports payments from various sources, this library currently accepts payments by (supported) credit cards only.
Following the examples
First, set up a sample application and configure it to work with Authorize.Net.
- 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” above.
- Run an
iexsession withiex -S mixand add some variable bindings and aliases to it (to save some time):
iex> alias Gringotts.{Response, CreditCard, Gateways.AuthorizeNet}
Link to this section Summary
Functions
Authorize a credit card transaction
Capture a transaction
Charge a credit card
Refund amount for a settled transaction referenced by id
Store a customer payment profile
Remove a customer profile from the payment gateway
Validates the config dynamically depending on what is the value of required_config
To void a transaction
Link to this section Functions
authorize(Float, Gringotts.CreditCard.t(), Keyword.t()) :: tuple()
Authorize a credit card transaction.
Function to authorize a transaction for the specified amount. It needs to be
followed up with a capture/3 transaction to transfer the funds to merchant account.
For this transaction Authorize.Net returns a transId which can be use for:
Optional Fields
opts = [
order: %{invoice_number: String, description: String},
ref_id: String,
lineitems: %{
item_id: String, name: String, description: String,
quantity: Integer, unit_price: Float
},
tax: %{amount: Float, name: String, description: String},
duty: %{amount: String, name: String, description: String},
shipping: %{amount: String, name: String, description: String},
po_number: String,
customer: %{id: String},
bill_to: %{
first_name: String, last_name: String, company: String,
address: String, city: String, state: String, zip: String,
country: String
},
ship_to: %{
first_name: String, last_name: String, company: String, address: String,
city: String, state: String, zip: String, country: String
},
customer_ip: String
]
Example
iex> opts = [
ref_id: "123456",
order: %{invoice_number: "INV-12345", description: "Product Description"},
lineitems: %{itemId: "1", name: "vase", description: "Cannes logo", quantity: "18", unit_price: "45.00"}
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> amount = 5
iex> result = Gringotts.authorize(Gringotts.Gateways.AuthorizeNet, amount, card, opts)
Capture a transaction.
Function to capture an amount for an authorized transaction.
For this transaction Authorize.Net returns a transId which can be use to:
Quirks
If a
capturetransaction needs tovoidthen it should be done before it is settled. For AuthorieNet all the transactions are settled after 24 hours.AuthorizeNet supports partical capture of the
authorized amount. But it is advisable to use oneauthorization codeonly once.
Optional Fields
opts = [
order: %{invoice_number: String, description: String},
ref_id: String
]
Example
iex> opts = [
ref_id: "123456"
]
iex> amount = 5
iex> id = "123456"
iex> result = Gringotts.capture(Gringotts.Gateways.AuthorizeNet, id, amount, opts)
purchase(Float, Gringotts.CreditCard.t(), Keyword.t()) :: tuple()
Charge a credit card.
Function to charge a user credit card for the specified amount. It performs authorize
and capture at the same time.
For this transaction Authorize.Net returns transId which can be used to:
Optional Fields
opts = [
order: %{invoice_number: String, description: String},
ref_id: String,
lineitems: %{
item_id: String, name: String, description: String,
quantity: Integer, unit_price: Float
},
tax: %{amount: Float, name: String, description: String},
duty: %{amount: String, name: String, description: String},
shipping: %{amount: String, name: String, description: String},
po_number: String,
customer: %{id: String},
bill_to: %{
first_name: String, last_name: String, company: String,
address: String, city: String, state: String, zip: String,
country: String
},
ship_to: %{
first_name: String, last_name: String, company: String, address: String,
city: String, state: String, zip: String, country: String
},
customer_ip: String
]
Example
iex> opts = [
ref_id: "123456",
order: %{invoice_number: "INV-12345", description: "Product Description"},
lineitems: %{itemId: "1", name: "vase", description: "Cannes logo", quantity: "18", unit_price: "45.00"}
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> amount = 5
iex> result = Gringotts.purchase(Gringotts.Gateways.AuthorizeNet, amount, card, opts)
Refund amount for a settled transaction referenced by id.
Use this method to refund a customer for a transaction that was already settled, requires
transId of the transaction. The payment field in the opts is used to set the mode of payment.
The card field inside payment needs the information of the credit card to be passed in the specified fields
so as to refund to that particular card.
Required fields
opts = [
payment: %{card: %{number: String, year: Integer, month: Integer}}
]
Optional fields
opts = [ref_id: String]
Example
iex> opts = [
payment: %{card: %{number: "5424000000000015", year: 2020, month: 12}}
ref_id: "123456"
]
iex> id = "123456"
iex> amount = 5
iex> result = Gringotts.refund(Gringotts.Gateways.AuthorizeNet, amount, id, opts)
Store a customer payment profile.
Use this function to store the customer card information by creating a customer profile which also
creates a payment profile if card inofrmation is provided, and in case the customer profile exists without a payment profile, the merchant
can create customer payment profile by passing the customer_profile_id in the opts.
The gateway also provide a provision for a validation mode, there are two modes liveMode
and testMode, to know more about modes see.
Quirks
- The current version of this library supports only
credit cardas the payment profile. - If a customer profile is created without the card info, then to create a payment profile
cardinfo needs to be passed alongwithcutomer_profile_idto create it.
Required Fields
opts = [
profile: %{merchant_customer_id: String, description: String, email: String}
]
Optional Fields
opts = [
validation_mode: String,
billTo: %{
first_name: String, last_name: String, company: String, address: String,
city: String, state: String, zip: String, country: String
},
customer_type: String,
customer_profile_id: String
]
Example
iex> opts = [
profile: %{merchant_customer_id: 123456, description: "test store", email: "test@gmail.com"},
validation_mode: "testMode"
]
iex> card = %CreditCard{number: "5424000000000015", year: 2020, month: 12, verification_code: "999"}
iex> result = Gringotts.store(Gringotts.Gateways.AuthorizeNet, card, opts)
Remove a customer profile from the payment gateway.
Use this function to unstore the customer card information by deleting the customer profile present. Requires the customer profile id.
Example
iex> id = "123456"
iex> opts = []
iex> result = Gringotts.store(Gringotts.Gateways.AuthorizeNet, id, opts)
Validates the config dynamically depending on what is the value of required_config
To void a transaction
Use this method to cancel either an original transaction that is not settled or
an entire order composed of more than one transaction. It can be submitted against ‘purchase’, authorize
and capture. Requires the transId of a transaction.
Optional fields
opts = [ref_id: String]
Example
iex> opts = [
ref_id: "123456"
]
iex> id = "123456"
iex> result = Gringotts.void(Gringotts.Gateways.AuthorizeNet, id, opts)