Server IP : 213.176.29.180 / Your IP : 18.220.194.186 Web Server : Apache System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64 User : webtaragh ( 1001) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0750) : /home/webtaragh/www/wp-includes/block-supports/../../ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
authorizenet/CONTRIBUTING.md 0000644 00000002570 14736103100 0011515 0 ustar 00 Thanks for contributing to the Authorize.Net PHP SDK. Before you submit a pull request, we ask that you consider the following: - Submit an issue to state the problem your pull request solves or the funtionality that it adds. We can then advise on the feasability of the pull request, and let you know if there are other possible solutions. - Part of the SDK is auto-generated based on the XML schema. Due to this auto-generation, we cannot merge contributions for request or response classes. You are welcome to open an issue to report problems or suggest improvements. Auto-generated classes include all files inside [contract/v1](https://github.com/AuthorizeNet/sdk-php/tree/master/lib/net/authorize/api/contract/v1) and [controller](https://github.com/AuthorizeNet/sdk-php/tree/master/lib/net/authorize/api/controller) folders, except [controller/base](https://github.com/AuthorizeNet/sdk-php/tree/master/lib/net/authorize/api/controller/base). - Files marked as deprecated are no longer supported. Issues and pull requests for changes to these deprecated files will be closed. - Recent changes will be in future branch. Check the code in *future* branch first to see if a fix has already been merged, before suggesting changes to a file. - **Always create pull request to the future branch.** The pull request will be merged to future, and later pushed to master as part of the next release. authorizenet/MIGRATING.md 0000644 00000014773 14736103100 0011137 0 ustar 00 # Migrating from Legacy Authorize.Net Classes Authorize.Net no longer supports several legacy classes, including AuthorizeNetAIM.php, AuthorizenetSIM.php, and others listed below, as part of PHP-SDK. If you are using any of these, we recommend that you update your code to use the new Authorize.Net API classes. **For details on the deprecation and replacement of legacy Authorize.Net APIs, visit https://developer.authorize.net/api/upgrade_guide/.** ## Full list of classes that are no longer supported | Class | New Feature | Sample Codes directory/repository | |----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| | AuthorizeNetAIM.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | | AuthorizeNetARB.php | [RecurringBilling](https://developer.authorize.net/api/reference/index.html#recurring-billing) | [sample-code-php/RecurringBilling](https://github.com/AuthorizeNet/sample-code-php/tree/master/RecurringBilling) | | AuthorizeNetCIM.php | [CustomerProfiles](https://developer.authorize.net/api/reference/index.html#customer-profiles) | [sample-code-php/CustomerProfiles](https://github.com/AuthorizeNet/sample-code-php/tree/master/CustomerProfiles) | | Hosted CIM | [Accept Customer](https://developer.authorize.net/content/developer/en_us/api/reference/features/customer_profiles.html#Using_the_Accept_Customer_Hosted_Form) | Not available | | AuthorizeNetCP.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | | AuthorizeNetDPM.php | [Accept.JS](https://developer.authorize.net/api/reference/features/acceptjs.html) | [Sample Accept Application](https://github.com/AuthorizeNet/accept-sample-app) | | AuthorizeNetSIM.php | [Accept Hosted](https://developer.authorize.net/content/developer/en_us/api/reference/features/accept_hosted.html) | Not available | | AuthorizeNetSOAP.php | [PaymentTransactions](https://developer.authorize.net/api/reference/index.html#payment-transactions) | [sample-code-php/PaymentTransactions](https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions) | | AuthorizeNetTD.php | [TransactionReporting](https://developer.authorize.net/api/reference/index.html#transaction-reporting) | [sample-code-php/TransactionReporting/](https://github.com/AuthorizeNet/sample-code-php/tree/master/TransactionReporting) | ## Example #### Old AuthorizeNetAIM example: ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); define("AUTHORIZENET_SANDBOX", true); $sale = new AuthorizeNetAIM; $sale->amount = "5.99"; $sale->card_num = '6011000000000012'; $sale->exp_date = '04/15'; $response = $sale->authorizeAndCapture(); if ($response->approved) { $transaction_id = $response->transaction_id; } ``` #### Corresponding new model code (charge-credit-card): ```php require 'vendor/autoload.php'; use net\authorize\api\contract\v1 as AnetAPI; use net\authorize\api\controller as AnetController; define("AUTHORIZENET_LOG_FILE", "phplog"); $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName("YOURLOGIN"); $merchantAuthentication->setTransactionKey("YOURKEY"); // Create the payment data for a credit card $creditCard = new AnetAPI\CreditCardType(); $creditCard->setCardNumber("6011000000000012"); $creditCard->setExpirationDate("2015-04"); $creditCard->setCardCode("123"); // Add the payment data to a paymentType object $paymentOne = new AnetAPI\PaymentType(); $paymentOne->setCreditCard($creditCard); $transactionRequestType = new AnetAPI\TransactionRequestType(); $transactionRequestType->setTransactionType("authCaptureTransaction"); $transactionRequestType->setAmount("5.99"); $transactionRequestType->setPayment($paymentOne); // Assemble the complete transaction request $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); $request->setTransactionRequest($transactionRequestType); // Create the controller and get the response $controller = new AnetController\CreateTransactionController($request); $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX); if ($response != null) { // Check to see if the API request was successfully received and acted upon if ($response->getMessages()->getResultCode() == "Ok") { // Since the API request was successful, look for a transaction response // and parse it to display the results of authorizing the card $tresponse = $response->getTransactionResponse(); if ($tresponse != null && $tresponse->getMessages() != null) { echo " Successfully created transaction with Transaction ID: " . $tresponse->getTransId() . "\n"; echo " Transaction Response Code: " . $tresponse->getResponseCode() . "\n"; echo " Message Code: " . $tresponse->getMessages()[0]->getCode() . "\n"; echo " Auth Code: " . $tresponse->getAuthCode() . "\n"; echo " Description: " . $tresponse->getMessages()[0]->getDescription() . "\n"; } } } ``` authorizenet/autoload.php 0000644 00000001337 14736103100 0011605 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated Always use composer generated autoload.php, by requiring vendor/autoload.php instead of autoload.php * @deprecated require "autoload.php"; --> require "vendor/autoload.php"; */ trigger_error('Custom autoloader is deprecated, use composer generated "vendor/autoload.php" instead of "autoload.php" .', E_USER_DEPRECATED); /** * Custom SPL autoloader for the AuthorizeNet SDK * * @package AuthorizeNet */ spl_autoload_register(function($className) { static $classMap; if (!isset($classMap)) { $classMap = require __DIR__ . DIRECTORY_SEPARATOR . 'classmap.php'; } if (isset($classMap[$className])) { include $classMap[$className]; } }); authorizenet/LICENSE.txt 0000644 00000042220 14736103100 0011103 0 ustar 00 SDK LICENSE AGREEMENT This Software Development Kit (“SDK”) License Agreement (“Agreement”) is between you (both the individual downloading the SDK and any legal entity on behalf of which such individual is acting) (“You” or “Your”) and Authorize.Net LLC (“Authorize.Net’). IT IS IMPORTANT THAT YOU READ CAREFULLY AND UNDERSTAND THIS AGREEMENT. BY CLICKING THE “I ACCEPT” BUTTON OR AN EQUIVALENT INDICATOR OR BY DOWNLOADING, INSTALLING OR USING THE SDK OR THE DOCUMENTATION, YOU AGREE TO BE BOUND BY THIS AGREEMENT. 1. DEFINITIONS 1.1 “Application(s)” means software programs that You develop to operate with the Gateway using components of the Software. 1.2 “Documentation” means the materials made available to You in connection with the Software by or on behalf of Authorize.Net pursuant to this Agreement. 1.3 “Gateway” means any electronic payment platform maintained and operated by Authorize.Net and any of its affiliates. 1.4 “Software” means all of the software included in the software development kit made available to You by or on behalf of Authorize.Net pursuant to this Agreement, including but not limited to sample source code, code snippets, software tools, code libraries, sample applications, Documentation and any upgrades, modified versions, updates, and/or additions thereto, if any, made available to You by or on behalf of Authorize.Net pursuant to this Agreement. 2. GRANT OF LICENSE; RESTRICTIONS 2.1 Limited License. Subject to and conditioned upon Your compliance with the terms of this Agreement, Authorize.Net hereby grants to You a limited, revocable, non-exclusive, non-transferable, royalty-free license during the term of this Agreement to: (a) in any country worldwide, use, reproduce, modify, and create derivative works of the components of the Software solely for the purpose of developing, testing and manufacturing Applications; (b) distribute, sell or otherwise provide Your Applications that include components of the Software to Your end users; and (c) use the Documentation in connection with the foregoing activities. The license to distribute Applications that include components of the Software as set forth in subsection (b) above includes the right to grant sublicenses to Your end users to use such components of the Software as incorporated into such Applications, subject to the limitations and restrictions set forth in this Agreement. 2.2 Restrictions. You shall not (and shall have no right to): (a) make or distribute copies of the Software or the Documentation, in whole or in part, except as expressly permitted pursuant to Section 2.1; (b) alter or remove any copyright, trademark, trade name or other proprietary notices, legends, symbols or labels appearing on or in the Software or Documentation; (c) sublicense (or purport to sublicense) the Software or the Documentation, in whole or in part, to any third party except as expressly permitted pursuant to Section 2.1; (d) engage in any activity with the Software, including the development or distribution of an Application, that interferes with, disrupts, damages, or accesses in an unauthorized manner the Gateway or platform, servers, or systems of Authorize.Net, any of its affiliates, or any third party; (e) make any statements that Your Application is “certified” or otherwise endorsed, or that its performance is guaranteed, by Authorize.Net or any of its affiliates; or (f) otherwise use or exploit the Software or the Documentation for any purpose other than to develop and distribute Applications as expressly permitted by this Agreement. 2.3 Ownership. You shall retain ownership of Your Applications developed in accordance with this Agreement, subject to Authorize.Net’s ownership of the Software and Documentation (including Authorize.Net’s ownership of any portion of the Software or Documentation incorporated in Your Applications). You acknowledge and agree that all right, title and interest in and to the Software and Documentation shall, at all times, be and remain the exclusive property of Authorize.Net and that You do not have or acquire any rights, express or implied, in the Software or Documentation except those rights expressly granted under this Agreement. 2.4 No Support. Authorize.Net has no obligation to provide support, maintenance, upgrades, modifications or new releases of the Software. 2.5 Open Source Software. You hereby acknowledge that the Software may contain software that is distributed under “open source” license terms (“Open Source Software”). You shall review the Documentation in order to determine which portions of the Software are Open Source Software and are licensed under such Open Source Software license terms. To the extent any such license requires that Authorize.Net provide You any rights with respect to such Open Source Software that are inconsistent with the limited rights granted to You in this Agreement, then such rights in the applicable Open Source Software license shall take precedence over the rights and restrictions granted in this Agreement, but solely with respect to such Open Source Software. You acknowledge that the Open Source Software license is solely between You and the applicable licensor of the Open Source Software and that Your use, reproduction and distribution of Open Source Software shall be in compliance with applicable Open Source Software license. You understand and agree that Authorize.Net is not liable for any loss or damage that You may experience as a result of Your use of Open Source Software and that You will look solely to the licensor of the Open Source Software in the event of any such loss or damage. 2.6 License to Authorize.Net. In the event You choose to submit any suggestions, feedback or other information or materials related to the Software or Documentation or Your use thereof (collectively, “Feedback”) to Authorize.Net, You hereby grant to Authorize.Net a worldwide, non-exclusive, royalty-free, transferable, sublicensable, perpetual and irrevocable license to use and otherwise exploit such Feedback in connection with the Software, Documentation, and other products and services. 2.7 Use. (a) You represent, warrant and agree to use the Software and write Applications only for purposes permitted by (i) this Agreement; (ii) applicable law and regulation, including, without limitation, the Payment Card Industry Data Security Standard (PCI DSS); and (iii) generally accepted practices or guidelines in the relevant jurisdictions. You represent, warrant and agree that if You use the Software to develop Applications for general public end users, that You will protect the privacy and legal rights of those users. If the Application receives or stores personal or sensitive information provided by end users, it must do so securely and in compliance with all applicable laws and regulations, including card association regulations. If the Application receives Authorize.Net account information, the Application may only use that information to access the end user's Authorize.Net account. You represent, warrant and agree that You are solely responsible for (and that neither Authorize.Net nor its affiliates have any responsibility to You or to any third party for): (i) any data, content, or resources that You obtain, transmit or display through the Application; and (ii) any breach of Your obligations under this Agreement, any applicable third party license, or any applicable law or regulation, and for the consequences of any such breach. 3. WARRANTY DISCLAIMER; LIMITATION OF LIABILITY 3.1 Disclaimer. THE SOFTWARE AND THE DOCUMENTATION ARE PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS WITH NO WARRANTY. YOU AGREE THAT YOUR USE OF THE SOFTWARE AND THE DOCUMENTATION IS AT YOUR SOLE RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, AUTHORIZE.NET AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, WITH RESPECT TO THE SOFTWARE AND THE DOCUMENTATION, INCLUDING ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, SATISFACTORY QUALITY, ACCURACY, TITLE AND NON-INFRINGEMENT, AND ANY WARRANTIES THAT MAY ARISE OUT OF COURSE OF PERFORMANCE, COURSE OF DEALING OR USAGE OF TRADE. NEITHER AUTHORIZE.NET NOR ITS AFFILIATES WARRANT THAT THE FUNCTIONS OR INFORMATION CONTAINED IN THE SOFTWARE OR THE DOCUMENTATION WILL MEET ANY REQUIREMENTS OR NEEDS YOU MAY HAVE, OR THAT THE SOFTWARE OR DOCUMENTATION WILL OPERATE ERROR FREE, OR THAT THE SOFTWARE OR DOCUMENTATION IS COMPATIBLE WITH ANY PARTICULAR OPERATING SYSTEM. 3.2 Limitation of Liability. IN NO EVENT SHALL AUTHORIZE.NET AND ITS AFFILIATES BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL OR PUNITIVE DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, BUSINESS, SAVINGS, DATA, USE OR COST OF SUBSTITUTE PROCUREMENT, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN AN ACTION IN CONTRACT OR TORT, EVEN IF AUTHORIZE.NET HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES ARE FORESEEABLE. IN NO EVENT SHALL THE ENTIRE LIABILITY OF AUTHORIZE.NET AND AFFILIATES ARISING FROM OR RELATING TO THIS AGREEMENT OR THE SUBJECT MATTER HEREOF EXCEED ONE HUNDRED U.S. DOLLARS ($100). THE PARTIES ACKNOWLEDGE THAT THE LIMITATIONS OF LIABILITY IN THIS SECTION 3.2 AND IN THE OTHER PROVISIONS OF THIS AGREEMENT AND THE ALLOCATION OF RISK HEREIN ARE AN ESSENTIAL ELEMENT OF THE BARGAIN BETWEEN THE PARTIES, WITHOUT WHICH AUTHORIZE.NET WOULD NOT HAVE ENTERED INTO THIS AGREEMENT. 4. INDEMNIFICATION. You shall indemnify, hold harmless and, at Authorize.Net’s request, defend Authorize.Net and its affiliates and their officers, directors, employees, and agents from and against any claim, suit or proceeding, and any associated liabilities, costs, damages and expenses, including reasonable attorneys’ fees, that arise out of relate to: (i) Your Applications or the use or distribution thereof and Your use or distribution of the Software or the Documentation (or any portion thereof including Open Source Software), including, but not limited to, any allegation that any such Application or any such use or distribution infringes, misappropriates or otherwise violates any intellectual property (including, without limitation, copyright, patent, and trademark), privacy, publicity or other rights of any third party, or has caused the death or injury of any person or damage to any property; (ii) Your alleged or actual breach of this Agreement; (iii) the alleged or actual breach of this Agreement by any party to whom you have provided Your Applications, the Software or the Documentation or (iii) Your alleged or actual violation of or non-compliance with any applicable laws, legislation, policies, rules, regulations or governmental requirements (including, without limitation, any laws, legislation, policies, rules, regulations or governmental requirements related to privacy and data collection). 5. TERMINATION. This Agreement and the licenses granted to you herein are effective until terminated. Authorize.Net may terminate this Agreement and the licenses granted to You at any time. Upon termination of this Agreement, You shall cease all use of the Software and the Documentation, return to Authorize.Net or destroy all copies of the Software and Documentation and related materials in Your possession, and so certify to Authorize.Net. Except for the license to You granted herein, the terms of this Agreement shall survive termination. 6. CONFIDENTIAL INFORMATION a. You hereby agree (i) to hold Authorize.Net’s Confidential Information in strict confidence and to take reasonable precautions to protect such Confidential Information (including, without limitation, all precautions You employ with respect to Your own confidential materials), (ii) not to divulge any such Confidential Information to any third person; (iii) not to make any use whatsoever at any time of such Confidential Information except as strictly licensed hereunder, (iv) not to remove or export from the United States or re-export any such Confidential Information or any direct product thereof, except in compliance with, and with all licenses and approvals required under applicable U.S. and foreign export laws and regulations, including, without limitation, those of the U.S. Department of Commerce. b. “Confidential Information” shall mean any data or information, oral or written, treated as confidential that relates to Authorize.Net’s past, present, or future research, development or business activities, including without limitation any unannounced products and services, any information relating to services, developments, inventions, processes, plans, financial information, customer data, revenue, transaction volume, forecasts, projections, application programming interfaces, Software and Documentation. 7. General Terms 7.1 Law. This Agreement and all matters arising out of or relating to this Agreement shall be governed by the internal laws of the State of California without giving effect to any choice of law rule. This Agreement shall not be governed by the United Nations Convention on Contracts for the International Sales of Goods, the application of which is expressly excluded. In the event of any controversy, claim or dispute between the parties arising out of or relating to this Agreement, such controversy, claim or dispute shall be resolved in the state or federal courts in Santa Clara County, California, and the parties hereby irrevocably consent to the jurisdiction and venue of such courts. 7.2 Logo License. Authorize.Net hereby grants to You the right to use, reproduce, publish, perform and display Authorize.Net logo solely in accordance with the current Authorize.Net brand guidelines. 7.3 Severability and Waiver. If any provision of this Agreement is held to be illegal, invalid or otherwise unenforceable, such provision shall be enforced to the extent possible consistent with the stated intention of the parties, or, if incapable of such enforcement, shall be deemed to be severed and deleted from this Agreement, while the remainder of this Agreement shall continue in full force and effect. The waiver by either party of any default or breach of this Agreement shall not constitute a waiver of any other or subsequent default or breach. 7.4 No Assignment. You may not assign, sell, transfer, delegate or otherwise dispose of, whether voluntarily or involuntarily, by operation of law or otherwise, this Agreement or any rights or obligations under this Agreement without the prior written consent of Authorize.Net, which may be withheld in Authorize.Net’s sole discretion. Any purported assignment, transfer or delegation by You shall be null and void. Subject to the foregoing, this Agreement shall be binding upon and shall inure to the benefit of the parties and their respective successors and assigns. 7.5 Government Rights. If You (or any person or entity to whom you provide the Software or Documentation) are an agency or instrumentality of the United States Government, the Software and Documentation are “commercial computer software” and “commercial computer software documentation,” and pursuant to FAR 12.212 or DFARS 227.7202, and their successors, as applicable, use, reproduction and disclosure of the Software and Documentation are governed by the terms of this Agreement. 7.6 Export Administration. You shall comply fully with all relevant export laws and regulations of the United States, including, without limitation, the U.S. Export Administration Regulations (collectively “Export Controls”). Without limiting the generality of the foregoing, You shall not, and You shall require Your representatives not to, export, direct or transfer the Software or the Documentation, or any direct product thereof, to any destination, person or entity restricted or prohibited by the Export Controls. 7.7 Privacy. In order to continually innovate and improve the Software, Licensee understands and agrees that Authorize.Net may collect certain usage statistics including but not limited to a unique identifier, associated IP address, version number of software, and information on which tools and/or services in the Software are being used and how they are being used. 7.8 Entire Agreement; Amendments. This Agreement constitutes the entire agreement between the parties and supersedes all prior or contemporaneous agreements or representations, written or oral, concerning the subject matter of this Agreement. Authorize.Net may make changes to this Agreement, Software or Documentation in its sole discretion. When these changes are made, Authorize.Net will make a new version of the Agreement, Software or Documentation available on the website where the Software is available. This Agreement may not be modified or amended by You except in a writing signed by a duly authorized representative of each party. You acknowledge and agree that Authorize.Net has not made any representations, warranties or agreements of any kind, except as expressly set forth herein. Authorize.Net Software Development Kit (SDK) License Agreement v. February 1, 2017 1 authorizenet/README.md 0000644 00000024477 14736103100 0010555 0 ustar 00 # Authorize.Net PHP SDK [![Travis CI Status](https://travis-ci.org/AuthorizeNet/sdk-php.svg?branch=master)](https://travis-ci.org/AuthorizeNet/sdk-php) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/AuthorizeNet/sdk-php/?branch=master) [![Packagist](https://img.shields.io/packagist/v/authorizenet/authorizenet.svg)](https://packagist.org/packages/authorizenet/authorizenet) [![Packagist Stable Version](https://poser.pugx.org/authorizenet/authorizenet/v/stable.svg)](https://packagist.org/packages/authorizenet/authorizenet) ## Requirements * PHP 5.6+ * cURL PHP Extension * JSON PHP Extension * An Authorize.Net account (see _Registration & Configuration_ section below) * TLS 1.2 capable versions of libcurl and OpenSSL (or its equivalent) ### Migrating from older versions Since August 2018, the Authorize.Net API has been reorganized to be more merchant focused. AuthorizeNetAIM, AuthorizeNetARB, AuthorizeNetCIM, Reporting and AuthorizeNetSIM classes have all been deprecated in favor of `net\authorize\api` . To see the full list of mapping of new features corresponding to the deprecated features, you can see [MIGRATING.md](MIGRATING.md). ### Contribution - If you need information or clarification about any Authorize.Net features, please create an issue for it. Also you can search in the [Authorize.Net developer community](https://community.developer.authorize.net/). - Before creating pull requests, please read [CONTRIBUTING.md](CONTRIBUTING.md) ### TLS 1.2 The Authorize.Net APIs only support connections using the TLS 1.2 security protocol. This SDK communicates with the Authorize.Net API using `libcurl` and `OpenSSL` (or equivalent crypto library). It's important to make sure you have new enough versions of these components to support TLS 1.2. Additionally, it's very important to keep these components up to date going forward to mitigate the risk of any security flaws that may be discovered in these libraries. To test whether your current installation is capable of communicating to our servers using TLS 1.2, run the following PHP code and examine the output for the TLS version: ```php <?php $ch = curl_init('https://apitest.authorize.net/xml/v1/request.api'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); $data = curl_exec($ch); curl_close($ch); ``` If curl is unable to connect to our URL (as given in the previous sample), it's likely that your system is not able to connect using TLS 1.2, or does not have a supported cipher installed. To verify what TLS version your connection _does_ support, run the following PHP code: ```php <?php $ch = curl_init('https://www.howsmyssl.com/a/check'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); $json = json_decode($data); echo "Connection uses " . $json->tls_version ."\n"; ``` ## Installation ### Composer We recommend using [`Composer`](http://getcomposer.org). *(Note: we never recommend you override the new secure-http default setting)*. *Update your composer.json file as per the example below and then run `composer update`.* ```json { "require": { "php": ">=5.6", "authorizenet/authorizenet": "~1.9.9" } } ``` After installation through Composer, don't forget to require its autoloader in your script or bootstrap file: ```php require 'vendor/autoload.php'; ``` ### Custom SPL Autoloader Alternatively, we provide a custom `SPL` autoloader for you to reference from within your PHP file: ```php require 'path/to/anet_php_sdk/autoload.php'; ``` This autoloader still requires the `vendor` directory and all of its dependencies to exist. However, this is a possible solution for cases where composer can't be run on a given system. You can run composer locally or on another system to build the directory, then copy the `vendor` directory to the desired system. ## Registration & Configuration Use of this SDK and the Authorize.Net APIs requires having an account on our system. You can find these details in the Settings section. If you don't currently have a production Authorize.Net account and need a sandbox account for testing, you can easily sign up for one [here](https://developer.authorize.net/sandbox/). ### Authentication To authenticate with the Authorize.Net API you will need to use your account's API Login ID and Transaction Key. If you don't have these values, you can obtain them from our Merchant Interface site. Access the Merchant Interface for production accounts at (https://account.authorize.net/) or sandbox accounts at (https://sandbox.authorize.net). Once you have your keys simply load them into the appropriate variables in your code, as per the below sample code dealing with the authentication part of the API request. #### To set your API credentials for an API request: ... ```php use net\authorize\api\contract\v1 as AnetAPI; ``` ... ```php $merchantAuthentication = new AnetAPI\MerchantAuthenticationType(); $merchantAuthentication->setName("YOURLOGIN"); $merchantAuthentication->setTransactionKey("YOURKEY"); ``` ... ```php $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($merchantAuthentication); ``` ... You should never include your Login ID and Transaction Key directly in a PHP file that's in a publically accessible portion of your website. A better practice would be to define these in a constants file, and then reference those constants in the appropriate place in your code. ### Switching between the sandbox environment and the production environment Authorize.Net maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this SDK is configured to communicate with the sandbox environment. To switch to the production environment, replace the environment constant in the execute method. For example: ```php // For PRODUCTION use $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION); ``` API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments. ## SDK Usage Examples and Sample Code To get started using this SDK, it's highly recommended to download our sample code repository: * [Authorize.Net PHP Sample Code Repository (on GitHub)](https://github.com/AuthorizeNet/sample-code-php) In that respository, we have comprehensive sample code for all common uses of our API: Additionally, you can find details and examples of how our API is structured in our API Reference Guide: * [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html) The API Reference Guide provides examples of what information is needed for a particular request and how that information would be formatted. Using those examples, you can easily determine what methods would be necessary to include that information in a request using this SDK. ## Building & Testing the SDK Integration tests for the AuthorizeNet SDK are in the `tests` directory. These tests are mainly for SDK development. However, you can also browse through them to find more usage examples for the various APIs. - Run `composer update --dev` to load the `PHPUnit` test library. - Copy the `phpunit.xml.dist` file to `phpunit.xml` and enter your merchant credentials in the constant fields. - Run `vendor/bin/phpunit` to run the test suite. *You'll probably want to disable emails on your sandbox account.* ### Testing Guide For additional help in testing your own code, Authorize.Net maintains a [comprehensive testing guide](http://developer.authorize.net/hello_world/testing_guide/) that includes test credit card numbers to use and special triggers to generate certain responses from the sandbox environment. ## Logging The SDK generates a log with masking for sensitive data like credit card, expiration dates. The provided levels for logging are `debug`, `info`, `warn`, `error`. Add ````use \net\authorize\util\LogFactory;````. Logger can be initialized using `$logger = LogFactory::getLog(get_class($this));` The default log file `phplog` gets generated in the current folder. The subsequent logs are appended to the same file, unless the execution folder is changed, and a new log file is generated. ### Usage Examples - Logging a string message `$logger->debug("Sending 'XML' Request type");` - Logging xml strings `$logger->debug($xmlRequest);` - Logging using formatting `$logger->debugFormat("Integer: %d, Float: %f, Xml-Request: %s\n", array(100, 1.29f, $xmlRequest));` ### Customizing Sensitive Tags A local copy of [AuthorizedNetSensitiveTagsConfig.json](/lib/net/authorize/util/ANetSensitiveFields.php) gets generated when code invoking the logger first gets executed. The local file can later be edited by developer to re-configure what is masked and what is visible. (*Do not edit the JSON in the SDK*). - For each element of the `sensitiveTags` array, - `tagName` field corresponds to the name of the property in object, or xml-tag that should be hidden entirely ( *XXXX* shown if no replacement specified ) or masked (e.g. showing the last 4 digits of credit card number). - `pattern`[<sup>[Note]</sup>](#regex-note) and `replacement`[<sup>[Note]</sup>](#regex-note) can be left `""`, if the default is to be used (as defined in [Log.php](/lib/net/authorize/util/Log.php)). `pattern` gives the regex to identify, while `replacement` defines the visible part. - `disableMask` can be set to *true* to allow the log to fully display that property in an object, or tag in a xml string. - `sensitiveStringRegexes`[<sup>[Note]</sup>](#regex-note) has list of credit-card regexes. So if credit-card number is not already masked, it would get entirely masked. - Take care of non-ascii characters (refer [manual](http://php.net/manual/en/regexp.reference.unicode.php)) while defining the regex, e.g. use `"pattern": "(\\p{N}+)(\\p{N}{4})"` instead of `"pattern": "(\\d+)(\\d{4})"`. Also note `\\` escape sequence is used. **<a name="regex-note">Note</a>:** **For any regex, no starting or ending '/' or any other delimiter should be defined. The '/' delimiter and unicode flag is added in the code.** ## License This repository is distributed under a proprietary license. See the provided [`LICENSE.txt`](/LICENSE.txt) file. authorizenet/lib/deprecated/shared/AuthorizeNetException.php 0000644 00000000765 14736103100 0020415 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated The Authorize.Net API has been reorganized to simplify & ease integration and to be more merchant focused * @deprecated AuthorizeNetException class is deprecated. * @deprecated Refer examples in https://github.com/AuthorizeNet/sample-code-php */ /** * AuthorizeNetException.php * * @package AuthorizeNet */ /** * Exception class for AuthorizeNet PHP SDK. * * @package AuthorizeNet */ class AuthorizeNetException extends Exception { } authorizenet/lib/deprecated/shared/AuthorizeNetXMLResponse.php 0000644 00000006212 14736103100 0020627 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated Use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php */ /** * Base class for the AuthorizeNet ARB & CIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetXML */ /** * Base class for the AuthorizeNet ARB & CIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetXML */ class AuthorizeNetXMLResponse { public $xml; // Holds a SimpleXML Element with response. /** * Constructor. Parses the AuthorizeNet response string. * * @param string $response The response from the AuthNet server. */ public function __construct($response) { $this->response = $response; if ($response) { $this->xml = @simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOWARNING); // Remove namespaces for use with XPath. $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response),'SimpleXMLElement', LIBXML_NOWARNING); } } /** * Was the transaction successful? * * @return bool */ public function isOk() { return ($this->getResultCode() == "Ok"); } /** * Run an xpath query on the cleaned XML response * * @param string $path * @return array Returns an array of SimpleXMLElement objects or FALSE in case of an error. */ public function xpath($path) { return $this->xpath_xml->xpath($path); } /** * Was there an error? * * @return bool */ public function isError() { return ($this->getResultCode() == "Error"); } /** * @return string */ public function getErrorMessage() { return "Error: {$this->getResultCode()} Message: {$this->getMessageText()} {$this->getMessageCode()}"; } /** * @return string */ public function getRefID() { return $this->_getElementContents("refId"); } /** * @return string */ public function getResultCode() { return $this->_getElementContents("resultCode"); } /** * @return string */ public function getMessageCode() { return $this->_getElementContents("code"); } /** * @return string */ public function getMessageText() { return $this->_getElementContents("text"); } /** * Grabs the contents of a unique element. * * @param string * @return string */ protected function _getElementContents($elementName) { $start = "<$elementName>"; $end = "</$elementName>"; if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) { return false; } else { $start_position = strpos($this->response, $start)+strlen($start); $end_position = strpos($this->response, $end); return substr($this->response, $start_position, $end_position-$start_position); } } } authorizenet/lib/deprecated/shared/AuthorizeNetTypes.php 0000644 00000025275 14736103100 0017566 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated All the classes in AuthorizeNetTypes are deprecated. * @deprecated Use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php */ /** * Classes for the various AuthorizeNet data types. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ /** * A class that contains all fields for a CIM Customer Profile. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCustomer { public $merchantCustomerId; public $description; public $email; public $paymentProfiles = array(); public $shipToList = array(); public $customerProfileId; } /** * A class that contains all fields for a CIM Address. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetAddress { public $firstName; public $lastName; public $company; public $address; public $city; public $state; public $zip; public $country; public $phoneNumber; public $faxNumber; public $customerAddressId; } /** * A class that contains all fields for a CIM Payment Profile. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetPaymentProfile { public $customerType; public $billTo; public $payment; public $customerPaymentProfileId; public function __construct() { $this->billTo = new AuthorizeNetAddress; $this->payment = new AuthorizeNetPayment; } } /** * A class that contains all fields for a CIM Payment Type. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetPayment { public $creditCard; public $bankAccount; public function __construct() { $this->creditCard = new AuthorizeNetCreditCard; $this->bankAccount = new AuthorizeNetBankAccount; } } /** * A class that contains all fields for a CIM Transaction. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetTransaction { public $amount; public $tax; public $shipping; public $duty; public $lineItems = array(); public $customerProfileId; public $customerPaymentProfileId; public $customerShippingAddressId; public $creditCardNumberMasked; public $bankRoutingNumberMasked; public $bankAccountNumberMasked; public $order; public $taxExempt; public $recurringBilling; public $cardCode; public $splitTenderId; public $approvalCode; public $transId; public function __construct() { $this->tax = (object)array(); $this->tax->amount = ""; $this->tax->name = ""; $this->tax->description = ""; $this->shipping = (object)array(); $this->shipping->amount = ""; $this->shipping->name = ""; $this->shipping->description = ""; $this->duty = (object)array(); $this->duty->amount = ""; $this->duty->name = ""; $this->duty->description = ""; // line items $this->order = (object)array(); $this->order->invoiceNumber = ""; $this->order->description = ""; $this->order->purchaseOrderNumber = ""; } } /** * A class that contains all fields for a CIM Transaction Line Item. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetLineItem { public $itemId; public $name; public $description; public $quantity; public $unitPrice; public $taxable; } /** * A class that contains all fields for a CIM Credit Card. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCreditCard { public $cardNumber; public $expirationDate; public $cardCode; } /** * A class that contains all fields for a CIM Bank Account. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetBankAccount { public $accountType; public $routingNumber; public $accountNumber; public $nameOnAccount; public $echeckType; public $bankName; } /** * A class that contains all fields for an AuthorizeNet ARB Subscription. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNet_Subscription { public $name; public $intervalLength; public $intervalUnit; public $startDate; public $totalOccurrences; public $trialOccurrences; public $amount; public $trialAmount; public $creditCardCardNumber; public $creditCardExpirationDate; public $creditCardCardCode; public $bankAccountAccountType; public $bankAccountRoutingNumber; public $bankAccountAccountNumber; public $bankAccountNameOnAccount; public $bankAccountEcheckType; public $bankAccountBankName; public $orderInvoiceNumber; public $orderDescription; public $customerId; public $customerEmail; public $customerPhoneNumber; public $customerFaxNumber; public $billToFirstName; public $billToLastName; public $billToCompany; public $billToAddress; public $billToCity; public $billToState; public $billToZip; public $billToCountry; public $shipToFirstName; public $shipToLastName; public $shipToCompany; public $shipToAddress; public $shipToCity; public $shipToState; public $shipToZip; public $shipToCountry; public function getXml() { $xml = "<subscription> <name>{$this->name}</name> <paymentSchedule> <interval> <length>{$this->intervalLength}</length> <unit>{$this->intervalUnit}</unit> </interval> <startDate>{$this->startDate}</startDate> <totalOccurrences>{$this->totalOccurrences}</totalOccurrences> <trialOccurrences>{$this->trialOccurrences}</trialOccurrences> </paymentSchedule> <amount>{$this->amount}</amount> <trialAmount>{$this->trialAmount}</trialAmount> <payment> <creditCard> <cardNumber>{$this->creditCardCardNumber}</cardNumber> <expirationDate>{$this->creditCardExpirationDate}</expirationDate> <cardCode>{$this->creditCardCardCode}</cardCode> </creditCard> <bankAccount> <accountType>{$this->bankAccountAccountType}</accountType> <routingNumber>{$this->bankAccountRoutingNumber}</routingNumber> <accountNumber>{$this->bankAccountAccountNumber}</accountNumber> <nameOnAccount>{$this->bankAccountNameOnAccount}</nameOnAccount> <echeckType>{$this->bankAccountEcheckType}</echeckType> <bankName>{$this->bankAccountBankName}</bankName> </bankAccount> </payment> <order> <invoiceNumber>{$this->orderInvoiceNumber}</invoiceNumber> <description>{$this->orderDescription}</description> </order> <customer> <id>{$this->customerId}</id> <email>{$this->customerEmail}</email> <phoneNumber>{$this->customerPhoneNumber}</phoneNumber> <faxNumber>{$this->customerFaxNumber}</faxNumber> </customer> <billTo> <firstName>{$this->billToFirstName}</firstName> <lastName>{$this->billToLastName}</lastName> <company>{$this->billToCompany}</company> <address>{$this->billToAddress}</address> <city>{$this->billToCity}</city> <state>{$this->billToState}</state> <zip>{$this->billToZip}</zip> <country>{$this->billToCountry}</country> </billTo> <shipTo> <firstName>{$this->shipToFirstName}</firstName> <lastName>{$this->shipToLastName}</lastName> <company>{$this->shipToCompany}</company> <address>{$this->shipToAddress}</address> <city>{$this->shipToCity}</city> <state>{$this->shipToState}</state> <zip>{$this->shipToZip}</zip> <country>{$this->shipToCountry}</country> </shipTo> </subscription>"; $xml_clean = ""; // Remove any blank child elements foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) { if (!preg_match('/><\//', $line)) { $xml_clean .= $line . "\n"; } } // Remove any blank parent elements $element_removed = 1; // Recursively repeat if a change is made while ($element_removed) { $element_removed = 0; if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) { $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean); $element_removed = 1; } } // Remove any blank lines // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean); return $xml_clean; } } /** * A class that contains all fields for an AuthorizeNet ARB SubscriptionList. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetGetSubscriptionList { public $searchType; public $sorting; public $paging; public function getXml() { $emptyString = ""; $sortingXml = (is_null($this->sorting)) ? $emptyString : $this->sorting->getXml(); $pagingXml = (is_null($this->paging)) ? $emptyString : $this->paging->getXml(); $xml = " <searchType>{$this->searchType}</searchType>" .$sortingXml .$pagingXml ; $xml_clean = ""; // Remove any blank child elements foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) { if (!preg_match('/><\//', $line)) { $xml_clean .= $line . "\n"; } } // Remove any blank parent elements $element_removed = 1; // Recursively repeat if a change is made while ($element_removed) { $element_removed = 0; if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) { $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean); $element_removed = 1; } } // Remove any blank lines // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean); return $xml_clean; } } class AuthorizeNetSubscriptionListPaging { public $limit; public $offset; public function getXml() { $xml = "<paging> <limit>{$this->limit}</limit> <offset>{$this->offset}</offset> </paging>"; return $xml; } } class AuthorizeNetSubscriptionListSorting { public $orderBy; public $orderDescending; public function getXml() { $xml = " <sorting> <orderBy>{$this->orderBy}</orderBy> <orderDescending>{$this->orderDescending}</orderDescending> </sorting>"; return $xml; } } authorizenet/lib/deprecated/shared/AuthorizeNetResponse.php 0000644 00000004437 14736103100 0020255 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated The Authorize.Net API has been reorganized to simplify & ease integration and to be more merchant focused * @deprecated AuthorizeNetRequest and it's derived classes are deprecated. * @deprecated Use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php */ trigger_error('AuthorizeNetResponse is deprecated, use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php .', E_USER_DEPRECATED); /** * Base class for the AuthorizeNet AIM & SIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetResponse */ /** * Parses an AuthorizeNet Response. * * @package AuthorizeNet * @subpackage AuthorizeNetResponse */ class AuthorizeNetResponse { const APPROVED = 1; const DECLINED = 2; const ERROR = 3; const HELD = 4; public $approved; public $declined; public $error; public $held; public $response_code; public $response_subcode; public $response_reason_code; public $response_reason_text; public $authorization_code; public $avs_response; public $transaction_id; public $invoice_number; public $description; public $amount; public $method; public $transaction_type; public $customer_id; public $first_name; public $last_name; public $company; public $address; public $city; public $state; public $zip_code; public $country; public $phone; public $fax; public $email_address; public $ship_to_first_name; public $ship_to_last_name; public $ship_to_company; public $ship_to_address; public $ship_to_city; public $ship_to_state; public $ship_to_zip_code; public $ship_to_country; public $tax; public $duty; public $freight; public $tax_exempt; public $purchase_order_number; public $md5_hash; public $card_code_response; public $cavv_response; // cardholder_authentication_verification_response public $account_number; public $card_type; public $split_tender_id; public $requested_amount; public $balance_on_card; public $response; // The response string from AuthorizeNet. } authorizenet/lib/deprecated/shared/AuthorizeNetRequest.php 0000644 00000010475 14736103100 0020106 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated The Authorize.Net API has been reorganized to simplify & ease integration and to be more merchant focused * @deprecated AuthorizeNetRequest and it's derived classes are deprecated. * @deprecated Use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php */ trigger_error('AuthorizeNetRequest is deprecated, use request/response classes in net\authorize\api\contract\v1 instead. Refer examples in https://github.com/AuthorizeNet/sample-code-php .', E_USER_DEPRECATED); use net\authorize\util\LogFactory; /** * Sends requests to the Authorize.Net gateways. * * @package AuthorizeNet * @subpackage AuthorizeNetRequest */ abstract class AuthorizeNetRequest { protected $_api_login; protected $_transaction_key; protected $_post_string; public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections. protected $_sandbox = true; protected $_logger = null; /** * Set the _post_string */ abstract protected function _setPostString(); /** * Handle the response string */ abstract protected function _handleResponse($string); /** * Get the post url. We need this because until 5.3 you * you could not access child constants in a parent class. */ abstract protected function _getPostUrl(); /** * Constructor. * * @param string $api_login_id The Merchant's API Login ID. * @param string $transaction_key The Merchant's Transaction Key. */ public function __construct($api_login_id = false, $transaction_key = false) { $this->_api_login = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); $this->_transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : "")); $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true); $this->_logger = LogFactory::getLog(get_class($this)); } /** * Alter the gateway url. * * @param bool $bool Use the Sandbox. */ public function setSandbox($bool) { $this->_sandbox = $bool; } /** * Set a log file. * * @param string $filepath Path to log file. */ public function setLogFile($filepath) { $this->_logger->setLogFile($filepath); } /** * Return the post string. * * @return string */ public function getPostString() { return $this->_post_string; } /** * Posts the request to AuthorizeNet & returns response. * * @return AuthorizeNetARB_Response The response. */ protected function _sendRequest() { $this->_setPostString(); $post_url = $this->_getPostUrl(); $curl_request = curl_init($post_url); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $this->_post_string); curl_setopt($curl_request, CURLOPT_HEADER, 0); curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); if ($this->VERIFY_PEER) { curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../ssl/cert.pem'); } else { if ($this->_logger) { $this->_logger->error("----Request----\nInvalid SSL option\n"); } return false; } if (preg_match('/xml/',$post_url)) { curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); } $response = curl_exec($curl_request); if ($this->_logger) { if ($curl_error = curl_error($curl_request)) { $this->_logger->error("----CURL ERROR----\n$curl_error\n\n"); } // Do not log requests that could contain CC info. $this->_logger->info("----Request----\n{$this->_post_string}\n"); $this->_logger->info("----Response----\n$response\n\n"); } curl_close($curl_request); return $this->_handleResponse($response); } } authorizenet/lib/deprecated/AuthorizeNetCP.php 0000644 00000022642 14736103100 0015511 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated We have reorganized and simplified the Authorize.Net API to ease integration and to focus on merchants' needs. * @deprecated We have deprecated AIM, ARB, CIM, and Reporting as separate options, in favor of AuthorizeNet::API. * @deprecated We have also deprecated SIM as a separate option, in favor of Accept Hosted. See https://developer.authorize.net/api/reference/features/accept_hosted.html for details on Accept Hosted. * @deprecated For details on the deprecation and replacement of legacy Authorize.Net methods, visit https://developer.authorize.net/api/upgrade_guide/. * @deprecated CP and CNP both use similar request structure (with differences in payment fields). * @deprecated For CP, refer examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions */ trigger_error('AuthorizeNetCP is deprecated, use AuthorizeNet::API instead. For CP, see examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions .', E_USER_DEPRECATED); /** * Easily interact with the Authorize.Net Card Present API. * * * @package AuthorizeNet * @subpackage AuthorizeNetCP * @link http://www.authorize.net/support/CP_guide.pdf Card Present Guide */ /** * Builds and sends an AuthorizeNet CP Request. * * @package AuthorizeNet * @subpackage AuthorizeNetCP */ class AuthorizeNetCP extends AuthorizeNetAIM { const LIVE_URL = 'https://cardpresent.authorize.net/gateway/transact.dll'; public $verify_x_fields = false; /** * Holds all the x_* name/values that will be posted in the request. * Default values are provided for best practice fields. */ protected $_x_post_fields = array( "cpversion" => "1.0", "delim_char" => ",", "encap_char" => "|", "market_type" => "2", "response_format" => "1", // 0 - XML, 1 - NVP ); /** * Device Types (x_device_type) * 1 = Unknown * 2 = Unattended Terminal * 3 = Self Service Terminal * 4 = Electronic Cash Register * 5 = Personal Computer- Based Terminal * 6 = AirPay * 7 = Wireless POS * 8 = Website * 9 = Dial Terminal * 10 = Virtual Terminal */ /** * Only used if merchant wants to send custom fields. */ private $_custom_fields = array(); /** * Strip sentinels and set track1 field. * * @param string $track1data */ public function setTrack1Data($track1data) { if (preg_match('/^%.*\?$/', $track1data)) { $this->track1 = substr($track1data, 1, -1); } else { $this->track1 = $track1data; } } /** * Strip sentinels and set track2 field. * * @param string $track2data */ public function setTrack2Data($track2data) { if (preg_match('/^;.*\?$/', $track2data)) { $this->track2 = substr($track2data, 1, -1); } else { $this->track2 = $track2data; } } /** * * * @param string $response * * @return AuthorizeNetAIM_Response */ protected function _handleResponse($response) { return new AuthorizeNetCP_Response($response, $this->_x_post_fields['delim_char'], $this->_x_post_fields['encap_char'], $this->_custom_fields); } } /** * Parses an AuthorizeNet Card Present Response. * * @package AuthorizeNet * @subpackage AuthorizeNetCP */ class AuthorizeNetCP_Response extends AuthorizeNetResponse { private $_response_array = array(); // An array with the split response. /** * Constructor. Parses the AuthorizeNet response string. * * @param string $response The response from the AuthNet server. * @param string $delimiter The delimiter used (default is ",") * @param string $encap_char The encap_char used (default is "|") * @param array $custom_fields Any custom fields set in the request. */ public function __construct($response, $delimiter, $encap_char, $custom_fields) { if ($response) { // If it's an XML response if (substr($response, 0, 5) == "<?xml") { $this->xml = @simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOWARNING); // Set all fields $this->version = array_pop(array_slice(explode('"', $response), 1,1)); $this->response_code = (string)$this->xml->ResponseCode; if ($this->response_code == 1) { $this->response_reason_code = (string)$this->xml->Messages->Message->Code; $this->response_reason_text = (string)$this->xml->Messages->Message->Description; } else { $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode; $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText; } $this->authorization_code = (string)$this->xml->AuthCode; $this->avs_code = (string)$this->xml->AVSResultCode; $this->card_code_response = (string)$this->xml->CVVResultCode; $this->transaction_id = (string)$this->xml->TransID; $this->md5_hash = (string)$this->xml->TransHash; $this->user_ref = (string)$this->xml->UserRef; $this->card_num = (string)$this->xml->AccountNumber; $this->card_type = (string)$this->xml->AccountType; $this->test_mode = (string)$this->xml->TestMode; $this->ref_trans_id = (string)$this->xml->RefTransID; } else { // If it's an NVP response // Split Array $this->response = $response; if ($encap_char) { $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); } else { $this->_response_array = explode($delimiter, $response); } /** * If AuthorizeNet doesn't return a delimited response. */ if (count($this->_response_array) < 10) { $this->approved = false; $this->error = true; $this->error_message = "Unrecognized response from AuthorizeNet: $response"; return; } // Set all fields $this->version = $this->_response_array[0]; $this->response_code = $this->_response_array[1]; $this->response_reason_code = $this->_response_array[2]; $this->response_reason_text = $this->_response_array[3]; $this->authorization_code = $this->_response_array[4]; $this->avs_code = $this->_response_array[5]; $this->card_code_response = $this->_response_array[6]; $this->transaction_id = $this->_response_array[7]; $this->md5_hash = $this->_response_array[8]; $this->user_ref = $this->_response_array[9]; $this->card_num = $this->_response_array[20]; $this->card_type = $this->_response_array[21]; $this->split_tender_id = isset($this->_response_array[22]) ? $this->_response_array[22] : NULL; $this->requested_amount = isset($this->_response_array[23]) ? $this->_response_array[23] : NULL; $this->approved_amount = isset($this->_response_array[24]) ? $this->_response_array[24] : NULL; $this->card_balance = isset($this->_response_array[25]) ? $this->_response_array[25] : NULL; } $this->approved = ($this->response_code == self::APPROVED); $this->declined = ($this->response_code == self::DECLINED); $this->error = ($this->response_code == self::ERROR); $this->held = ($this->response_code == self::HELD); if ($this->error) { $this->error_message = "AuthorizeNet Error: Response Code: ".$this->response_code." Response Reason Code: ".$this->response_reason_code." Response Reason Text: ".$this->response_reason_text." "; } } else { $this->approved = false; $this->error = true; $this->error_message = "Error connecting to AuthorizeNet"; } } /** * Is the MD5 provided correct? * * @param string $api_login_id * @param string $md5_setting * @return bool */ public function isAuthorizeNet($api_login_id = false, $md5_setting = false) { $amount = ($this->amount ? $this->amount : '0.00'); $api_login_id = ($api_login_id ? $api_login_id : AUTHORIZENET_API_LOGIN_ID); $md5_setting = ($md5_setting ? $md5_setting : AUTHORIZENET_MD5_SETTING); return ($this->md5_hash == strtoupper(md5($md5_setting . $api_login_id . $this->transaction_id . $amount))); } } authorizenet/lib/deprecated/AuthorizeNetARB.php 0000644 00000012411 14736103100 0015604 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated We have reorganized and simplified the Authorize.Net API to ease integration and to focus on merchants' needs. * @deprecated We have deprecated AIM, ARB, CIM, and Reporting as separate options, in favor of AuthorizeNet::API. * @deprecated We have also deprecated SIM as a separate option, in favor of Accept Hosted. See https://developer.authorize.net/api/reference/features/accept_hosted.html for details on Accept Hosted. * @deprecated For details on the deprecation and replacement of legacy Authorize.Net methods, visit https://developer.authorize.net/api/upgrade_guide/. * @deprecated For ARB, refer examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/RecurringBilling */ trigger_error('AuthorizeNetARB is deprecated, use AuthorizeNet::API instead. For ARB, see examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/RecurringBilling .', E_USER_DEPRECATED); /** * Easily interact with the Authorize.Net ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB * @link http://www.authorize.net/support/ARB_guide.pdf ARB Guide */ /** * A class to send a request to the ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetARB extends AuthorizeNetRequest { const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; private $_request_type; private $_request_payload; /** * Optional. Used if the merchant wants to set a reference ID. * * @param string $refId */ public function setRefId($refId) { $this->_request_payload = ($refId ? "<refId>$refId</refId>" : ""); } /** * Create an ARB subscription * * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function createSubscription(AuthorizeNet_Subscription $subscription) { $this->_request_type = "CreateSubscriptionRequest"; $this->_request_payload .= $subscription->getXml(); return $this->_sendRequest(); } /** * Update an ARB subscription * * @param int $subscriptionId * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function updateSubscription($subscriptionId, AuthorizeNet_Subscription $subscription) { $this->_request_type = "UpdateSubscriptionRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; $this->_request_payload .= $subscription->getXml(); return $this->_sendRequest(); } /** * Get status of a subscription * * @param int $subscriptionId * * @return AuthorizeNetARB_Response */ public function getSubscriptionStatus($subscriptionId) { $this->_request_type = "GetSubscriptionStatusRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; return $this->_sendRequest(); } /** * Cancel a subscription * * @param int $subscriptionId * * @return AuthorizeNetARB_Response */ public function cancelSubscription($subscriptionId) { $this->_request_type = "CancelSubscriptionRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; return $this->_sendRequest(); } /** * Create an ARB subscription * * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function getSubscriptionList(AuthorizeNetGetSubscriptionList $subscriptionList) { $this->_request_type = "GetSubscriptionListRequest"; $this->_request_payload .= $subscriptionList->getXml(); return $this->_sendRequest(); } /** * * * @param string $response * * @return AuthorizeNetARB_Response */ protected function _handleResponse($response) { return new AuthorizeNetARB_Response($response); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * Prepare the XML document for posting. */ protected function _setPostString() { $this->_post_string =<<<XML <?xml version="1.0" encoding="utf-8"?> <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>{$this->_api_login}</name> <transactionKey>{$this->_transaction_key}</transactionKey> </merchantAuthentication> {$this->_request_payload} </ARB{$this->_request_type}> XML; } } /** * A class to parse a response from the ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetARB_Response extends AuthorizeNetXMLResponse { /** * @return int */ public function getSubscriptionId() { return $this->_getElementContents("subscriptionId"); } /** * @return string */ public function getSubscriptionStatus() { return $this->_getElementContents("status"); } } authorizenet/lib/deprecated/README-DeprecatedSamples.md 0000644 00000014724 14736103100 0017000 0 ustar 00 Old Usage Examples (Of Deprecated SDK Functionality) ======================================= # This documentation in this directoary and the objects it documents have been deprecated **For the README for this repository, see `[README.md]`(/README.md) in the root level of the repository. For examples of how to interact with the current Authorize.Net API, see our new sample code GitHub repository at https://github.com/AuthorizeNet/sample-code-php.** **What follows is the old README pertaining to this deprecated functionality:** ## Requirements - PHP 5.3+ *(>=5.3.10 recommended)* - cURL PHP Extension - JSON PHP Extension - SimpleXML PHP Extension - An Authorize.Net Merchant Account or Sandbox Account. You can get a free sandbox account at http://developer.authorize.net/sandbox/ ## Autoloading [`Composer`](http://getcomposer.org) currently has a [MITM](https://github.com/composer/composer/issues/1074) security vulnerability. However, if you wish to use it, require its autoloader in your script or bootstrap file: ```php require 'vendor/autoload.php'; ``` *Note: you'll need a composer.json file with the following require section and to run `composer update`.* ```json "require": { "authorizenet/authorizenet": "~1.8" } ``` Alternatively, we provide a custom `SPL` autoloader: ```php require 'path/to/anet_php_sdk/autoload.php'; ``` ## Authentication To authenticate with the Authorize.Net API you will need to retrieve your API Login ID and Transaction Key from the [`Merchant Interface`](https://account.authorize.net/). You can find these details in the Settings section. If you need a sandbox account you can sign up for one really easily [`here`](https://developer.authorize.net/sandbox/). Once you have your keys simply plug them into the appropriate variables as per the samples below. ````php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); ```` ## Usage Examples See below for basic usage examples. View the `tests/` folder for more examples of each API. Additional documentation is in the `docs/` folder. ### AuthorizeNetAIM.php Quick Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); define("AUTHORIZENET_SANDBOX", true); $sale = new AuthorizeNetAIM; $sale->amount = "5.99"; $sale->card_num = '6011000000000012'; $sale->exp_date = '04/15'; $response = $sale->authorizeAndCapture(); if ($response->approved) { $transaction_id = $response->transaction_id; } ``` ### AuthorizeNetAIM.php Advanced Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); define("AUTHORIZENET_SANDBOX", true); $auth = new AuthorizeNetAIM; $auth->amount = "45.00"; // Use eCheck: $auth->setECheck( '121042882', '123456789123', 'CHECKING', 'Bank of Earth', 'Jane Doe', 'WEB' ); // Set multiple line items: $auth->addLineItem('item1', 'Golf tees', 'Blue tees', '2', '5.00', 'N'); $auth->addLineItem('item2', 'Golf shirt', 'XL', '1', '40.00', 'N'); // Set Invoice Number: $auth->invoice_num = time(); // Set a Merchant Defined Field: $auth->setCustomField("entrance_source", "Search Engine"); // Authorize Only: $response = $auth->authorizeOnly(); if ($response->approved) { $auth_code = $response->transaction_id; // Now capture: $capture = new AuthorizeNetAIM; $capture_response = $capture->priorAuthCapture($auth_code); // Now void: $void = new AuthorizeNetAIM; $void_response = $void->void($capture_response->transaction_id); } ``` ### AuthorizeNetARB.php Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); $subscription = new AuthorizeNet_Subscription; $subscription->name = "PHP Monthly Magazine"; $subscription->intervalLength = "1"; $subscription->intervalUnit = "months"; $subscription->startDate = "2011-03-12"; $subscription->totalOccurrences = "12"; $subscription->amount = "12.99"; $subscription->creditCardCardNumber = "6011000000000012"; $subscription->creditCardExpirationDate= "2018-10"; $subscription->creditCardCardCode = "123"; $subscription->billToFirstName = "Rasmus"; $subscription->billToLastName = "Doe"; // Create the subscription. $request = new AuthorizeNetARB; $response = $request->createSubscription($subscription); $subscription_id = $response->getSubscriptionId(); ``` ### AuthorizeNetCIM.php Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); $request = new AuthorizeNetCIM; // Create new customer profile $customerProfile = new AuthorizeNetCustomer; $customerProfile->description = "Description of customer"; $customerProfile->merchantCustomerId = time(); $customerProfile->email = "test@domain.com"; $response = $request->createCustomerProfile($customerProfile); if ($response->isOk()) { $customerProfileId = $response->getCustomerProfileId(); } ``` ### AuthorizeNetSIM.php Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_MD5_SETTING", ""); $message = new AuthorizeNetSIM; if ($message->isAuthorizeNet()) { $transactionId = $message->transaction_id; } ``` ### AuthorizeNetDPM.php Usage Example ```php $url = "http://YOUR_DOMAIN.com/direct_post.php"; $api_login_id = 'YOUR_API_LOGIN_ID'; $transaction_key = 'YOUR_TRANSACTION_KEY'; $md5_setting = 'YOUR_MD5_SETTING'; // Your MD5 Setting $amount = "5.99"; AuthorizeNetDPM::directPostDemo($url, $api_login_id, $transaction_key, $amount, $md5_setting); ``` ### AuthorizeNetCP.php Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); define("AUTHORIZENET_MD5_SETTING", ""); $sale = new AuthorizeNetCP; $sale->amount = '59.99'; $sale->device_type = '4'; $sale->setTrack1Data('%B4111111111111111^CARDUSER/JOHN^1803101000000000020000831000000?'); $response = $sale->authorizeAndCapture(); $trans_id = $response->transaction_id; ``` ### AuthorizeNetTD.php Usage Example ```php define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN"); define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY"); $request = new AuthorizeNetTD; $response = $request->getTransactionDetails("12345"); echo $response->xml->transaction->transactionStatus; ``` authorizenet/lib/deprecated/AuthorizeNetSIM.php 0000644 00000016117 14736103100 0015637 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated SIM is replaced by Accept Hosted https://developer.authorize.net/content/developer/en_us/api/reference/features/accept_hosted.html */ trigger_error('AuthorizeNetSIM is deprecated, use Accept Hosted instead: https://developer.authorize.net/content/developer/en_us/api/reference/features/accept_hosted.html. ', E_USER_DEPRECATED); /** * Easily use the Authorize.Net Server Integration Method(SIM). * * @package AuthorizeNet * @subpackage AuthorizeNetSIM * @link http://www.authorize.net/support/SIM_guide.pdf SIM Guide */ /** * Easily parse an AuthorizeNet SIM Response. * @package AuthorizeNet * @subpackage AuthorizeNetSIM */ class AuthorizeNetSIM extends AuthorizeNetResponse { // For ARB transactions public $subscription_id; public $subscription_paynum; /** * Constructor. * * @param string $api_login_id * @param string $md5_setting For verifying an Authorize.Net message. */ public function __construct($api_login_id = false, $md5_setting = false) { $this->api_login_id = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); $this->md5_setting = ($md5_setting ? $md5_setting : (defined('AUTHORIZENET_MD5_SETTING') ? AUTHORIZENET_MD5_SETTING : "")); $this->response = $_POST; // Set fields without x_ prefix foreach ($_POST as $key => $value) { $name = substr($key, 2); $this->$name = $value; } // Set some human readable fields $map = array( 'invoice_number' => 'x_invoice_num', 'transaction_type' => 'x_type', 'zip_code' => 'x_zip', 'email_address' => 'x_email', 'ship_to_zip_code' => 'x_ship_to_zip', 'account_number' => 'x_account_number', 'avs_response' => 'x_avs_code', 'authorization_code' => 'x_auth_code', 'transaction_id' => 'x_trans_id', 'customer_id' => 'x_cust_id', 'md5_hash' => 'x_MD5_Hash', 'card_code_response' => 'x_cvv2_resp_code', 'cavv_response' => 'x_cavv_response', ); foreach ($map as $key => $value) { $this->$key = (isset($_POST[$value]) ? $_POST[$value] : ""); } $this->approved = ($this->response_code == self::APPROVED); $this->declined = ($this->response_code == self::DECLINED); $this->error = ($this->response_code == self::ERROR); $this->held = ($this->response_code == self::HELD); } /** * Verify the request is AuthorizeNet. * * @return bool */ public function isAuthorizeNet() { return count($_POST) && $this->md5_hash && ($this->generateHash() == $this->md5_hash); } /** * Generates an Md5 hash to compare against Authorize.Net's. * * @return string Hash */ public function generateHash() { $amount = ($this->amount ? $this->amount : "0.00"); return strtoupper(md5($this->md5_setting . $this->api_login_id . $this->transaction_id . $amount)); } } /** * A helper class for using hosted order page. * * @package AuthorizeNet * @subpackage AuthorizeNetSIM */ class AuthorizeNetSIM_Form { public $x_address; public $x_amount; public $x_background_url; public $x_card_num; public $x_city; public $x_color_background; public $x_color_link; public $x_color_text; public $x_company; public $x_country; public $x_cust_id; public $x_customer_ip; public $x_description; public $x_delim_data; public $x_duplicate_window; public $x_duty; public $x_email; public $x_email_customer; public $x_fax; public $x_first_name; public $x_footer_email_receipt; public $x_footer_html_payment_form; public $x_footer_html_receipt; public $x_fp_hash; public $x_fp_sequence; public $x_fp_timestamp; public $x_freight; public $x_header_email_receipt; public $x_header_html_payment_form; public $x_header_html_receipt; public $x_invoice_num; public $x_last_name; public $x_line_item; public $x_login; public $x_logo_url; public $x_method; public $x_phone; public $x_po_num; public $x_receipt_link_method; public $x_receipt_link_text; public $x_receipt_link_url; public $x_recurring_billing; public $x_relay_response; public $x_relay_url; public $x_rename; public $x_ship_to_address; public $x_ship_to_company; public $x_ship_to_country; public $x_ship_to_city; public $x_ship_to_first_name; public $x_ship_to_last_name; public $x_ship_to_state; public $x_ship_to_zip; public $x_show_form; public $x_state; public $x_tax; public $x_tax_exempt; public $x_test_request; public $x_trans_id; public $x_type; public $x_version; public $x_zip; /** * Constructor * * @param array $fields Fields to set. */ public function __construct($fields = false) { // Set some best practice fields $this->x_relay_response = "FALSE"; $this->x_version = "3.1"; $this->x_delim_char = ","; $this->x_delim_data = "TRUE"; if ($fields) { foreach ($fields as $key => $value) { $this->$key = $value; } } } /** * Get a string of HTML hidden fields for use in a form. * * @return string */ public function getHiddenFieldString() { $array = (array)$this; $string = ""; foreach ($array as $key => $value) { if ($value) { $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'">'; } } return $string; } /** * Generates a fingerprint needed for a hosted order form or DPM. * * @param string $api_login_id Login ID. * @param string $transaction_key API key. * @param string $amount Amount of transaction. * @param string $fp_sequence An invoice number or random number. * @param string $fp_timestamp Timestamp. * @param string $fp_currency_code Currency Code * * @return string The fingerprint. */ public static function getFingerprint($api_login_id, $transaction_key, $amount, $fp_sequence, $fp_timestamp, $fp_currency_code = '') { $api_login_id = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); $transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : "")); if (function_exists('hash_hmac')) { return hash_hmac("md5", $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^" . $fp_currency_code, $transaction_key); } return bin2hex(mhash(MHASH_MD5, $api_login_id . "^" . $fp_sequence . "^" . $fp_timestamp . "^" . $amount . "^" . $fp_currency_code, $transaction_key)); } } authorizenet/lib/deprecated/AuthorizeNetAIM.php 0000644 00000045015 14736103100 0015614 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated We have reorganized and simplified the Authorize.Net API to ease integration and to focus on merchants' needs. * @deprecated We have deprecated AIM, ARB, CIM, and Reporting as separate options, in favor of AuthorizeNet::API. * @deprecated We have also deprecated SIM as a separate option, in favor of Accept Hosted. See https://developer.authorize.net/api/reference/features/accept_hosted.html for details on Accept Hosted. * @deprecated For details on the deprecation and replacement of legacy Authorize.Net methods, visit https://developer.authorize.net/api/upgrade_guide/. * @deprecated For AIM, refer examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions */ trigger_error('AuthorizeNetAIM is deprecated, use AuthorizeNet::API instead. For AIM, see examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions .', E_USER_DEPRECATED); /** * Easily interact with the Authorize.Net AIM API. * * * Example Authorize and Capture Transaction against the Sandbox: * <code> * <?php require_once 'AuthorizeNet.php' * $sale = new AuthorizeNetAIM; * $sale->setFields( * array( * 'amount' => '4.99', * 'card_num' => '411111111111111', * 'exp_date' => '0515' * ) * ); * $response = $sale->authorizeAndCapture(); * if ($response->approved) { * echo "Sale successful!"; } else { * echo $response->error_message; * } * ?> * </code> * * Note: To send requests to the live gateway, either define this: * define("AUTHORIZENET_SANDBOX", false); * -- OR -- * $sale = new AuthorizeNetAIM; * $sale->setSandbox(false); * * @package AuthorizeNet * @subpackage AuthorizeNetAIM * @link http://www.authorize.net/support/AIM_guide.pdf AIM Guide */ /** * Builds and sends an AuthorizeNet AIM Request. * * @package AuthorizeNet * @subpackage AuthorizeNetAIM */ class AuthorizeNetAIM extends AuthorizeNetRequest { const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; /** * Holds all the x_* name/values that will be posted in the request. * Default values are provided for best practice fields. */ protected $_x_post_fields = array( "version" => "3.1", "delim_char" => ",", "delim_data" => "TRUE", "relay_response" => "FALSE", "encap_char" => "|", ); /** * Only used if merchant wants to send multiple line items about the charge. */ private $_additional_line_items = array(); /** * Only used if merchant wants to send custom fields. */ private $_custom_fields = array(); /** * Checks to make sure a field is actually in the API before setting. * Set to false to skip this check. */ public $verify_x_fields = true; /** * A list of all fields in the AIM API. * Used to warn user if they try to set a field not offered in the API. */ private $_all_aim_fields = array("address","allow_partial_auth","amount", "auth_code","authentication_indicator", "bank_aba_code","bank_acct_name", "bank_acct_num","bank_acct_type","bank_check_number","bank_name", "card_code","card_num","cardholder_authentication_value","city","company", "country","cust_id","customer_ip","delim_char","delim_data","description", "duplicate_window","duty","echeck_type","email","email_customer", "encap_char","exp_date","fax","first_name","footer_email_receipt", "freight","header_email_receipt","invoice_num","last_name","line_item", "login","method","phone","po_num","recurring_billing","relay_response", "ship_to_address","ship_to_city","ship_to_company","ship_to_country", "ship_to_first_name","ship_to_last_name","ship_to_state","ship_to_zip", "split_tender_id","state","tax","tax_exempt","test_request","tran_key", "trans_id","type","version","zip" ); /** * Do an AUTH_CAPTURE transaction. * * Required "x_" fields: card_num, exp_date, amount * * @param string $amount The dollar amount to charge * @param string $card_num The credit card number * @param string $exp_date CC expiration date * * @return AuthorizeNetAIM_Response */ public function authorizeAndCapture($amount = false, $card_num = false, $exp_date = false) { ($amount ? $this->amount = $amount : null); ($card_num ? $this->card_num = $card_num : null); ($exp_date ? $this->exp_date = $exp_date : null); $this->type = "AUTH_CAPTURE"; return $this->_sendRequest(); } /** * Do a PRIOR_AUTH_CAPTURE transaction. * * Required "x_" field: trans_id(The transaction id of the prior auth, unless split * tender, then set x_split_tender_id manually.) * amount (only if lesser than original auth) * * @param string $trans_id Transaction id to charge * @param string $amount Dollar amount to charge if lesser than auth * * @return AuthorizeNetAIM_Response */ public function priorAuthCapture($trans_id = false, $amount = false) { ($trans_id ? $this->trans_id = $trans_id : null); ($amount ? $this->amount = $amount : null); $this->type = "PRIOR_AUTH_CAPTURE"; return $this->_sendRequest(); } /** * Do an AUTH_ONLY transaction. * * Required "x_" fields: card_num, exp_date, amount * * @param string $amount The dollar amount to charge * @param string $card_num The credit card number * @param string $exp_date CC expiration date * * @return AuthorizeNetAIM_Response */ public function authorizeOnly($amount = false, $card_num = false, $exp_date = false) { ($amount ? $this->amount = $amount : null); ($card_num ? $this->card_num = $card_num : null); ($exp_date ? $this->exp_date = $exp_date : null); $this->type = "AUTH_ONLY"; return $this->_sendRequest(); } /** * Do a VOID transaction. * * Required "x_" field: trans_id(The transaction id of the prior auth, unless split * tender, then set x_split_tender_id manually.) * * @param string $trans_id Transaction id to void * * @return AuthorizeNetAIM_Response */ public function void($trans_id = false) { ($trans_id ? $this->trans_id = $trans_id : null); $this->type = "VOID"; return $this->_sendRequest(); } /** * Do a CAPTURE_ONLY transaction. * * Required "x_" fields: auth_code, amount, card_num , exp_date * * @param string $auth_code The auth code * @param string $amount The dollar amount to charge * @param string $card_num The last 4 of credit card number * @param string $exp_date CC expiration date * * @return AuthorizeNetAIM_Response */ public function captureOnly($auth_code = false, $amount = false, $card_num = false, $exp_date = false) { ($auth_code ? $this->auth_code = $auth_code : null); ($amount ? $this->amount = $amount : null); ($card_num ? $this->card_num = $card_num : null); ($exp_date ? $this->exp_date = $exp_date : null); $this->type = "CAPTURE_ONLY"; return $this->_sendRequest(); } /** * Do a CREDIT transaction. * * Required "x_" fields: trans_id, amount, card_num (just the last 4) * * @param string $trans_id Transaction id to credit * @param string $amount The dollar amount to credit * @param string $card_num The last 4 of credit card number * * @return AuthorizeNetAIM_Response */ public function credit($trans_id = false, $amount = false, $card_num = false) { ($trans_id ? $this->trans_id = $trans_id : null); ($amount ? $this->amount = $amount : null); ($card_num ? $this->card_num = $card_num : null); $this->type = "CREDIT"; return $this->_sendRequest(); } /** * Alternative syntax for setting x_ fields. * * Usage: $sale->method = "echeck"; * * @param string $name * @param string $value */ public function __set($name, $value) { $this->setField($name, $value); } /** * Quickly set multiple fields. * * Note: The prefix x_ will be added to all fields. If you want to set a * custom field without the x_ prefix, use setCustomField or setCustomFields. * * @param array $fields Takes an array or object. */ public function setFields($fields) { $array = (array)$fields; foreach ($array as $key => $value) { $this->setField($key, $value); } } /** * Quickly set multiple custom fields. * * @param array $fields */ public function setCustomFields($fields) { $array = (array)$fields; foreach ($array as $key => $value) { $this->setCustomField($key, $value); } } /** * Add a line item. * * @param string $item_id * @param string $item_name * @param string $item_description * @param string $item_quantity * @param string $item_unit_price * @param string $item_taxable */ public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) { $line_item = ""; $delimiter = ""; foreach (func_get_args() as $key => $value) { $line_item .= $delimiter . preg_replace('/\|/', '_', $value); $delimiter = "<|>"; } $this->_additional_line_items[] = $line_item; } /** * Use ECHECK as payment type. */ public function setECheck($bank_aba_code, $bank_acct_num, $bank_acct_type, $bank_name, $bank_acct_name, $echeck_type = 'WEB') { $this->setFields( array( 'method' => 'echeck', 'bank_aba_code' => $bank_aba_code, 'bank_acct_num' => $bank_acct_num, 'bank_acct_type' => $bank_acct_type, 'bank_name' => $bank_name, 'bank_acct_name' => $bank_acct_name, 'echeck_type' => $echeck_type, ) ); } /** * Set an individual name/value pair. This will append x_ to the name * before posting. * * @param string $name * @param string $value */ public function setField($name, $value) { if ($this->verify_x_fields) { if (in_array($name, $this->_all_aim_fields)) { $this->_x_post_fields[$name] = $value; } else { throw new AuthorizeNetException("Error: no field $name exists in the AIM API. To set a custom field use setCustomField('field','value') instead."); } } else { $this->_x_post_fields[$name] = $value; } } /** * Set a custom field. Note: the x_ prefix will not be added to * your custom field if you use this method. * * @param string $name * @param string $value */ public function setCustomField($name, $value) { $this->_custom_fields[$name] = $value; } /** * Unset an x_ field. * * @param string $name Field to unset. */ public function unsetField($name) { unset($this->_x_post_fields[$name]); } /** * * * @param string $response * * @return AuthorizeNetAIM_Response */ protected function _handleResponse($response) { return new AuthorizeNetAIM_Response($response, $this->_x_post_fields['delim_char'], $this->_x_post_fields['encap_char'], $this->_custom_fields); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * Converts the x_post_fields array into a string suitable for posting. */ protected function _setPostString() { $this->_x_post_fields['login'] = $this->_api_login; $this->_x_post_fields['tran_key'] = $this->_transaction_key; $this->_post_string = ""; foreach ($this->_x_post_fields as $key => $value) { $this->_post_string .= "x_$key=" . urlencode($value) . "&"; } // Add line items foreach ($this->_additional_line_items as $key => $value) { $this->_post_string .= "x_line_item=" . urlencode($value) . "&"; } // Add custom fields foreach ($this->_custom_fields as $key => $value) { $this->_post_string .= "$key=" . urlencode($value) . "&"; } $this->_post_string = rtrim($this->_post_string, "& "); } } /** * Parses an AuthorizeNet AIM Response. * * @package AuthorizeNet * @subpackage AuthorizeNetAIM */ class AuthorizeNetAIM_Response extends AuthorizeNetResponse { private $_response_array = array(); // An array with the split response. /** * Constructor. Parses the AuthorizeNet response string. * * @param string $response The response from the AuthNet server. * @param string $delimiter The delimiter used (default is ",") * @param string $encap_char The encap_char used (default is "|") * @param array $custom_fields Any custom fields set in the request. */ public function __construct($response, $delimiter, $encap_char, $custom_fields) { if ($response) { // Split Array $this->response = $response; if ($encap_char) { $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); } else { $this->_response_array = explode($delimiter, $response); } /** * If AuthorizeNet doesn't return a delimited response. */ if (count($this->_response_array) < 10) { $this->approved = false; $this->error = true; $this->error_message = "Unrecognized response from AuthorizeNet: $response"; return; } // Set all fields $this->response_code = $this->_response_array[0]; $this->response_subcode = $this->_response_array[1]; $this->response_reason_code = $this->_response_array[2]; $this->response_reason_text = $this->_response_array[3]; $this->authorization_code = $this->_response_array[4]; $this->avs_response = $this->_response_array[5]; $this->transaction_id = $this->_response_array[6]; $this->invoice_number = $this->_response_array[7]; $this->description = $this->_response_array[8]; $this->amount = $this->_response_array[9]; $this->method = $this->_response_array[10]; $this->transaction_type = $this->_response_array[11]; $this->customer_id = $this->_response_array[12]; $this->first_name = $this->_response_array[13]; $this->last_name = $this->_response_array[14]; $this->company = $this->_response_array[15]; $this->address = $this->_response_array[16]; $this->city = $this->_response_array[17]; $this->state = $this->_response_array[18]; $this->zip_code = $this->_response_array[19]; $this->country = $this->_response_array[20]; $this->phone = $this->_response_array[21]; $this->fax = $this->_response_array[22]; $this->email_address = $this->_response_array[23]; $this->ship_to_first_name = $this->_response_array[24]; $this->ship_to_last_name = $this->_response_array[25]; $this->ship_to_company = $this->_response_array[26]; $this->ship_to_address = $this->_response_array[27]; $this->ship_to_city = $this->_response_array[28]; $this->ship_to_state = $this->_response_array[29]; $this->ship_to_zip_code = $this->_response_array[30]; $this->ship_to_country = $this->_response_array[31]; $this->tax = $this->_response_array[32]; $this->duty = $this->_response_array[33]; $this->freight = $this->_response_array[34]; $this->tax_exempt = $this->_response_array[35]; $this->purchase_order_number= $this->_response_array[36]; $this->md5_hash = $this->_response_array[37]; $this->card_code_response = $this->_response_array[38]; $this->cavv_response = $this->_response_array[39]; $this->account_number = $this->_response_array[50]; $this->card_type = $this->_response_array[51]; $this->split_tender_id = $this->_response_array[52]; $this->requested_amount = $this->_response_array[53]; $this->balance_on_card = $this->_response_array[54]; $this->approved = ($this->response_code == self::APPROVED); $this->declined = ($this->response_code == self::DECLINED); $this->error = ($this->response_code == self::ERROR); $this->held = ($this->response_code == self::HELD); // Set custom fields if ($count = count($custom_fields)) { $custom_fields_response = array_slice($this->_response_array, -$count-1, $count); $i = 0; foreach ($custom_fields as $key => $value) { $this->$key = $custom_fields_response[$i]; $i++; } } if ($this->error) { $this->error_message = "AuthorizeNet Error: Response Code: ".$this->response_code." Response Subcode: ".$this->response_subcode." Response Reason Code: ".$this->response_reason_code." Response Reason Text: ".$this->response_reason_text." "; } } else { $this->approved = false; $this->error = true; $this->error_message = "Error connecting to AuthorizeNet"; } } } authorizenet/lib/deprecated/AuthorizeNetDPM.php 0000644 00000023027 14736103100 0015625 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated Direct Post Method is replaced by Accept.JS https://developer.authorize.net/api/reference/features/acceptjs.html * @deprecated Refer sample accept application: https://github.com/AuthorizeNet/accept-sample-app */ trigger_error('AuthorizeNetDPM is deprecated, use Accept.JS instead. Refer sample accept application: https://github.com/AuthorizeNet/accept-sample-app .', E_USER_DEPRECATED); /** * Demonstrates the Direct Post Method. * * To implement the Direct Post Method you need to implement 3 steps: * * Step 1: Add necessary hidden fields to your checkout form and make your form is set to post to AuthorizeNet. * * Step 2: Receive a response from AuthorizeNet, do your business logic, and return * a relay response snippet with a url to redirect the customer to. * * Step 3: Show a receipt page to your customer. * * This class is more for demonstration purposes than actual production use. * * * @package AuthorizeNet * @subpackage AuthorizeNetDPM */ /** * A class that demonstrates the DPM method. * * @package AuthorizeNet * @subpackage AuthorizeNetDPM */ class AuthorizeNetDPM extends AuthorizeNetSIM_Form { const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; /** * Implements all 3 steps of the Direct Post Method for demonstration * purposes. */ public static function directPostDemo($url, $api_login_id, $transaction_key, $amount = "0.00", $md5_setting = "") { // Step 1: Show checkout form to customer. if (!count($_POST) && !count($_GET)) { $fp_sequence = time(); // Any sequential number like an invoice number. echo AuthorizeNetDPM::getCreditCardForm($amount, $fp_sequence, $url, $api_login_id, $transaction_key); } // Step 2: Handle AuthorizeNet Transaction Result & return snippet. elseif (count($_POST)) { $response = new AuthorizeNetSIM($api_login_id, $md5_setting); if ($response->isAuthorizeNet()) { if ($response->approved) { // Do your processing here. $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; } else { // Redirect to error page. $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text; } // Send the Javascript back to AuthorizeNet, which will redirect user back to your site. echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url); } else { echo "Error -- not AuthorizeNet. Check your MD5 Setting."; } } // Step 3: Show receipt page to customer. elseif (!count($_POST) && count($_GET)) { if ($_GET['response_code'] == 1) { echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']); } else { echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']); } } } /** * A snippet to send to AuthorizeNet to redirect the user back to the * merchant's server. Use this on your relay response page. * * @param string $redirect_url Where to redirect the user. * * @return string */ public static function getRelayResponseSnippet($redirect_url) { return "<html><head><script language=\"javascript\"> <!-- window.location=\"{$redirect_url}\"; //--> </script> </head><body><noscript><meta http-equiv=\"refresh\" content=\"1;url={$redirect_url}\"></noscript></body></html>"; } /** * Generate a sample form for use in a demo Direct Post implementation. * * @param string $amount Amount of the transaction. * @param string $fp_sequence Sequential number(ie. Invoice #) * @param string $relay_response_url The Relay Response URL * @param string $api_login_id Your API Login ID * @param string $transaction_key Your API Tran Key. * @param bool $test_mode Use the sandbox? * @param bool $prefill Prefill sample values(for test purposes). * * @return string */ public static function getCreditCardForm($amount, $fp_sequence, $relay_response_url, $api_login_id, $transaction_key, $test_mode = true, $prefill = true) { $time = time(); $fp = self::getFingerprint($api_login_id, $transaction_key, $amount, $fp_sequence, $time); $sim = new AuthorizeNetSIM_Form( array( 'x_amount' => $amount, 'x_fp_sequence' => $fp_sequence, 'x_fp_hash' => $fp, 'x_fp_timestamp' => $time, 'x_relay_response'=> "TRUE", 'x_relay_url' => $relay_response_url, 'x_login' => $api_login_id, ) ); $hidden_fields = $sim->getHiddenFieldString(); $post_url = ($test_mode ? self::SANDBOX_URL : self::LIVE_URL); $form = ' <style> fieldset { overflow: auto; border: 0; margin: 0; padding: 0; } fieldset div { float: left; } fieldset.centered div { text-align: center; } label { color: #183b55; display: block; margin-bottom: 5px; } label img { display: block; margin-bottom: 5px; } input.text { border: 1px solid #bfbab4; margin: 0 4px 8px 0; padding: 6px; color: #1e1e1e; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: inset 0px 5px 5px #eee; -moz-box-shadow: inset 0px 5px 5px #eee; box-shadow: inset 0px 5px 5px #eee; } .submit { display: block; background-color: #76b2d7; border: 1px solid #766056; color: #3a2014; margin: 13px 0; padding: 8px 16px; -webkit-border-radius: 12px; -moz-border-radius: 12px; border-radius: 12px; font-size: 14px; -webkit-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); } </style> <form method="post" action="'.$post_url.'"> '.$hidden_fields.' <fieldset> <div> <label>Credit Card Number</label> <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input> </div> <div> <label>Exp.</label> <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input> </div> <div> <label>CCV</label> <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input> </div> </fieldset> <fieldset> <div> <label>First Name</label> <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input> </div> <div> <label>Last Name</label> <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input> </div> </fieldset> <fieldset> <div> <label>Address</label> <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input> </div> <div> <label>City</label> <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input> </div> </fieldset> <fieldset> <div> <label>State</label> <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input> </div> <div> <label>Zip Code</label> <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input> </div> <div> <label>Country</label> <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input> </div> </fieldset> <input type="submit" value="BUY" class="submit buy"> </form>'; return $form; } } authorizenet/lib/deprecated/AuthorizeNetTD.php 0000644 00000017142 14736103100 0015515 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated We have reorganized and simplified the Authorize.Net API to ease integration and to focus on merchants' needs. * @deprecated We have deprecated AIM, ARB, CIM, and Reporting as separate options, in favor of AuthorizeNet::API. * @deprecated We have also deprecated SIM as a separate option, in favor of Accept Hosted. See https://developer.authorize.net/api/reference/features/accept_hosted.html for details on Accept Hosted. * @deprecated For details on the deprecation and replacement of legacy Authorize.Net methods, visit https://developer.authorize.net/api/upgrade_guide/. * @deprecated For Transaction Reporting, refer examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/TransactionReporting */ trigger_error('AuthorizeNetTD is deprecated, use AuthorizeNet::API instead. For TD, see examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/TransactionReporting .', E_USER_DEPRECATED); /** * Easily interact with the Authorize.Net Transaction Details XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetTD * @link http://www.authorize.net/support/ReportingGuide_XML.pdf Transaction Details XML Guide */ /** * A class to send a request to the Transaction Details XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetTD */ class AuthorizeNetTD extends AuthorizeNetRequest { const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; private $_xml; /** * This function returns information about a settled batch: Batch ID, Settlement Time, & * Settlement State. If you specify includeStatistics, you also receive batch statistics * by payment type. * * * The detault date range is one day (the previous 24 hour period). The maximum date range is 31 * days. The merchant time zone is taken into consideration when calculating the batch date range, * unless the Z is specified in the first and last settlement date * * @param bool $includeStatistics * @param string $firstSettlementDate // yyyy-mmddTHH:MM:SS * @param string $lastSettlementDate // yyyy-mmddTHH:MM:SS * @param bool $utc // Use UTC instead of merchant time zone setting * * @return AuthorizeNetTD_Response */ public function getSettledBatchList($includeStatistics = false, $firstSettlementDate = false, $lastSettlementDate = false, $utc = true) { $utc = ($utc ? "Z" : ""); $this->_constructXml("getSettledBatchListRequest"); ($includeStatistics ? $this->_xml->addChild("includeStatistics", $includeStatistics) : null); ($firstSettlementDate ? $this->_xml->addChild("firstSettlementDate", $firstSettlementDate . $utc) : null); ($lastSettlementDate ? $this->_xml->addChild("lastSettlementDate", $lastSettlementDate . $utc) : null); return $this->_sendRequest(); } /** * Return all settled batches for a certain month. * * @param int $month * @param int $year * * @return AuthorizeNetTD_Response */ public function getSettledBatchListForMonth($month = false, $year = false) { $month = ($month ? $month : date('m')); $year = ($year ? $year : date('Y')); $firstSettlementDate = substr(date('c',mktime(0, 0, 0, $month, 1, $year)),0,-6); $lastSettlementDate = substr(date('c',mktime(0, 0, 0, $month+1, 0, $year)),0,-6); return $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); } /** * This function returns limited transaction details for a specified batch ID * * @param int $batchId * * @return AuthorizeNetTD_Response */ public function getTransactionList($batchId) { $this->_constructXml("getTransactionListRequest"); $this->_xml->addChild("batchId", $batchId); return $this->_sendRequest(); } /** * Return all transactions for a certain day. * * @param int $month * @param int $day * @param int $year * * @return array Array of SimpleXMLElments */ public function getTransactionsForDay($month = false, $day = false, $year = false) { $transactions = array(); $month = ($month ? $month : date('m')); $day = ($day ? $day : date('d')); $year = ($year ? $year : date('Y')); $firstSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); $lastSettlementDate = substr(date('c',mktime(0, 0, 0, (int)$month, (int)$day, (int)$year)),0,-6); $response = $this->getSettledBatchList(true, $firstSettlementDate, $lastSettlementDate); $batches = $response->xpath("batchList/batch"); foreach ($batches as $batch) { $batch_id = (string)$batch->batchId; $request = new AuthorizeNetTD; $tran_list = $request->getTransactionList($batch_id); $transactions = array_merge($transactions, $tran_list->xpath("transactions/transaction")); } return $transactions; } /** * This function returns full transaction details for a specified transaction ID. * * @param int $transId * * @return AuthorizeNetTD_Response */ public function getTransactionDetails($transId) { $this->_constructXml("getTransactionDetailsRequest"); $this->_xml->addChild("transId", $transId); return $this->_sendRequest(); } /** * This function returns statistics about the settled batch specified by $batchId. * * @param int $batchId * * @return AuthorizeNetTD_Response */ public function getBatchStatistics($batchId) { $this->_constructXml("getBatchStatisticsRequest"); $this->_xml->addChild("batchId", $batchId); return $this->_sendRequest(); } /** * This function returns the last 1000 unsettled transactions. * * * @return AuthorizeNetTD_Response */ public function getUnsettledTransactionList() { $this->_constructXml("getUnsettledTransactionListRequest"); return $this->_sendRequest(); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * * * @param string $response * * @return AuthorizeNetTransactionDetails_Response */ protected function _handleResponse($response) { return new AuthorizeNetTD_Response($response); } /** * Prepare the XML post string. */ protected function _setPostString() { $this->_post_string = $this->_xml->asXML(); } /** * Start the SimpleXMLElement that will be posted. * * @param string $request_type The action to be performed. */ private function _constructXml($request_type) { $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; $this->_xml = @new SimpleXMLElement($string); $merchant = $this->_xml->addChild('merchantAuthentication'); $merchant->addChild('name',$this->_api_login); $merchant->addChild('transactionKey',$this->_transaction_key); } } /** * A class to parse a response from the Transaction Details XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetTD */ class AuthorizeNetTD_Response extends AuthorizeNetXMLResponse { } authorizenet/lib/deprecated/AuthorizeNetCIM.php 0000644 00000044732 14736103100 0015623 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated We have reorganized and simplified the Authorize.Net API to ease integration and to focus on merchants' needs. * @deprecated We have deprecated AIM, ARB, CIM, and Reporting as separate options, in favor of AuthorizeNet::API. * @deprecated We have also deprecated SIM as a separate option, in favor of Accept Hosted. See https://developer.authorize.net/api/reference/features/accept_hosted.html for details on Accept Hosted. * @deprecated For details on the deprecation and replacement of legacy Authorize.Net methods, visit https://developer.authorize.net/api/upgrade_guide/. * @deprecated For CIM, refer examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/CustomerProfiles */ trigger_error('AuthorizeNetCIM is deprecated, use AuthorizeNet::API instead. For CIM, see examples in https://github.com/AuthorizeNet/sample-code-php/tree/master/CustomerProfiles .', E_USER_DEPRECATED); /** * Easily interact with the Authorize.Net CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM * @link http://www.authorize.net/support/CIM_XML_guide.pdf CIM XML Guide */ /** * A class to send a request to the CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCIM extends AuthorizeNetRequest { const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; private $_xml; private $_refId = false; private $_validationMode = "none"; // "none","testMode","liveMode" private $_extraOptions; private $_transactionTypes = array( 'AuthOnly', 'AuthCapture', 'CaptureOnly', 'PriorAuthCapture', 'Refund', 'Void', ); /** * Optional. Used if the merchant wants to set a reference ID. * * @param string $refId */ public function setRefId($refId) { $this->_refId = $refId; } /** * Create a customer profile. * * @param AuthorizeNetCustomer $customerProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function createCustomerProfile($customerProfile, $validationMode = "none") { $this->_validationMode = $validationMode; $this->_constructXml("createCustomerProfileRequest"); $profile = $this->_xml->addChild("profile"); $this->_addObject($profile, $customerProfile); return $this->_sendRequest(); } /** * Create a customer payment profile. * * @param int $customerProfileId * @param AuthorizeNetPaymentProfile $paymentProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function createCustomerPaymentProfile($customerProfileId, $paymentProfile, $validationMode = "none") { $this->_validationMode = $validationMode; $this->_constructXml("createCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $profile = $this->_xml->addChild("paymentProfile"); $this->_addObject($profile, $paymentProfile); return $this->_sendRequest(); } /** * Create a shipping address. * * @param int $customerProfileId * @param AuthorizeNetAddress $shippingAddress * * @return AuthorizeNetCIM_Response */ public function createCustomerShippingAddress($customerProfileId, $shippingAddress) { $this->_constructXml("createCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $address = $this->_xml->addChild("address"); $this->_addObject($address, $shippingAddress); return $this->_sendRequest(); } /** * Create a transaction. * * @param string $transactionType * @param AuthorizeNetTransaction $transaction * @param string $extraOptionsString * * @return AuthorizeNetCIM_Response */ public function createCustomerProfileTransaction($transactionType, $transaction, $extraOptionsString = "") { $this->_constructXml("createCustomerProfileTransactionRequest"); $transactionParent = $this->_xml->addChild("transaction"); $transactionChild = $transactionParent->addChild("profileTrans" . $transactionType); $this->_addObject($transactionChild, $transaction); $this->_extraOptions = $extraOptionsString . "x_encap_char=|"; return $this->_sendRequest(); } /** * Delete a customer profile. * * @param int $customerProfileId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerProfile($customerProfileId) { $this->_constructXml("deleteCustomerProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); return $this->_sendRequest(); } /** * Delete a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId) { $this->_constructXml("deleteCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); return $this->_sendRequest(); } /** * Delete a shipping address. * * @param int $customerProfileId * @param int $customerAddressId * * @return AuthorizeNetCIM_Response */ public function deleteCustomerShippingAddress($customerProfileId, $customerAddressId) { $this->_constructXml("deleteCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerAddressId", $customerAddressId); return $this->_sendRequest(); } /** * Get all customer profile ids. * * @return AuthorizeNetCIM_Response */ public function getCustomerProfileIds() { $this->_constructXml("getCustomerProfileIdsRequest"); return $this->_sendRequest(); } /** * Get a customer profile. * * @param int $customerProfileId * * @return AuthorizeNetCIM_Response */ public function getCustomerProfile($customerProfileId, $unmaskExpirationDate = false) { $this->_constructXml("getCustomerProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); if ( $unmaskExpirationDate ) { $this->_xml->addChild("unmaskExpirationDate", true); } return $this->_sendRequest(); } /** * Get a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * @param boolean $unmaskExpirationDate * * @return AuthorizeNetCIM_Response */ public function getCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $unmaskExpirationDate = false) { $this->_constructXml("getCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerPaymentProfileId", $customerPaymentProfileId); if ( $unmaskExpirationDate ) { $this->_xml->addChild("unmaskExpirationDate", true); } return $this->_sendRequest(); } /** * Get a shipping address. * * @param int $customerProfileId * @param int $customerAddressId * * @return AuthorizeNetCIM_Response */ public function getCustomerShippingAddress($customerProfileId, $customerAddressId) { $this->_constructXml("getCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $this->_xml->addChild("customerAddressId", $customerAddressId); return $this->_sendRequest(); } /** * Update a profile. * * @param int $customerProfileId * @param AuthorizeNetCustomer $customerProfile * * @return AuthorizeNetCIM_Response */ public function updateCustomerProfile($customerProfileId, $customerProfile) { $this->_constructXml("updateCustomerProfileRequest"); $customerProfile->customerProfileId = $customerProfileId; $profile = $this->_xml->addChild("profile"); $this->_addObject($profile, $customerProfile); return $this->_sendRequest(); } /** * Update a payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * @param AuthorizeNetPaymentProfile $paymentProfile * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function updateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $paymentProfile, $validationMode = "none") { $this->_validationMode = $validationMode; $this->_constructXml("updateCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $paymentProfile->customerPaymentProfileId = $customerPaymentProfileId; $profile = $this->_xml->addChild("paymentProfile"); $this->_addObject($profile, $paymentProfile); return $this->_sendRequest(); } /** * Update a shipping address. * * @param int $customerProfileId * @param int $customerShippingAddressId * @param AuthorizeNetAddress $shippingAddress * * @return AuthorizeNetCIM_Response */ public function updateCustomerShippingAddress($customerProfileId, $customerShippingAddressId, $shippingAddress) { $this->_constructXml("updateCustomerShippingAddressRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); $shippingAddress->customerAddressId = $customerShippingAddressId; $sa = $this->_xml->addChild("address"); $this->_addObject($sa, $shippingAddress); return $this->_sendRequest(); } /** * Update the status of an existing order that contains multiple transactions with the same splitTenderId. * * @param int $splitTenderId * @param string $splitTenderStatus * * @return AuthorizeNetCIM_Response */ public function updateSplitTenderGroup($splitTenderId, $splitTenderStatus) { $this->_constructXml("updateSplitTenderGroupRequest"); $this->_xml->addChild("splitTenderId", $splitTenderId); $this->_xml->addChild("splitTenderStatus", $splitTenderStatus); return $this->_sendRequest(); } /** * Validate a customer payment profile. * * @param int $customerProfileId * @param int $customerPaymentProfileId * @param int $customerShippingAddressId * @param int $cardCode * @param string $validationMode * * @return AuthorizeNetCIM_Response */ public function validateCustomerPaymentProfile($customerProfileId, $customerPaymentProfileId, $customerShippingAddressId, $cardCode, $validationMode = "testMode") { $this->_validationMode = $validationMode; $this->_constructXml("validateCustomerPaymentProfileRequest"); $this->_xml->addChild("customerProfileId",$customerProfileId); $this->_xml->addChild("customerPaymentProfileId",$customerPaymentProfileId); $this->_xml->addChild("customerShippingAddressId",$customerShippingAddressId); $this->_xml->addChild("cardCode",$cardCode); return $this->_sendRequest(); } /** * Get hosted profile page request token * * @param string $customerProfileId * @param mixed $settings * * @return AuthorizeNetCIM_Response */ public function getHostedProfilePageRequest($customerProfileId, $settings=0) { $this->_constructXml("getHostedProfilePageRequest"); $this->_xml->addChild("customerProfileId", $customerProfileId); if (!empty($settings)) { $hostedSettings = $this->_xml->addChild("hostedProfileSettings"); foreach ($settings as $key => $val) { $setting = $hostedSettings->addChild("setting"); $setting->addChild("settingName", $key); $setting->addChild("settingValue", $val); } } return $this->_sendRequest(); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * * * @param string $response * * @return AuthorizeNetCIM_Response */ protected function _handleResponse($response) { return new AuthorizeNetCIM_Response($response); } /** * Prepare the XML post string. */ protected function _setPostString() { ($this->_validationMode != "none" ? $this->_xml->addChild('validationMode',$this->_validationMode) : ""); $this->_post_string = $this->_xml->asXML(); // Add extraOptions CDATA if ($this->_extraOptions) { $this->_xml->addChild("extraOptions"); $this->_post_string = str_replace(array("<extraOptions></extraOptions>","<extraOptions/>"),'<extraOptions><![CDATA[' . $this->_extraOptions . ']]></extraOptions>', $this->_xml->asXML()); $this->_extraOptions = false; } // Blank out our validation mode, so that we don't include it in calls that // don't use it. $this->_validationMode = "none"; } /** * Start the SimpleXMLElement that will be posted. * * @param string $request_type The action to be performed. */ private function _constructXml($request_type) { $string = '<?xml version="1.0" encoding="utf-8"?><'.$request_type.' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"></'.$request_type.'>'; $this->_xml = @new SimpleXMLElement($string); $merchant = $this->_xml->addChild('merchantAuthentication'); $merchant->addChild('name',$this->_api_login); $merchant->addChild('transactionKey',$this->_transaction_key); ($this->_refId ? $this->_xml->addChild('refId',$this->_refId) : ""); } /** * Add an object to an SimpleXMLElement parent element. * * @param SimpleXMLElement $destination The parent element. * @param Object $object An object, array or value. */ private function _addObject($destination, $object) { $array = (array)$object; foreach ($array as $key => $value) { if ($value && !is_object($value)) { if (is_array($value) && count($value)) { foreach ($value as $index => $item) { $items = $destination->addChild($key); $this->_addObject($items, $item); } } else { $destination->addChild($key,$value); } } elseif (is_object($value) && self::_notEmpty($value)) { $dest = $destination->addChild($key); $this->_addObject($dest, $value); } } } /** * Checks whether an array or object contains any values. * * @param Object $object * * @return bool */ private static function _notEmpty($object) { $array = (array)$object; foreach ($array as $key => $value) { if ($value && !is_object($value)) { return true; } elseif (is_object($value)) { if (self::_notEmpty($value)) { return true; } } } return false; } } /** * A class to parse a response from the CIM XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCIM_Response extends AuthorizeNetXMLResponse { /** * @return AuthorizeNetAIM_Response */ public function getTransactionResponse() { return new AuthorizeNetAIM_Response($this->_getElementContents("directResponse"), ",", "|", array()); } /** * @return array Array of AuthorizeNetAIM_Response objects for each payment profile. */ public function getValidationResponses() { $responses = (array)$this->xml->validationDirectResponseList; $return = array(); foreach ((array)$responses["string"] as $response) { $return[] = new AuthorizeNetAIM_Response($response, ",", "", array()); } return $return; } /** * @return AuthorizeNetAIM_Response */ public function getValidationResponse() { return new AuthorizeNetAIM_Response($this->_getElementContents("validationDirectResponse"), ",", "|", array()); } /** * @return array */ public function getCustomerProfileIds() { $ids = (array)$this->xml->ids; if(!empty($ids)) return $ids["numericString"]; else return $ids; } /** * @return array */ public function getCustomerPaymentProfileIds() { $ids = (array)$this->xml->customerPaymentProfileIdList; if(!empty($ids)) return $ids["numericString"]; else return $ids; } /** * @return array */ public function getCustomerShippingAddressIds() { $ids = (array)$this->xml->customerShippingAddressIdList; if(!empty($ids)) return $ids["numericString"]; else return $ids; } /** * @return string */ public function getCustomerAddressId() { return $this->_getElementContents("customerAddressId"); } /** * @return string */ public function getCustomerProfileId() { return $this->_getElementContents("customerProfileId"); } /** * @return string */ public function getPaymentProfileId() { return $this->_getElementContents("customerPaymentProfileId"); } } authorizenet/lib/deprecated/AuthorizeNetSOAP.php 0000644 00000006317 14736103100 0015752 0 ustar 00 <?php /** * @deprecated since version 1.9.8 * @deprecated AuthorizeNet SOAP is replaced by XMP APIs https://developer.authorize.net/api/reference/index.html#payment-transactions * @deprecated Refer sample codes : https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions */ trigger_error('AuthorizeNetSOAP is deprecated, use XML APIs instead. Refer sample codes : https://github.com/AuthorizeNet/sample-code-php/tree/master/PaymentTransactions .', E_USER_DEPRECATED); /** * A simple wrapper for the SOAP API as well as a helper function * to generate a documentation file from the WSDL. * * @package AuthorizeNet * @subpackage AuthorizeNetSoap */ /** * A simple wrapper for the SOAP API as well as a helper function * to generate a documentation file from the WSDL. * * @package AuthorizeNet * @subpackage AuthorizeNetSoap * @todo Make the doc file a usable class. */ class AuthorizeNetSOAP extends SoapClient { const WSDL_URL = "https://api2.authorize.net/soap/v1/Service.asmx?WSDL"; const LIVE_URL = "https://api2.authorize.net/soap/v1/Service.asmx"; const SANDBOX_URL = "https://apitest.authorize.net/soap/v1/Service.asmx"; public $sandbox; /** * Constructor */ public function __construct() { parent::__construct(self::WSDL_URL); $this->__setLocation(self::SANDBOX_URL); } /** * Switch between the sandbox or production gateway. * * @param bool */ public function setSandbox($bool) { $this->__setLocation(($bool ? self::SANDBOX_URL : self::LIVE_URL)); } /** * Get all types as PHP Code. * @return string */ public function getSoapTypes() { $string = ""; $types = $this->__getTypes(); foreach ($types as $type) { if (preg_match("/struct /",$type)) { $type = preg_replace("/struct /","class ",$type); $type = preg_replace("/ (\w+) (\w+);/"," // $1\n public \$$2;",$type); $string .= $type ."\n"; } } return $string; } /** * Get all methods as PHP Code. * @return string */ public function getSoapMethods() { $string = ""; $functions = array(); $methods = $this->__getFunctions(); foreach ($methods as $index => $method) { $sig = explode(" ", $method, 2); if (!isset($functions[$sig[1]])) { $string .= " /**\n * @return {$sig[0]}\n */\n public function {$sig[1]} {}\n\n"; $functions[$sig[1]] = true; } } return $string; } /** * Create a file from the WSDL for reference. */ public function saveSoapDocumentation($path) { $string = "<?php\n"; $string .= "/**\n"; $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n"; $string .= " * Generated " . date("m/d/Y") . "\n"; $string .= " */\n"; $string .= "class AuthorizeNetSOAP\n"; $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>"; return file_put_contents($path, $string); } } authorizenet/lib/shared/AuthorizeNetException.php 0000644 00000000313 14736103100 0016302 0 ustar 00 <?php /** * AuthorizeNetException.php * * @package AuthorizeNet */ /** * Exception class for AuthorizeNet PHP SDK. * * @package AuthorizeNet */ class AuthorizeNetException extends Exception { } authorizenet/lib/shared/AuthorizeNetXMLResponse.php 0000644 00000005712 14736103100 0016533 0 ustar 00 <?php /** * Base class for the AuthorizeNet ARB & CIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetXML */ /** * Base class for the AuthorizeNet ARB & CIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetXML */ class AuthorizeNetXMLResponse { public $xml; // Holds a SimpleXML Element with response. /** * Constructor. Parses the AuthorizeNet response string. * * @param string $response The response from the AuthNet server. */ public function __construct($response) { $this->response = $response; if ($response) { $this->xml = @simplexml_load_string($response,'SimpleXMLElement', LIBXML_NOWARNING); // Remove namespaces for use with XPath. $this->xpath_xml = @simplexml_load_string(preg_replace('/ xmlns:xsi[^>]+/','',$response),'SimpleXMLElement', LIBXML_NOWARNING); } } /** * Was the transaction successful? * * @return bool */ public function isOk() { return ($this->getResultCode() == "Ok"); } /** * Run an xpath query on the cleaned XML response * * @param string $path * @return array Returns an array of SimpleXMLElement objects or FALSE in case of an error. */ public function xpath($path) { return $this->xpath_xml->xpath($path); } /** * Was there an error? * * @return bool */ public function isError() { return ($this->getResultCode() == "Error"); } /** * @return string */ public function getErrorMessage() { return "Error: {$this->getResultCode()} Message: {$this->getMessageText()} {$this->getMessageCode()}"; } /** * @return string */ public function getRefID() { return $this->_getElementContents("refId"); } /** * @return string */ public function getResultCode() { return $this->_getElementContents("resultCode"); } /** * @return string */ public function getMessageCode() { return $this->_getElementContents("code"); } /** * @return string */ public function getMessageText() { return $this->_getElementContents("text"); } /** * Grabs the contents of a unique element. * * @param string * @return string */ protected function _getElementContents($elementName) { $start = "<$elementName>"; $end = "</$elementName>"; if (strpos($this->response,$start) === false || strpos($this->response,$end) === false) { return false; } else { $start_position = strpos($this->response, $start)+strlen($start); $end_position = strpos($this->response, $end); return substr($this->response, $start_position, $end_position-$start_position); } } } authorizenet/lib/shared/AuthorizeNetTypes.php 0000644 00000024672 14736103100 0015466 0 ustar 00 <?php /** * Classes for the various AuthorizeNet data types. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ /** * A class that contains all fields for a CIM Customer Profile. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCustomer { public $merchantCustomerId; public $description; public $email; public $paymentProfiles = array(); public $shipToList = array(); public $customerProfileId; } /** * A class that contains all fields for a CIM Address. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetAddress { public $firstName; public $lastName; public $company; public $address; public $city; public $state; public $zip; public $country; public $phoneNumber; public $faxNumber; public $customerAddressId; } /** * A class that contains all fields for a CIM Payment Profile. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetPaymentProfile { public $customerType; public $billTo; public $payment; public $customerPaymentProfileId; public function __construct() { $this->billTo = new AuthorizeNetAddress; $this->payment = new AuthorizeNetPayment; } } /** * A class that contains all fields for a CIM Payment Type. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetPayment { public $creditCard; public $bankAccount; public function __construct() { $this->creditCard = new AuthorizeNetCreditCard; $this->bankAccount = new AuthorizeNetBankAccount; } } /** * A class that contains all fields for a CIM Transaction. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetTransaction { public $amount; public $tax; public $shipping; public $duty; public $lineItems = array(); public $customerProfileId; public $customerPaymentProfileId; public $customerShippingAddressId; public $creditCardNumberMasked; public $bankRoutingNumberMasked; public $bankAccountNumberMasked; public $order; public $taxExempt; public $recurringBilling; public $cardCode; public $splitTenderId; public $approvalCode; public $transId; public function __construct() { $this->tax = (object)array(); $this->tax->amount = ""; $this->tax->name = ""; $this->tax->description = ""; $this->shipping = (object)array(); $this->shipping->amount = ""; $this->shipping->name = ""; $this->shipping->description = ""; $this->duty = (object)array(); $this->duty->amount = ""; $this->duty->name = ""; $this->duty->description = ""; // line items $this->order = (object)array(); $this->order->invoiceNumber = ""; $this->order->description = ""; $this->order->purchaseOrderNumber = ""; } } /** * A class that contains all fields for a CIM Transaction Line Item. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetLineItem { public $itemId; public $name; public $description; public $quantity; public $unitPrice; public $taxable; } /** * A class that contains all fields for a CIM Credit Card. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetCreditCard { public $cardNumber; public $expirationDate; public $cardCode; } /** * A class that contains all fields for a CIM Bank Account. * * @package AuthorizeNet * @subpackage AuthorizeNetCIM */ class AuthorizeNetBankAccount { public $accountType; public $routingNumber; public $accountNumber; public $nameOnAccount; public $echeckType; public $bankName; } /** * A class that contains all fields for an AuthorizeNet ARB Subscription. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNet_Subscription { public $name; public $intervalLength; public $intervalUnit; public $startDate; public $totalOccurrences; public $trialOccurrences; public $amount; public $trialAmount; public $creditCardCardNumber; public $creditCardExpirationDate; public $creditCardCardCode; public $bankAccountAccountType; public $bankAccountRoutingNumber; public $bankAccountAccountNumber; public $bankAccountNameOnAccount; public $bankAccountEcheckType; public $bankAccountBankName; public $orderInvoiceNumber; public $orderDescription; public $customerId; public $customerEmail; public $customerPhoneNumber; public $customerFaxNumber; public $billToFirstName; public $billToLastName; public $billToCompany; public $billToAddress; public $billToCity; public $billToState; public $billToZip; public $billToCountry; public $shipToFirstName; public $shipToLastName; public $shipToCompany; public $shipToAddress; public $shipToCity; public $shipToState; public $shipToZip; public $shipToCountry; public function getXml() { $xml = "<subscription> <name>{$this->name}</name> <paymentSchedule> <interval> <length>{$this->intervalLength}</length> <unit>{$this->intervalUnit}</unit> </interval> <startDate>{$this->startDate}</startDate> <totalOccurrences>{$this->totalOccurrences}</totalOccurrences> <trialOccurrences>{$this->trialOccurrences}</trialOccurrences> </paymentSchedule> <amount>{$this->amount}</amount> <trialAmount>{$this->trialAmount}</trialAmount> <payment> <creditCard> <cardNumber>{$this->creditCardCardNumber}</cardNumber> <expirationDate>{$this->creditCardExpirationDate}</expirationDate> <cardCode>{$this->creditCardCardCode}</cardCode> </creditCard> <bankAccount> <accountType>{$this->bankAccountAccountType}</accountType> <routingNumber>{$this->bankAccountRoutingNumber}</routingNumber> <accountNumber>{$this->bankAccountAccountNumber}</accountNumber> <nameOnAccount>{$this->bankAccountNameOnAccount}</nameOnAccount> <echeckType>{$this->bankAccountEcheckType}</echeckType> <bankName>{$this->bankAccountBankName}</bankName> </bankAccount> </payment> <order> <invoiceNumber>{$this->orderInvoiceNumber}</invoiceNumber> <description>{$this->orderDescription}</description> </order> <customer> <id>{$this->customerId}</id> <email>{$this->customerEmail}</email> <phoneNumber>{$this->customerPhoneNumber}</phoneNumber> <faxNumber>{$this->customerFaxNumber}</faxNumber> </customer> <billTo> <firstName>{$this->billToFirstName}</firstName> <lastName>{$this->billToLastName}</lastName> <company>{$this->billToCompany}</company> <address>{$this->billToAddress}</address> <city>{$this->billToCity}</city> <state>{$this->billToState}</state> <zip>{$this->billToZip}</zip> <country>{$this->billToCountry}</country> </billTo> <shipTo> <firstName>{$this->shipToFirstName}</firstName> <lastName>{$this->shipToLastName}</lastName> <company>{$this->shipToCompany}</company> <address>{$this->shipToAddress}</address> <city>{$this->shipToCity}</city> <state>{$this->shipToState}</state> <zip>{$this->shipToZip}</zip> <country>{$this->shipToCountry}</country> </shipTo> </subscription>"; $xml_clean = ""; // Remove any blank child elements foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) { if (!preg_match('/><\//', $line)) { $xml_clean .= $line . "\n"; } } // Remove any blank parent elements $element_removed = 1; // Recursively repeat if a change is made while ($element_removed) { $element_removed = 0; if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) { $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean); $element_removed = 1; } } // Remove any blank lines // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean); return $xml_clean; } } /** * A class that contains all fields for an AuthorizeNet ARB SubscriptionList. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetGetSubscriptionList { public $searchType; public $sorting; public $paging; public function getXml() { $emptyString = ""; $sortingXml = (is_null($this->sorting)) ? $emptyString : $this->sorting->getXml(); $pagingXml = (is_null($this->paging)) ? $emptyString : $this->paging->getXml(); $xml = " <searchType>{$this->searchType}</searchType>" .$sortingXml .$pagingXml ; $xml_clean = ""; // Remove any blank child elements foreach (preg_split("/(\r?\n)/", $xml) as $key => $line) { if (!preg_match('/><\//', $line)) { $xml_clean .= $line . "\n"; } } // Remove any blank parent elements $element_removed = 1; // Recursively repeat if a change is made while ($element_removed) { $element_removed = 0; if (preg_match('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', $xml_clean)) { $xml_clean = preg_replace('/<[a-z]+>[\r?\n]+\s*<\/[a-z]+>/i', '', $xml_clean); $element_removed = 1; } } // Remove any blank lines // $xml_clean = preg_replace('/\r\n[\s]+\r\n/','',$xml_clean); return $xml_clean; } } class AuthorizeNetSubscriptionListPaging { public $limit; public $offset; public function getXml() { $xml = "<paging> <limit>{$this->limit}</limit> <offset>{$this->offset}</offset> </paging>"; return $xml; } } class AuthorizeNetSubscriptionListSorting { public $orderBy; public $orderDescending; public function getXml() { $xml = " <sorting> <orderBy>{$this->orderBy}</orderBy> <orderDescending>{$this->orderDescending}</orderDescending> </sorting>"; return $xml; } } authorizenet/lib/shared/AuthorizeNetResponse.php 0000644 00000003307 14736103100 0016150 0 ustar 00 <?php /** * Base class for the AuthorizeNet AIM & SIM Responses. * * @package AuthorizeNet * @subpackage AuthorizeNetResponse */ /** * Parses an AuthorizeNet Response. * * @package AuthorizeNet * @subpackage AuthorizeNetResponse */ class AuthorizeNetResponse { const APPROVED = 1; const DECLINED = 2; const ERROR = 3; const HELD = 4; public $approved; public $declined; public $error; public $held; public $response_code; public $response_subcode; public $response_reason_code; public $response_reason_text; public $authorization_code; public $avs_response; public $transaction_id; public $invoice_number; public $description; public $amount; public $method; public $transaction_type; public $customer_id; public $first_name; public $last_name; public $company; public $address; public $city; public $state; public $zip_code; public $country; public $phone; public $fax; public $email_address; public $ship_to_first_name; public $ship_to_last_name; public $ship_to_company; public $ship_to_address; public $ship_to_city; public $ship_to_state; public $ship_to_zip_code; public $ship_to_country; public $tax; public $duty; public $freight; public $tax_exempt; public $purchase_order_number; public $md5_hash; public $card_code_response; public $cavv_response; // cardholder_authentication_verification_response public $account_number; public $card_type; public $split_tender_id; public $requested_amount; public $balance_on_card; public $response; // The response string from AuthorizeNet. } authorizenet/lib/shared/AuthorizeNetRequest.php 0000644 00000007342 14736103100 0016005 0 ustar 00 <?php use net\authorize\util\LogFactory; /** * Sends requests to the Authorize.Net gateways. * * @package AuthorizeNet * @subpackage AuthorizeNetRequest */ abstract class AuthorizeNetRequest { protected $_api_login; protected $_transaction_key; protected $_post_string; public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections. protected $_sandbox = true; protected $_logger = null; /** * Set the _post_string */ abstract protected function _setPostString(); /** * Handle the response string */ abstract protected function _handleResponse($string); /** * Get the post url. We need this because until 5.3 you * you could not access child constants in a parent class. */ abstract protected function _getPostUrl(); /** * Constructor. * * @param string $api_login_id The Merchant's API Login ID. * @param string $transaction_key The Merchant's Transaction Key. */ public function __construct($api_login_id = false, $transaction_key = false) { $this->_api_login = ($api_login_id ? $api_login_id : (defined('AUTHORIZENET_API_LOGIN_ID') ? AUTHORIZENET_API_LOGIN_ID : "")); $this->_transaction_key = ($transaction_key ? $transaction_key : (defined('AUTHORIZENET_TRANSACTION_KEY') ? AUTHORIZENET_TRANSACTION_KEY : "")); $this->_sandbox = (defined('AUTHORIZENET_SANDBOX') ? AUTHORIZENET_SANDBOX : true); $this->_logger = LogFactory::getLog(get_class($this)); } /** * Alter the gateway url. * * @param bool $bool Use the Sandbox. */ public function setSandbox($bool) { $this->_sandbox = $bool; } /** * Set a log file. * * @param string $filepath Path to log file. */ public function setLogFile($filepath) { $this->_logger->setLogFile($filepath); } /** * Return the post string. * * @return string */ public function getPostString() { return $this->_post_string; } /** * Posts the request to AuthorizeNet & returns response. * * @return AuthorizeNetARB_Response The response. */ protected function _sendRequest() { $this->_setPostString(); $post_url = $this->_getPostUrl(); $curl_request = curl_init($post_url); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $this->_post_string); curl_setopt($curl_request, CURLOPT_HEADER, 0); curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); if ($this->VERIFY_PEER) { curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/ssl/cert.pem'); } else { if ($this->_logger) { $this->_logger->error("----Request----\nInvalid SSL option\n"); } return false; } if (preg_match('/xml/',$post_url)) { curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); } $response = curl_exec($curl_request); if ($this->_logger) { if ($curl_error = curl_error($curl_request)) { $this->_logger->error("----CURL ERROR----\n$curl_error\n\n"); } // Do not log requests that could contain CC info. $this->_logger->info("----Request----\n{$this->_post_string}\n"); $this->_logger->info("----Response----\n$response\n\n"); } curl_close($curl_request); return $this->_handleResponse($response); } } authorizenet/lib/AuthorizeNetCP.php 0000644 00000020573 14736103100 0013412 0 ustar 00 <?php /** * Easily interact with the Authorize.Net Card Present API. * * * @package AuthorizeNet * @subpackage AuthorizeNetCP * @link http://www.authorize.net/support/CP_guide.pdf Card Present Guide */ /** * Builds and sends an AuthorizeNet CP Request. * * @package AuthorizeNet * @subpackage AuthorizeNetCP */ class AuthorizeNetCP extends AuthorizeNetAIM { const LIVE_URL = 'https://cardpresent.authorize.net/gateway/transact.dll'; public $verify_x_fields = false; /** * Holds all the x_* name/values that will be posted in the request. * Default values are provided for best practice fields. */ protected $_x_post_fields = array( "cpversion" => "1.0", "delim_char" => ",", "encap_char" => "|", "market_type" => "2", "response_format" => "1", // 0 - XML, 1 - NVP ); /** * Device Types (x_device_type) * 1 = Unknown * 2 = Unattended Terminal * 3 = Self Service Terminal * 4 = Electronic Cash Register * 5 = Personal Computer- Based Terminal * 6 = AirPay * 7 = Wireless POS * 8 = Website * 9 = Dial Terminal * 10 = Virtual Terminal */ /** * Only used if merchant wants to send custom fields. */ private $_custom_fields = array(); /** * Strip sentinels and set track1 field. * * @param string $track1data */ public function setTrack1Data($track1data) { if (preg_match('/^%.*\?$/', $track1data)) { $this->track1 = substr($track1data, 1, -1); } else { $this->track1 = $track1data; } } /** * Strip sentinels and set track2 field. * * @param string $track2data */ public function setTrack2Data($track2data) { if (preg_match('/^;.*\?$/', $track2data)) { $this->track2 = substr($track2data, 1, -1); } else { $this->track2 = $track2data; } } /** * * * @param string $response * * @return AuthorizeNetAIM_Response */ protected function _handleResponse($response) { return new AuthorizeNetCP_Response($response, $this->_x_post_fields['delim_char'], $this->_x_post_fields['encap_char'], $this->_custom_fields); } } /** * Parses an AuthorizeNet Card Present Response. * * @package AuthorizeNet * @subpackage AuthorizeNetCP */ class AuthorizeNetCP_Response extends AuthorizeNetResponse { private $_response_array = array(); // An array with the split response. /** * Constructor. Parses the AuthorizeNet response string. * * @param string $response The response from the AuthNet server. * @param string $delimiter The delimiter used (default is ",") * @param string $encap_char The encap_char used (default is "|") * @param array $custom_fields Any custom fields set in the request. */ public function __construct($response, $delimiter, $encap_char, $custom_fields) { if ($response) { // If it's an XML response if (substr($response, 0, 5) == "<?xml") { $this->xml = @simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOWARNING); // Set all fields $this->version = array_pop(array_slice(explode('"', $response), 1,1)); $this->response_code = (string)$this->xml->ResponseCode; if ($this->response_code == 1) { $this->response_reason_code = (string)$this->xml->Messages->Message->Code; $this->response_reason_text = (string)$this->xml->Messages->Message->Description; } else { $this->response_reason_code = (string)$this->xml->Errors->Error->ErrorCode; $this->response_reason_text = (string)$this->xml->Errors->Error->ErrorText; } $this->authorization_code = (string)$this->xml->AuthCode; $this->avs_code = (string)$this->xml->AVSResultCode; $this->card_code_response = (string)$this->xml->CVVResultCode; $this->transaction_id = (string)$this->xml->TransID; $this->md5_hash = (string)$this->xml->TransHash; $this->user_ref = (string)$this->xml->UserRef; $this->card_num = (string)$this->xml->AccountNumber; $this->card_type = (string)$this->xml->AccountType; $this->test_mode = (string)$this->xml->TestMode; $this->ref_trans_id = (string)$this->xml->RefTransID; } else { // If it's an NVP response // Split Array $this->response = $response; if ($encap_char) { $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); } else { $this->_response_array = explode($delimiter, $response); } /** * If AuthorizeNet doesn't return a delimited response. */ if (count($this->_response_array) < 10) { $this->approved = false; $this->error = true; $this->error_message = "Unrecognized response from AuthorizeNet: $response"; return; } // Set all fields $this->version = $this->_response_array[0]; $this->response_code = $this->_response_array[1]; $this->response_reason_code = $this->_response_array[2]; $this->response_reason_text = $this->_response_array[3]; $this->authorization_code = $this->_response_array[4]; $this->avs_code = $this->_response_array[5]; $this->card_code_response = $this->_response_array[6]; $this->transaction_id = $this->_response_array[7]; $this->md5_hash = $this->_response_array[8]; $this->user_ref = $this->_response_array[9]; $this->card_num = $this->_response_array[20]; $this->card_type = $this->_response_array[21]; $this->split_tender_id = isset($this->_response_array[22]) ? $this->_response_array[22] : NULL; $this->requested_amount = isset($this->_response_array[23]) ? $this->_response_array[23] : NULL; $this->approved_amount = isset($this->_response_array[24]) ? $this->_response_array[24] : NULL; $this->card_balance = isset($this->_response_array[25]) ? $this->_response_array[25] : NULL; } $this->approved = ($this->response_code == self::APPROVED); $this->declined = ($this->response_code == self::DECLINED); $this->error = ($this->response_code == self::ERROR); $this->held = ($this->response_code == self::HELD); if ($this->error) { $this->error_message = "AuthorizeNet Error: Response Code: ".$this->response_code." Response Reason Code: ".$this->response_reason_code." Response Reason Text: ".$this->response_reason_text." "; } } else { $this->approved = false; $this->error = true; $this->error_message = "Error connecting to AuthorizeNet"; } } /** * Is the MD5 provided correct? * * @param string $api_login_id * @param string $md5_setting * @return bool */ public function isAuthorizeNet($api_login_id = false, $md5_setting = false) { $amount = ($this->amount ? $this->amount : '0.00'); $api_login_id = ($api_login_id ? $api_login_id : AUTHORIZENET_API_LOGIN_ID); $md5_setting = ($md5_setting ? $md5_setting : AUTHORIZENET_MD5_SETTING); return ($this->md5_hash == strtoupper(md5($md5_setting . $api_login_id . $this->transaction_id . $amount))); } } authorizenet/lib/AuthorizeNetARB.php 0000644 00000010511 14736103100 0013503 0 ustar 00 <?php /** * Easily interact with the Authorize.Net ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB * @link http://www.authorize.net/support/ARB_guide.pdf ARB Guide */ /** * A class to send a request to the ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetARB extends AuthorizeNetRequest { const LIVE_URL = "https://api2.authorize.net/xml/v1/request.api"; const SANDBOX_URL = "https://apitest.authorize.net/xml/v1/request.api"; private $_request_type; private $_request_payload; /** * Optional. Used if the merchant wants to set a reference ID. * * @param string $refId */ public function setRefId($refId) { $this->_request_payload = ($refId ? "<refId>$refId</refId>" : ""); } /** * Create an ARB subscription * * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function createSubscription(AuthorizeNet_Subscription $subscription) { $this->_request_type = "CreateSubscriptionRequest"; $this->_request_payload .= $subscription->getXml(); return $this->_sendRequest(); } /** * Update an ARB subscription * * @param int $subscriptionId * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function updateSubscription($subscriptionId, AuthorizeNet_Subscription $subscription) { $this->_request_type = "UpdateSubscriptionRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; $this->_request_payload .= $subscription->getXml(); return $this->_sendRequest(); } /** * Get status of a subscription * * @param int $subscriptionId * * @return AuthorizeNetARB_Response */ public function getSubscriptionStatus($subscriptionId) { $this->_request_type = "GetSubscriptionStatusRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; return $this->_sendRequest(); } /** * Cancel a subscription * * @param int $subscriptionId * * @return AuthorizeNetARB_Response */ public function cancelSubscription($subscriptionId) { $this->_request_type = "CancelSubscriptionRequest"; $this->_request_payload .= "<subscriptionId>$subscriptionId</subscriptionId>"; return $this->_sendRequest(); } /** * Create an ARB subscription * * @param AuthorizeNet_Subscription $subscription * * @return AuthorizeNetARB_Response */ public function getSubscriptionList(AuthorizeNetGetSubscriptionList $subscriptionList) { $this->_request_type = "GetSubscriptionListRequest"; $this->_request_payload .= $subscriptionList->getXml(); return $this->_sendRequest(); } /** * * * @param string $response * * @return AuthorizeNetARB_Response */ protected function _handleResponse($response) { return new AuthorizeNetARB_Response($response); } /** * @return string */ protected function _getPostUrl() { return ($this->_sandbox ? self::SANDBOX_URL : self::LIVE_URL); } /** * Prepare the XML document for posting. */ protected function _setPostString() { $this->_post_string =<<<XML <?xml version="1.0" encoding="utf-8"?> <ARB{$this->_request_type} xmlns= "AnetApi/xml/v1/schema/AnetApiSchema.xsd"> <merchantAuthentication> <name>{$this->_api_login}</name> <transactionKey>{$this->_transaction_key}</transactionKey> </merchantAuthentication> {$this->_request_payload} </ARB{$this->_request_type}> XML; } } /** * A class to parse a response from the ARB XML API. * * @package AuthorizeNet * @subpackage AuthorizeNetARB */ class AuthorizeNetARB_Response extends AuthorizeNetXMLResponse { /** * @return int */ public function getSubscriptionId() { return $this->_getElementContents("subscriptionId"); } /** * @return string */ public function getSubscriptionStatus() { return $this->_getElementContents("status"); } } authorizenet/lib/net/authorize/util/HttpClient.php 0000644 00000007011 14736103100 0016371 0 ustar 00 <?php namespace net\authorize\util; use net\authorize\util\LogFactory; use net\authorize\util\Log; /** * A class to send a request to the XML API. * * @package AuthorizeNet * @subpackage net\authorize\util */ class HttpClient { private $_Url = ""; public $VERIFY_PEER = true; // attempt trust validation of SSL certificates when establishing secure connections. private $logger = NULL; /** * Constructor. * */ public function __construct() { $this->logger = LogFactory::getLog(get_class($this)); } /** * Set a log file. * * @param string $endPoint end point to hit from \net\authorize\api\constants\ANetEnvironment */ public function setPostUrl( $endPoint = \net\authorize\api\constants\ANetEnvironment::CUSTOM) { $this->_Url = sprintf( "%s/xml/v1/request.api", $endPoint); } /** * @return string */ public function _getPostUrl() { //return (self::URL); return ($this->_Url); } /** * Set a log file. * * @param string $filepath Path to log file. */ public function setLogFile($filepath) { $this->logger->setLogFile($filepath); } /** * Posts the request to AuthorizeNet endpoint using Curl & returns response. * * @param string $xmlRequest * @return string $xmlResponse The response. */ public function _sendRequest($xmlRequest) { $xmlResponse = ""; $post_url = $this->_getPostUrl(); $curl_request = curl_init($post_url); curl_setopt($curl_request, CURLOPT_POSTFIELDS, $xmlRequest); curl_setopt($curl_request, CURLOPT_HEADER, 0); curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); $this->logger->info(sprintf(" Url: %s", $post_url)); // Do not log requests that could contain CC info. $this->logger->info(sprintf("Request to AnetApi: \n%s", $xmlRequest)); if ($this->VERIFY_PEER) { curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem'); } else { $this->logger->error("Invalid SSL option for the request"); return false; } if (preg_match('/xml/',$post_url)) { curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); // file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND); $this->logger->info("Sending 'XML' Request type"); } try { $this->logger->info("Sending http request via Curl"); $xmlResponse = curl_exec($curl_request); $this->logger->info("Response from AnetApi: $xmlResponse"); } catch (\Exception $ex) { $errorMessage = sprintf("\n%s:Error making http request via curl: Code:'%s', Message:'%s', Trace:'%s', File:'%s':'%s'", $this->now(), $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), $ex->getFile(), $ex->getLine() ); $this->logger->error($errorMessage); } if ($this->logger && $this->logger->getLogFile()) { if ($curl_error = curl_error($curl_request)) { $this->logger->error("CURL ERROR: $curl_error"); } } curl_close($curl_request); return $xmlResponse; } private function now() { return date( DATE_RFC2822); } } authorizenet/lib/net/authorize/util/LogFactory.php 0000644 00000000610 14736103100 0016362 0 ustar 00 <?php namespace net\authorize\util; class LogFactory { private static $logger = NULL; public static function getLog($classType){ if(NULL == self::$logger){ self::$logger = new Log(); if(defined('AUTHORIZENET_LOG_FILE')){ self::$logger->setLogFile(AUTHORIZENET_LOG_FILE); } } return self::$logger; } } ?>