{"id":13509482,"url":"https://github.com/marcelog/elixir_authorizenet","last_synced_at":"2025-03-21T02:31:50.129Z","repository":{"id":34097297,"uuid":"37922757","full_name":"marcelog/elixir_authorizenet","owner":"marcelog","description":"Unofficial Elixir Client for the Authorize.NET API","archived":false,"fork":false,"pushed_at":"2021-02-14T07:39:54.000Z","size":122,"stargazers_count":11,"open_issues_count":4,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T19:52:27.211Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcelog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-23T14:08:31.000Z","updated_at":"2024-07-16T05:43:22.000Z","dependencies_parsed_at":"2022-07-29T19:40:05.165Z","dependency_job_id":null,"html_url":"https://github.com/marcelog/elixir_authorizenet","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Felixir_authorizenet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Felixir_authorizenet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Felixir_authorizenet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcelog%2Felixir_authorizenet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcelog","download_url":"https://codeload.github.com/marcelog/elixir_authorizenet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244725559,"owners_count":20499629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:01:08.427Z","updated_at":"2025-03-21T02:31:49.847Z","avatar_url":"https://github.com/marcelog.png","language":"Elixir","funding_links":[],"categories":["Third Party APIs"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/marcelog/elixir_authorizenet.svg)](https://travis-ci.org/marcelog/elixir_authorizenet)\n[![Deps Status](https://beta.hexfaktor.org/badge/all/github/marcelog/elixir_authorizenet.svg)](https://beta.hexfaktor.org/github/marcelog/elixir_authorizenet)\n\n# elixir_authorizenet\n\nElixir client for the [Authorize.Net merchant API](http://developer.authorize.net/api/reference/index.html). This\nshould help you integrate using the [AIM](http://developer.authorize.net/api/aim/).\n\nA nice number of features are implemented (probably most of the ones used\non a daily basis are already there), but since the API offers a big number of\nfeatures and combinations, I still consider this as WIP, and pull requests,\nsuggestions, or other kind of feedback are very welcome!\n\n# Using it with Mix\n\nTo use it in your Mix projects, first add it as a dependency:\n\n```elixir\ndef deps do\n  [{:elixir_authorizenet, \"~\u003e 0.3.0\"}]\nend\n```\nThen run mix deps.get to install it.\n\n----\n\n# Configuring\nIn your config.exs, setup the following section:\n\n```elixir\nconfig :elixir_authorizenet,\n  environment: :sandbox,  # :sandbox or :production\n  validation_mode: :test, # :test, :live, or :none\n  login_id: \"login_id\",\n  transaction_key: \"transaction_key\"\n```\n\n----\n\n# Documentation\n\nWhat follows is just a glance, a quick overview of the common used features.\nFeel free to take a look at the [documentation](http://hexdocs.pm/elixir_authorizenet/)\nserved by hex.pm or the source itself to find more.\n\n## Customer Profiles\nThese are used when you want to store information in the Authorize.Net servers,\nlike credit card or bank account information, and also billing and shipping\naddresses. This effectively is the interface to the [CIM](http://developer.authorize.net/api/cim/).\n\nCustomer Profiles are used via the [Customer](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/customer.ex) module.\n\n```elixir\nalias AuthorizeNet.Customer, as: C\n```\n\n### Creating\n```elixir\n  \u003e C.create \"merchantId\", \"description\", \"email@host.com\"\n  %AuthorizeNet.Customer{description: \"description\", email: \"email@host.com\",\n   id: \"merchantId\", payment_profiles: [], profile_id: 35962612,\n   shipping_addresses: []}\n```\n\n### Updating\n```elixir\n  \u003e C.update 35962612, \"merchantId\", \"description\", \"email2@host.com\"\n  %AuthorizeNet.Customer{description: \"description\", email: \"email2@host.com\",\n   id: \"merchantId\", payment_profiles: [], profile_id: 35962612,\n   shipping_addresses: []}\n```\n\n### Get all IDs\n```elixir\n  \u003e C.get_all\n  [35962612]\n```\n\n### Get Customer Profile\n```elixir\n  \u003e C.get 35962612\n  %AuthorizeNet.Customer{description: \"description\", email: \"email2@host.com\",\n   id: \"merchantId\", payment_profiles: [], profile_id: 35962612,\n   shipping_addresses: []}\n```\n\n### Deleting\n```elixir\n  \u003e C.delete 35962612\n  :ok\n```\n\n----\n\n## Addresses\nTo handle billing and shipping addresses, use the [Address](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/address.ex)\nmodule.\n```elixir\nalias AuthorizeNet.Address, as: A\n\naddress = A.new(\n  \"first_name\",\n  \"last_name\",\n  \"company\",\n  \"street\",\n  \"city\",\n  \"state\",\n  \"zip\",\n  \"country\",\n  \"phone\",\n  \"fax\"\n)\n%AuthorizeNet.Address{address: \"street\", city: \"city\", company: \"company\",\n country: \"country\", customer_id: nil, fax: \"fax\", first_name: \"first_name\",\n id: nil, last_name: \"last_name\", phone: \"phone\", state: \"state\", zip: \"zip\"}\n```\n\n----\n## Shipping Addresses\nYou can do some CRUD with shipping addresses in a customer profile.\n\n### Creating\n```elixir\n  \u003e C.create_shipping_address 35962612, address\n  %AuthorizeNet.Address{address: \"street\", city: \"city\", company: \"company\",\n   country: \"country\", customer_id: 35962612, fax: \"fax\",\n   first_name: \"first_name\", id: 34066037, last_name: \"last_name\", phone: \"phone\",\n   state: \"state\", zip: \"zip\"}\n```\n\n### Getting\n```elixir\n  \u003e C.get_shipping_address 35962612, 34066037\n  %AuthorizeNet.Address{address: \"street\", city: \"city\", company: \"company\",\n   country: \"country\", customer_id: 35962612, fax: \"fax\",\n   first_name: \"first_name\", id: 34066037, last_name: \"last_name\", phone: \"phone\",\n   state: \"state\", zip: \"zip\"}\n```\n\n### Updating\nMake sure you have an `AuthorizeNet.Address` struct with customer_id and id already filled in\n(for example by getting it from the server). Then:\n\n```elixir\n  \u003e C.update_shipping_address address\n  %AuthorizeNet.Address{address: \"street\", city: \"city\", company: \"company\",\n   country: \"country\", customer_id: 35962612, fax: \"fax\",\n   first_name: \"first_name\", id: 34066235, last_name: \"last_name\", phone: \"phone\",\n   state: \"state\", zip: \"zip2\"}\n```\n\n### Deleting\n```elixir\n  \u003e C.delete_shipping_address 35962612, 34066037\n  :ok\n```\n----\n\n## Customer Payment Profiles\n\nPayment profiles are handled in the [PaymentProfile](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/payment_profile.ex)\nmodule. With a PaymentProfile you can declare credit cards and bank accounts and\nsave them into a customer profile. Bank accounts are handled by the module [BankAccount](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/bank_account.ex)\nwhile credit cards are handled by the module [Card](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/card.ex).\n\n```elixir\nalias AuthorizeNet.PaymentProfile, as: P\nalias AuthorizeNet.BankAccount, as: BankAccount\nalias AuthorizeNet.Card, as: Card\n```\n\nAnd can be created with the functions:\n\n * **AuthorizeNet.PaymentProfile.create_business**: To create a \"business\" associated payment profile.\n * **AuthorizeNet.PaymentProfile.create_individual**: To create a payment profile for an individual, not associated to a business.\n\n### Creating a Credit Card\n```elixir\n  \u003e card = Card.new \"5424000000000015\", \"2015-08\", \"900\"\n  %AuthorizeNet.Card{code: \"900\", expiration_date: \"2015-08\",\n   number: \"5424000000000015\"}\n\n  \u003e P.create_individual 35962612, address, card\n  %AuthorizeNet.PaymentProfile{address: %AuthorizeNet.Address{address: \"street\",\n    city: \"city\", company: \"company\", country: \"country\", customer_id: nil,\n    fax: \"fax\", first_name: \"first_name\", id: nil, last_name: \"last_name\",\n    phone: \"phone\", state: \"state\", zip: \"zip\"}, customer_id: 35962612,\n   payment_type: %AuthorizeNet.Card{code: \"900\", expiration_date: \"2015-08\",\n    number: \"5424000000000015\"}, profile_id: 32510145, type: :individual}\n```\n\n### Creating a bank account\nBank accounts can be created via 3 functions:\n\n * **AuthorizeNet.BankAccount.savings**: A savings account.\n * **AuthorizeNet.BankAccount.checking**: A checking account.\n * **AuthorizeNet.BankAccount.business_checking**: A business checking account.\n\n```elixir\n  \u003e account = BankAccount.savings \"bank_name\", \"routing_number\", \"account_number\", \"name_on_account\", :ccd\n  %AuthorizeNet.BankAccount{account_number: \"account_number\",\n   bank_name: \"bank_name\", echeck_type: :ccd, name_on_account: \"name_on_account\",\n   routing_number: \"routing_number\", type: :savings}\n\n  \u003e P.create_individual 35962612, address, account\n  %AuthorizeNet.PaymentProfile{address: %AuthorizeNet.Address{address: \"street\",\n    city: \"city\", company: \"company\", country: \"country\", customer_id: nil,\n    fax: \"fax\", first_name: \"first_name\", id: nil, last_name: \"last_name\",\n    phone: \"phone\", state: \"state\", zip: \"zip\"}, customer_id: 35962612,\n   payment_type: %AuthorizeNet.BankAccount{account_number: \"account_number\",\n    bank_name: \"bank_name\", echeck_type: :web, name_on_account: \"name_on_account\",\n    routing_number: \"routing_number\", type: :savings}, profile_id: 32510152,\n   type: :individual}\n```\n\nThe last argument is the type of [echeck](https://www.authorize.net/support/CNP/helpfiles/Miscellaneous/Pop-up_Terms/ALL/eCheck.Net_Type.htm).\n\n### Getting a payment profile\n```elixir\n  \u003e P.get 35962612, 32510152\n  %AuthorizeNet.PaymentProfile{address: %AuthorizeNet.Address{address: \"street\",\n    city: \"city\", company: \"company\", country: \"country\", customer_id: nil,\n    fax: \"fax\", first_name: \"first_name\", id: nil, last_name: \"last_name\",\n    phone: \"phone\", state: \"state\", zip: \"zip\"}, customer_id: 35962612,\n   payment_type: %AuthorizeNet.BankAccount{account_number: \"XXXX0999\",\n    bank_name: \"bank_name\", echeck_type: :web, name_on_account: \"name_on_account\",\n    routing_number: \"XXXX3093\", type: :savings}, profile_id: 32510152,\n   type: :individual}\n```\n\nThere is a third argument available which is a list of options. The available\noptions are:\n\n * **:unmask_expiration_date**: For payment profiles associated to credit cards,\n this will return the expiration date unmasked.\n\nExample:\n```elixir\n  \u003e P.get 35962612, 34818508, [:unmask_expiration_date]\n```\n\n### Searching for payment profiles\nThis will return all the payment profiles of all customers that matches the\ngiven criteria. For more information about the values allowed see:\n[http://developer.authorize.net/api/reference/#customer-profiles-get-customer-payment-profile-list](http://developer.authorize.net/api/reference/#customer-profiles-get-customer-payment-profile-list).\n\n```elixir\n  \u003e P.get_list \"cardsExpiringInMonth\", \"2016-08\", \"id\", false, 100, 1\n  [%AuthorizeNet.PaymentProfile{address: %AuthorizeNet.Address{address: \"street\",\n   city: \"city\", company: \"company\", country: \"country\", customer_id: 38311592,\n   fax: \"fax\", first_name: \"first_name\", id: nil, last_name: \"last_name\",\n   phone: \"phone\", state: \"state\", zip: \"zip\"}, customer_id: 38311592,\n   payment_type: %AuthorizeNet.Card{code: nil, expiration_date: \"XXXX\",\n   number: \"XXXX0015\"}, profile_id: 34818508, type: nil}]\n```\n\n### Validating\n```elixir\n  \u003e P.valid? 35962612, 32510145\n  {false,\n   %AuthorizeNet.Error.Operation{message: [{\"E00027\", \"Card Code is required.\"}]}}\n\n  \u003e P.valid? 35962612, 32510145, \"900\"\n  true\n```\n\n### Deleting\n```elixir\n  \u003e AuthorizeNet.PaymentProfile.delete 35962612, 32510145\n  :ok\n```\n\n----\n\n## Making transactions\n\n### In a nutshell\nTransactions are made via the [Transaction](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/transaction.ex) module.\nTo create a transaction, just call the `new` function, passing an optional amount (a float) as the argument.\n\n```elixir\nalias AuthorizeNet.Transaction, as: T\n\nT.new(12.34)\n```\n\nTo run a transaction, just call the `run` function:\n```elixir\nT.new(12.34) |\u003e\nT.run\n```\n\n### TransactionResponse\nAll transactions will return a [TransactionResponse](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/transaction_response.ex)\nstruct, like:\n\n```elixir\n%AuthorizeNet.TransactionResponse{account_number: \"XXXX0015\",\n account_type: \"MasterCard\", auth_code: \"QWIDX2\", avs_result: \"Y\",\n cavv_result: nil, code: 1, cvv_result: nil,\n errors: [{\"I00001\", \"Successful.\"}], operation_errors: [],\n ref_transaction_id: nil, success: true, test_request: \"0\",\n transaction_hash: \"D05A1D1C4558FB329522CCFC62B4A7F3\",\n transaction_id: \"2235759738\", user_fields: [{\"key1\", \"value1\"}, {\"key2\", \"value2\"}]}\n```\n\n### Transaction types\nAuthorize.Net supports different [transaction types](https://support.authorize.net/authkb/index?page=content\u0026id=A510).\nYou can choose between them as follows:\n```elixir\nT.new                     |\u003e\nT.auth_capture()          # or\nT.auth_only()             # or\nT.capture_only()          # or\nT.prior_auth_capture()    # or\nT.void(transaction_id)    # or\nT.refund(transaction_id)  # or\n```\n\n### Adding customer, billing and shipping information\nThese might or might not be required depending on the type of payment you choose\n(i.e: customer profiles include the billing and shipping information in their\npayment profile ids and shipping address ids respectively):\n\n```elixir\nT.bill_to(address)                             |\u003e\nT.ship_to(address)                             |\u003e\nT.customer_individual(\"id1\", \"email@host.com\") |\u003e\n\n# You can also specify a \"business\" customer instead:\nT.customer_business(\"id1\", \"email@host.com\")\n```\n\n### Transaction Settings\nYou can enable and disable different transaction settings, like:\n```elixir\nT.enable_partial_auth      |\u003e  # or T.disable_partial_auth\nT.enable_duplicate_window  |\u003e  # or T.disable_duplicate_window\nT.enable_test_request      |\u003e  # or T.disable_test_request\nT.enable_recurring_billing |\u003e  # or T.disable_recurring_billing\nT.enable_email_customer        # or T.disable_email_customer\n```\n\n### Adding tax information\nOptionally, you can add some tax information:\n```elixir\nT.not_tax_exempt                              |\u003e # or T.tax_exempt\nT.tax(\"name\", \"description\", 3.44)            |\u003e\nT.duty(\"name\", \"description\", 3.44)           |\u003e\nT.shipping_cost(\"name\", \"description\", 3.44)\n```\n\n### Adding order information\nYou can include the order information (and optionally any billing items and\npurchase order ) like this:\n\n```elixir\nT.order(\"4455\", \"order description\")         |\u003e\nT.add_item(1, \"item1\", \"itemdesc1\", 1, 1.00) |\u003e\nT.add_item(2, \"item2\", \"itemdesc2\", 1, 2.00) |\u003e\nT.po_number(\"po_number_1\")\n```\n\n### Specifying market type\n```elixir\nT.market_retail    # or\nT.market_ecommerce # or\nT.market_moto\n```\n\n### Specifying device type\n```elixir\nT.device_website                  # or\nT.device_unknown                  # or\nT.device_unattended_terminal      # or\nT.device_electronic_cash_register # or\nT.device_personal_computer        # or\nT.device_air_pay                  # or\nT.device_self_service_terminal    # or\nT.device_wireless_pos             # or\nT.device_dial_terminal            # or\nT.device_virtual_terminal         # or\n```\n\n### Adding custom fields\n```elixir\nT.user_fields(%{\n  \"key1\": \"value1\",\n  \"key2\": \"value2\"\n})\n```\n\n### Other information you can add to the transaction.\n```elixir\nT.auth_code(\"QFBYYN\")              |\u003e # Used for already authorised transactions.\nT.ref_transaction_id(\"2235786422\") |\u003e # Used to refund or credit\nT.employee_id(5678)                |\u003e\nT.customer_ip(\"127.0.0.1\")\n```\n\n### Paying with credit card\n```elixir\nT.new(10.25)                         |\u003e\nT.auth_capture()                     |\u003e\nT.bill_to(address)                   |\u003e\nT.pay_with_card(card)                |\u003e\nT.order(\"4455\", \"order description\") |\u003e\nT.run\n```\n\n### Paying with a payment profile id\n```elixir\nT.new(10.25)                         |\u003e\nT.auth_capture()                     |\u003e\nT.pay_with_customer_profile(\n  customer_profile_id,\n  payment_profile_id,\n  shipping_address_id,\n  card_code\n)                                    |\u003e\nT.order(\"4455\", \"order description\") |\u003e\nT.run\n```\n\n### Paying with Apple Pay\n```elixir\nT.new(10.25)                         |\u003e\nT.auth_capture()                     |\u003e\nT.pay_with_apple_pay(encrypted_data) |\u003e\nT.order(\"4455\", \"order description\") |\u003e\nT.run\n```\n\n### Paying with a Bank Account\n```elixir\nT.new(10.25)                         |\u003e\nT.bill_to(address)                   |\u003e\nT.auth_capture()                     |\u003e\nT.pay_with_bank_account(account)     |\u003e\nT.order(\"4455\", \"order description\") |\u003e\nT.run\n```\n\n### Voiding a transaction\n```elixir\nT.new                |\u003e\nT.void(\"2235759535\") |\u003e\nT.run\n```\n\n### Refund a transaction\n```elixir\nT.new(3.00)                          |\u003e\nT.bill_to(address)                   |\u003e\nT.order(\"4455\", \"order description\") |\u003e\nT.pay_with_card(card)                |\u003e\nT.refund(\"2235759535\")               |\u003e\nT.run\n```\n\n----\n\n## Errors\n\nThese errors might be raised by the API calls:\n\n * [AuthorizeNet.Error.Connection](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/error/connection_error.ex): There was an error when trying to hit the API endpoint (like a network issue).\n\n * [AuthorizeNet.Error.Request](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/error/request_error.ex): The request was sent and received by the server, but it returned a status different than 200.\n\n * [AuthorizeNet.Error.Operation](https://github.com/marcelog/elixir_authorizenet/blob/master/lib/elixir_authorizenet/error/operation_error.ex): The request was sent and received successfully, a status 200 was returned by the server, but there was an error when trying to process the operation.\n\n# License\nThe source code is released under Apache 2 License.\n\nCheck [LICENSE](https://github.com/marcelog/elixir_authorizenet/blob/master/LICENSE) file for more information.\n\n# TODO\n * Allow payment profiles when creating a customer profile.\n * Add support for [hosted profile page](http://developer.authorize.net/api/reference/index.html#manage-customer-profiles-get-hosted-profile-page).\n * Add support for [creating a customer profile from a successful transaction](http://developer.authorize.net/api/reference/index.html#manage-customer-profiles-create-a-customer-profile-from-a-transaction).\n * Add support for [recurring billing](http://developer.authorize.net/api/reference/index.html#recurring-billing).\n\n# Useful Authorize.Net documentation\n * [API reference](http://developer.authorize.net/api/reference/).\n * [Transaction Types](https://support.authorize.net/authkb/index?page=content\u0026id=A510).\n * How to generate [specific error codes](http://developer.authorize.net/tools/errorgenerationguide/) useful for testing purposes.\n * Error reason [check tool](http://developer.authorize.net/tools/responsereasoncode/).\n * [FAQ about sandbox environment](https://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/Authorize-Net-Sandbox-FAQs/ba-p/17440).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Felixir_authorizenet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcelog%2Felixir_authorizenet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcelog%2Felixir_authorizenet/lists"}