{"id":20629936,"url":"https://github.com/academe/authorizenet-objects","last_synced_at":"2025-06-21T22:41:55.153Z","repository":{"id":54265682,"uuid":"84731258","full_name":"academe/authorizenet-objects","owner":"academe","description":"Value objects for construction Authorize.Net messages","archived":false,"fork":false,"pushed_at":"2021-02-28T12:37:06.000Z","size":198,"stargazers_count":8,"open_issues_count":7,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-23T15:23:58.014Z","etag":null,"topics":["authorize-net","authorizenet","json","json-api","payment-gateway"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/academe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-12T14:20:14.000Z","updated_at":"2024-12-19T11:59:08.000Z","dependencies_parsed_at":"2022-08-13T10:30:33.019Z","dependency_job_id":null,"html_url":"https://github.com/academe/authorizenet-objects","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/academe/authorizenet-objects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/academe%2Fauthorizenet-objects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/academe%2Fauthorizenet-objects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/academe%2Fauthorizenet-objects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/academe%2Fauthorizenet-objects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/academe","download_url":"https://codeload.github.com/academe/authorizenet-objects/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/academe%2Fauthorizenet-objects/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261205690,"owners_count":23124813,"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":["authorize-net","authorizenet","json","json-api","payment-gateway"],"created_at":"2024-11-16T14:06:27.767Z","updated_at":"2025-06-21T22:41:50.133Z","avatar_url":"https://github.com/academe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Value Objects for Authorize.Net\n\n[![Build Status](https://travis-ci.org/academe/authorizenet-objects.svg?branch=master)](https://travis-ci.org/academe/authorizenet-objects)\n[![Latest Stable Version](https://poser.pugx.org/academe/authorizenet-objects/v/stable)](https://packagist.org/packages/academe/authorizenet-objects)\n[![Total Downloads](https://poser.pugx.org/academe/authorizenet-objects/downloads)](https://packagist.org/packages/academe/authorizenet-objects)\n[![Latest Unstable Version](https://poser.pugx.org/academe/authorizenet-objects/v/unstable)](https://packagist.org/packages/academe/authorizenet-objects)\n[![License](https://poser.pugx.org/academe/authorizenet-objects/license)](https://packagist.org/packages/academe/authorizenet-objects)\n\nThe aim of this pacjage is to model, as value objects, all the data structures\ndefined here:\nhttp://developer.authorize.net/api/reference/\n\nThe data structure for the API messages is defined in the\n[XSD DTD](https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd).\nAlthough that is for the XSL API, the JSON API mirrors it closely.\nThis DTD has been parsed into\n[this documentation page](https://academe.github.io/authorizenet-objects/AnetApiSchema.html)\nusing [xs3p.xsl](https://github.com/bitfehler/xs3p), which can be a little easier\nto read, and contains fewer errors than the official HTML documentation.\nPractically, use the two together.\n\n## General Project Stucture\n\nThe request messages are under `Academe\\AuthorizeNet\\Request`.\nAll these requests take a `Academe\\AuthorizeNet\\Auth\\MerchantAuthentication` object\nto provide authentication and one or more additional objects to carry the main\nmessage detail.\n\nThe `Academe\\AuthorizeNet\\Request\\CreateTransaction` message takes a transaction\nobject from under `Academe\\AuthorizeNet\\Request\\Transaction`.\nThe `Transaction` object is built mainly from scalar data and other objects under\n`Academe\\AuthorizeNet\\Request\\Model`.\n\nThere are collections under `Academe\\AuthorizeNet\\Collections` used to group some\nof the `Model` objects, for example `LineItems` or `UserFields`.\nThese `Collections` may be moved to `Academe\\AuthorizeNet\\Request` at some point,\nso be ready for that.\n\nNote: this documentation is sparse at the moment, but the code covers much of the API.\n\n## Examples\n\nOne package that uses this package is the\n[Authorize.Net API](https://github.com/academe/omnipay-authorizenetapi)\ndriver for the [Omnipay](https://omnipay.thephpleague.com/) project.\n\nFurther libraries can then wrap these objects into a gateway driver.\nAny request object, once constructed, can be serialised to JSON (`json_encode()`)\nto provide the body of the request that the API will expect.\n\nThe response from Authorize.Net will be a JSON structure, which can be parsed\nby the application. The intention is also to create a factory in this package\nthat will parse the response into value objects and collections.\nMany of the response value objects have been created, but there is no factory\nyet to fill them up with data.\n\n```php\n\u003c?php\n\nuse Academe\\AuthorizeNet;\nuse Academe\\AuthorizeNet\\Auth;\nuse Academe\\AuthorizeNet\\Amount;\nuse Academe\\AuthorizeNet\\Payment;\nuse Academe\\AuthorizeNet\\Request;\nuse Academe\\AuthorizeNet\\Collections;\n\n// Composer: moneyphp/money\nuse Money\\Money;\n\nrequire 'vendor/autoload.php';\n\necho \"\u003cpre\u003e\";\n\n// Set up authorisation details.\n$auth = new Auth\\MerchantAuthentication('xxx', 'yyy');\n\n// Create a credit card.\n$credit_card = new Payment\\CreditCard('4000123412341234', '1220', '123');\n\n// Or create a magnetic stripe track (only one can be used).\n$track1 = new Payment\\Track1('TTTTTTTTTTTTTTTT11111');\n$track2 = new Payment\\Track2('TTTTTTTT2222222222222222');\n\n// Create order details.\n$order = new Request\\Model\\Order('orderx', 'ordery');\n\n// Create customer detals.\n$customer = new Request\\Model\\Customer('business', 'Customer ID', 'customer@example.com');\n\n// Create retail flags\n$retail = new Request\\Model\\Retail(2, 3, 'HJSHDJSDJKSD');\n\n// Create a billing name and address.\n$billTo = new Request\\Model\\NameAddress('BFirstname', 'BLastname', null, 'Address Line');\n$billTo = $billTo-\u003ewithCompany('My Billing Company Ltd')-\u003ewithZip('ZippyZipBill');\n\n// Create a shipping name and address.\n$shipTo = new Request\\Model\\NameAddress();\n// A single with() can set multiple values at once.\n$shipTo = $shipTo-\u003ewith([\n    'firstName' =\u003e 'Firstname',\n    'lastName' =\u003e 'Lastname',\n    'city' =\u003e 'My City',\n    'country' =\u003e 'United Kingdom',\n]);\n\n// Create a total amount of £24.99\n$amount = new Amount\\Amount('GBP', 2499);\n// Or maybe just £19.99\n$amount = $amount-\u003ewithMajorUnit(19.99);\n\n// Better still, use moneyphp/money to set the amount to £15.49\n$money_php_object = Money::GBP(1549);\n$amount = new Amount\\MoneyPhp($money_php_object);\n\n// Create tax amount.\n// All parameters have a with*() method available.\n$tax = new Request\\Model\\ExtendedAmount();\n$tax = $tax-\u003ewithName('Tax Name')-\u003ewithDescription('Tax Description');\n$tax = $tax-\u003ewithAmount(new Amount\\MoneyPhp(Money::GBP(99));\n\n// Set up some line items.\n// Note these collections are not value objects. Should they be?\n$lineItems = new Collections\\LineItems();\n$lineItems-\u003epush(new Request\\Model\\LineItem(1, 'Item Name 1', 'Item Desc 1', 1.5, new Amount\\MoneyPhp(Money::GBP(49)), false));\n$lineItems-\u003epush(new Request\\Model\\LineItem(2, 'Item Name 2', 'Item Desc 2', 2, new Amount\\MoneyPhp(Money::GBP(97)), true));\n\n// Set up some transaction settings.\n$transactionSettings = new Collections\\TransactionSettings();\n$transactionSettings-\u003epush(new Request\\Model\\Setting('Foo', 'Bar'));\n\n// And add some user fields.\n$userFields = new Collections\\UserFields();\n$userFields-\u003epush(new Request\\Model\\UserField('UserFoo', 'UserBar'));\n\n// Now put most of these into an Auth Capture transaction.\n$auth_capture_transaction = new Request\\Transaction\\AuthCapture($amount);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithPayment(/*$track1*/ $credit_card);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithCreateProfile(false);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithTaxExempt(true);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithLineItems($lineItems);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithTransactionSettings($transactionSettings);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithUserFields($userFields);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithSolutionId('SOLLLL');\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithTax($tax)-\u003ewithDuty($tax)-\u003ewithShipping($tax);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithPoNumber('myPoNumber');\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithCustomer($customer);\n$auth_capture_transaction = $auth_capture_transaction-\u003ewithRetail($retail);\n\n// You can set multiple items using an array:\n\n$auth_capture_transaction = $auth_capture_transaction-\u003ewith([\n    'order' =\u003e $order,\n    'shipTo' =\u003e $shipTo,\n    'billTo' =\u003e $billTo,\n    'employeeId' =\u003e '1234',\n    'customerIp' =\u003e '1.2.3.4',\n]);\n\n\n// Add the auth capture transaction to the transaction request, along with the auth details.\n$transaction_request = new Request\\CreateTransaction($auth, $auth_capture_transaction);\n\n// Display the resulting JSON request message.\necho '\u003cp\u003e' . $transaction_request-\u003egetObjectName() . ': \u003c/p\u003e';\necho \"\u003ctextarea style='width:100%;height: 12em'\u003e\" . json_encode($transaction_request) . \"\u003c/textarea\u003e\";\n\n/*\n{\n   \"createTransactionRequest\":{\n      \"merchantAuthentication\":{\n         \"name\":\"xxx\",\n         \"transactionKey\":\"yyy\"\n      },\n      \"refId\":\"REFREFREF\",\n      \"transactionRequest\":{\n         \"transactionType\":\"authCaptureTransaction\",\n         \"amount\":\"9.99\",\n         \"currencyCode\":\"GBP\",\n         \"payment\":{\n            \"creditCard\":{\n               \"cardNumber\":\"4000123412341234\",\n               \"expirationDate\":\"1220\",\n               \"cardCode\":\"123\"\n            }\n         },\n         \"profile\":{\n            \"createProfile\":false\n         },\n         \"solution\":{\n            \"id\":\"SOLLLL\"\n         },\n         \"order\":{\n            \"invoiceNumber\":\"orderx\",\n            \"description\":\"ordery\"\n         },\n         \"lineItems\":{\n            \"lineItem\":[\n               {\n                  \"itemId\":1,\n                  \"name\":\"Item Name 1\",\n                  \"description\":\"Item Desc 1\",\n                  \"quantity\":1.5,\n                  \"unitPrice\":\"0.49\",\n                  \"taxable\":false\n               },\n               {\n                  \"itemId\":2,\n                  \"name\":\"Item Name 2\",\n                  \"description\":\"Item Desc 2\",\n                  \"quantity\":2,\n                  \"unitPrice\":\"0.97\",\n                  \"taxable\":true\n               }\n            ]\n         },\n         \"tax\":{\n            \"amount\":\"9.99\",\n            \"name\":\"Tax Name\",\n            \"description\":\"Tax Description\"\n         },\n         \"duty\":{\n            \"amount\":\"9.99\",\n            \"name\":\"Tax Name\",\n            \"description\":\"Tax Description\"\n         },\n         \"shipping\":{\n            \"amount\":\"9.99\",\n            \"name\":\"Tax Name\",\n            \"description\":\"Tax Description\"\n         },\n         \"taxExempt\":true,\n         \"poNumber\":\"myPoNumber\",\n         \"customer\":{\n            \"type\":\"business\",\n            \"id\":\"Customer ID\",\n            \"email\":\"customer@example.com\"\n         },\n         \"billTo\":{\n            \"firstName\":\"BFirstname\",\n            \"lastName\":\"BLastname\",\n            \"company\":\"My Billing Company Ltd\",\n            \"address\":\"Address Line\",\n            \"zip\":\"ZippyZipBill\"\n         },\n         \"shipTo\":{\n            \"firstName\":\"Firstname\",\n            \"lastName\":\"Lastname\",\n            \"city\":\"My City\",\n            \"country\":\"United Kingdom\"\n         },\n         \"customerIP\":\"1.2.3.4\",\n         \"cardholderAuthentication\":{\n            \"authenticationIndicator\":\"AAAA\"\n         },\n         \"retail\":{\n            \"marketType\":2,\n            \"deviceType\":3,\n            \"customerSignature\":\"HJSHDJSDJKSD\"\n         },\n         \"employeeId\":\"1234\",\n         \"transactionSettings\":{\n            \"setting\":[\n               {\n                  \"settingName\":\"Foo\",\n                  \"settingValue\":\"Bar\"\n               }\n            ]\n         },\n         \"userFields\":{\n            \"userField\":[\n               {\n                  \"name\":\"UserFoo\",\n                  \"value\":\"UserBar\"\n               }\n            ]\n         }\n      }\n   }\n}\n*/\n```\n\nThis can be sent to the gateway simply (and naively, just for demonstration) using Guzzle:\n\n```php\n// \"guzzlehttp/guzzle\": \"~6.0\"\nuse GuzzleHttp\\Client;\n\n$client = new GuzzleHttp\\Client();\n\n// sandbox endpoint\n$endpoint = 'https://apitest.authorize.net/xml/v1/request.api';\n\n$response = $client-\u003erequest('POST', $endpoint, [\n    // Just pass the object and Guzzle will cast it to JSON.\n    'json' =\u003e $transaction_request,\n]);\n\nvar_dump((string)$response-\u003egetBody());\n\n/*\n{\n   \"transactionResponse\":{\n      \"responseCode\":\"1\",\n      \"authCode\":\"59WHY9\",\n      \"avsResultCode\":\"Y\",\n      \"cvvResultCode\":\"P\",\n      \"transId\":\"60020301993\",\n      \"refTransID\":\"\",\n      \"transHash\":\"2EA6BB2D8D88C587EA16C77C44C7B8B2\",\n      \"testRequest\":\"0\",\n      \"accountNumber\":\"XXXX1234\",\n      \"entryMode\":\"Keyed\",\n      \"accountType\":\"Visa\",\n      \"messages\":[\n         {\n            \"code\":\"1\",\n            \"description\":\"This transaction has been approved.\"\n         }\n      ],\n      \"userFields\":[\n         {\n            \"name\":\"UserFoo\",\n            \"value\":\"UserBar\"\n         }\n      ],\n      \"transHashSha2\":\"\"\n   },\n   \"refId\":\"5678917213\",\n   \"messages\":{\n      \"resultCode\":\"Ok\",\n      \"message\":[\n         {\n            \"code\":\"I00001\",\n            \"text\":\"Successful.\"\n         }\n      ]\n   }\n}\n*/\n```\n\nThis response data can then be parsed into nested objects:\n\n```php\n$responseObject = new \\Academe\\AuthorizeNet\\Response\\Response(json_decode((string)$response-\u003egetBody(), true));\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facademe%2Fauthorizenet-objects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facademe%2Fauthorizenet-objects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facademe%2Fauthorizenet-objects/lists"}