├── .eslintrc.yml ├── .github └── workflows │ └── nodejs-workflow.yml ├── .gitignore ├── .gitmodules ├── .npmignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── lib ├── apicontracts.js ├── apicontrollers.js ├── apicontrollersbase.js ├── authorizenet.js ├── config.js ├── constants.js ├── logger.js └── utils.js ├── mappings └── Schema.js ├── package.json ├── sample └── test.js ├── scripts ├── ControllerTemplate.jst ├── generateControllersFromSchema.js ├── generateControllersFromSchema.sh ├── generateObjectsFromSchema.js ├── generateObjectsFromSchema.sh ├── headertemplate.jst └── masterUpdate.sh └── test ├── constants.js ├── test-AuthenticateTest.js ├── test-applepaytransactions.js ├── test-customerprofiles.js ├── test-paymenttransactions.js ├── test-paypalexpresscheckout.js ├── test-recurringbilling.js ├── test-transactionreporting.js ├── test-visacheckout.js └── utils.js /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | node: true 3 | mocha: true 4 | es6: true 5 | extends: 'eslint:recommended' 6 | parserOptions: 7 | sourceType: module 8 | rules: 9 | indent: 10 | - error 11 | - tab 12 | linebreak-style: 13 | - error 14 | - unix 15 | quotes: 16 | - error 17 | - single 18 | semi: 19 | - error 20 | - always 21 | -------------------------------------------------------------------------------- /.github/workflows/nodejs-workflow.yml: -------------------------------------------------------------------------------- 1 | name: Authorize.net Node.js CI 2 | on: 3 | push: 4 | pull_request: 5 | workflow_dispatch: 6 | env: 7 | sdk_node: 'sdk-node' 8 | sample_code_node: 'sample-code-node' 9 | local_npm_folder: 'local-npm-folder' 10 | jobs: 11 | workflow-job: 12 | defaults: 13 | run: 14 | shell: bash 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | operating-system: [ubuntu-latest, macos-latest, windows-latest] 19 | node-ver: [14.x, 16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x] 20 | exclude: 21 | - operating-system: macos-latest 22 | node-ver: 14.x 23 | include: 24 | - operating-system: macos-13 25 | node-ver: 14.x 26 | runs-on: ${{matrix.operating-system}} 27 | steps: 28 | - name: Creating separate folders for SDK and Sample Codes 29 | run: | 30 | rm -rf $sdk_node 31 | rm -rf $sample_code_node 32 | mkdir $sdk_node $sample_code_node 33 | 34 | - name: Checkout authorizenet/sdk-node 35 | uses: actions/checkout@v4 36 | with: 37 | path: ${{env.sdk_node}} 38 | 39 | - name: Checkout authorizenet/sample-code-node 40 | uses: actions/checkout@v4 41 | with: 42 | repository: 'authorizenet/sample-code-node' 43 | ref: 'master' 44 | path: ${{env.sample_code_node}} 45 | 46 | - name: Install Node 47 | uses: actions/setup-node@v4 48 | with: 49 | node-version: ${{matrix.node-ver}} 50 | 51 | - name: Install and Test 52 | run: | 53 | cd $sdk_node 54 | npm install 55 | npm test 56 | 57 | npm pack 58 | PACKAGE_VERSION=$(grep '"version"' package.json | cut -d '"' -f 4 | head -n 1) 59 | cd ../$sample_code_node 60 | npm install 61 | npm install file:../$sdk_node/authorizenet-$PACKAGE_VERSION.tgz 62 | if [[ ${{matrix.node-ver}} = 14* ]]; then 63 | npm install ajv@5.5.2 64 | fi 65 | npm list 66 | node test-runner.js 67 | 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sample-code-node"] 2 | path = sample-code-node 3 | url = https://github.com/AuthorizeNet/sample-code-node.git 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Test 7 | test 8 | sample 9 | 10 | # Scripts 11 | scripts 12 | 13 | # json mappings 14 | mappings 15 | 16 | #Eslint 17 | .eslintrc.yml 18 | 19 | # Dependency directory 20 | node_modules 21 | 22 | # Git Ignore 23 | .gitignore 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "4" 5 | - "6" 6 | - "8" 7 | - "10" 8 | - "12" 9 | 10 | matrix: 11 | allow_failures: 12 | - node_js: "4" 13 | - node_js: "6" 14 | - node_js: "8" 15 | 16 | before_install: 17 | # execute all of the commands which need to be executed 18 | # before installing dependencies 19 | 20 | install: 21 | # install all of the dependencies we need here 22 | - npm install 23 | 24 | before_script: 25 | # execute all of the commands which need to be executed 26 | # before running actual tests 27 | - git submodule update --remote --recursive 28 | 29 | script: 30 | # execute all of the tests or other commands to determine 31 | # whether the build will pass or fail 32 | - mocha 33 | 34 | after_script: -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | + Thanks for contributing to the Authorize.Net Node SDK. 2 | 3 | + Before you submit a pull request, we ask that you consider the following: 4 | 5 | - 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. 6 | - 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 are inside [sdk-node/lib/apicontracts.js](https://github.com/AuthorizeNet/sdk-node/tree/master/lib) and [sdk-node/lib/apicontrollers.js](https://github.com/AuthorizeNet/sdk-node/tree/master/lib) folders, except [sdk-node/lib/apicontrollersbase.js](https://github.com/AuthorizeNet/sdk-node/tree/master/lib). 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | SDK LICENSE AGREEMENT 2 | 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’). 3 | 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. 4 | 5 | 1. DEFINITIONS 6 | 1.1 “Application(s)” means software programs that You develop to operate with the Gateway using components of the Software. 7 | 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. 8 | 1.3 “Gateway” means any electronic payment platform maintained and operated by Authorize.Net and any of its affiliates. 9 | 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. 10 | 2. GRANT OF LICENSE; RESTRICTIONS 11 | 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. 12 | 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. 13 | 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. 14 | 2.4 No Support. Authorize.Net has no obligation to provide support, maintenance, upgrades, modifications or new releases of the Software. 15 | 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. 16 | 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. 17 | 2.7 Use. 18 | (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. 19 | 3. WARRANTY DISCLAIMER; LIMITATION OF LIABILITY 20 | 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.  21 | 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. 22 | 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). 23 | 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. 24 | 6. CONFIDENTIAL INFORMATION 25 | 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. 26 | 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. 27 | 7. General Terms 28 | 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. 29 | 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. 30 | 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. 31 | 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. 32 | 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. 33 | 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. 34 | 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. 35 | 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 36 | Authorize.Net has not made any representations, warranties or agreements of any kind, except as expressly set forth herein. 37 | 38 | 39 | Authorize.Net Software Development Kit (SDK) License Agreement 40 | v. February 1, 2017 41 | 1 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Authorize.Net Node.js SDK 2 | 3 | [![Authorize.net Node.js CI](https://github.com/AuthorizeNet/sdk-node/actions/workflows/nodejs-workflow.yml/badge.svg?branch=master)](https://github.com/AuthorizeNet/sdk-node/actions/workflows/nodejs-workflow.yml) 4 | [![NPM version](https://badge.fury.io/js/authorizenet.png)](http://badge.fury.io/js/authorizenet) 5 | 6 | 7 | ## Requirements 8 | 9 | * Node.js version 14.x.x or higher 10 | * An Authorize.Net account (see _Registration & Configuration_ section below) 11 | 12 | ### Contribution 13 | 14 | - If you need information or clarification about Authorize.Net features, create an issue with your question. You can also search the [Authorize.Net developer community](https://community.developer.authorize.net/) for discussions related to your question. 15 | 16 | - Before creating pull requests, please read [the contributors guide](CONTRIBUTING.md). 17 | 18 | ### TLS 1.2 19 | 20 | The Authorize.Net APIs only support connections using the TLS 1.2 security protocol. Make sure to upgrade all required components to support TLS 1.2. Keep these components up to date to mitigate the risk of new security flaws. 21 | 22 | ## Installation 23 | 24 | To install AuthorizeNet 25 | 26 | `npm install authorizenet` 27 | 28 | 29 | ## Registration & Configuration 30 | 31 | Use of this SDK and the Authorize.Net APIs requires having an account on the Authorize.Net system. You can find these details in the Settings section. 32 | 33 | If you don't currently have a production Authorize.Net account, [sign up for a sandbox account](https://developer.authorize.net/sandbox/). 34 | 35 | ### Authentication 36 | 37 | To authenticate with the Authorize.Net API, use your account's API Login ID and Transaction Key. If you don't have these credentials, you can obtain them from our Merchant Interface site. For production accounts, the Merchant Interface is located at (https://account.authorize.net/); and for sandbox accounts, at (https://sandbox.authorize.net). 38 | 39 | 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. 40 | 41 | #### To set your API credentials for an API request: 42 | 43 | ```javascript 44 | var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 45 | merchantAuthenticationType.setName('YOUR_API_LOGIN_ID'); 46 | merchantAuthenticationType.setTransactionKey('YOUR_TRANSACTION_KEY'); 47 | ``` 48 | 49 | An authentication test sample is provided and can be run with the following command: 50 | 51 | `node sample/test.js` 52 | 53 | Never include your Login ID and Transaction Key directly in a file that's in a publicly accessible portion of your website. As a best practice, define the API Login ID and Transaction Key in a constants file, and reference those constants in the appropriate place in your code. 54 | 55 | ### Switching between the sandbox environment and the production environment 56 | 57 | Authorize.Net maintains a complete sandbox environment for testing and development purposes. The sandbox environment is an exact replica of our production environment, with simulated transaction authorization and settlement. By default, this SDK is configured to use with the sandbox environment. To switch to the production environment, call `setEnvironment` on the controller variable before execute. 58 | 59 | For example: 60 | 61 | ```javascript 62 | // For PRODUCTION use 63 | ctrl.setEnvironment(SDKConstants.endpoint.production); 64 | ``` 65 | 66 | API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments. 67 | 68 | 69 | ## SDK Usage Examples and Sample Code 70 | 71 | When using this SDK, downloading the Authorize.Net sample code repository is recommended. 72 | 73 | * [Authorize.Net Node.js Sample Code Repository (on GitHub)](https://github.com/AuthorizeNet/sample-code-node) 74 | 75 | The repository contains comprehensive sample code for all common uses of the Authorize.Net API: 76 | 77 | The API Reference contains details and examples of the structure and formatting of the Authorize.Net API. 78 | 79 | * [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html) 80 | 81 | Use the examples in the API Reference to determine which methods and information to include in an API request using this SDK. 82 | 83 | ## Create a Chase Pay Transaction 84 | 85 | Use this method to authorize and capture a payment using a tokenized credit card number issued by Chase Pay. Chase Pay transactions are only available to merchants using the Paymentech processor. 86 | 87 | The following information is required in the request: 88 | 89 | - **payment token** 90 | - **expiration date** 91 | - **cryptogram** received from the token provider 92 | - **tokenRequestorName** 93 | - **tokenRequestorId** 94 | - **tokenRequestorEci** 95 | 96 | When using the SDK to submit Chase Pay transactions, consider the following points: 97 | 98 | - `tokenRequesterName` must be populated with **`”CHASE_PAY”`** 99 | - `tokenRequestorId` must be populated with the **`Token Requestor ID`** provided by Chase Pay services for each transaction during consumer checkout 100 | - `tokenRequesterEci` must be populated with the **`ECI Indicator`** provided by Chase Pay services for each transaction during consumer checkout 101 | 102 | 103 | ## Building & Testing the SDK 104 | 105 | ### Running the SDK Tests 106 | 107 | `mocha` 108 | 109 | ### Run Particular Tests 110 | 111 | `mocha test/` 112 | 113 | 114 | ### For using behind proxy 115 | 116 | 1. Create a `config` object as follows: 117 | ```javascript 118 | config = { 119 | 'proxy': { 120 | 'setProxy': true, 121 | 'proxyUrl': 'http://:@:' 122 | } 123 | } 124 | ``` 125 | 126 | 2. Pass this `config` object to the controller constructor. 127 | 128 | For example, 129 | 130 | ```javascript 131 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON(), config); 132 | ``` 133 | 134 | ### Testing Guide 135 | 136 | 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. 137 | 138 | ### Transaction Hash Upgrade 139 | 140 | Authorize.Net is phasing out the MD5 based `transHash` element in favor of the SHA-512 based `transHashSHA2`. The setting in the Merchant Interface which controlled the MD5 Hash option is no longer available, and the `transHash` element will stop returning values at a later date to be determined. For information on how to use `transHashSHA2`, see the [Transaction Hash Upgrade Guide] (https://developer.authorize.net/support/hash_upgrade/). 141 | 142 | ## License 143 | 144 | This repository is distributed under a proprietary license. See the provided [`LICENSE.txt`](/LICENSE.txt) file. 145 | -------------------------------------------------------------------------------- /lib/apicontrollers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var APIOperationBase = require('./apicontrollersbase.js').APIOperationBase; 4 | const Logger = require('./logger.js'); 5 | 6 | class ANetApiController extends APIOperationBase { 7 | constructor(apiRequest, externalConfig = null) { 8 | var logger = Logger.getLogger('ANetApiController', externalConfig) 9 | logger.debug('Enter ANetApiController constructor'); 10 | super(apiRequest, externalConfig); 11 | logger.debug('Exit ANetApiController constructor'); 12 | } 13 | 14 | validateRequest(){ 15 | logger.debug('Enter validateRequest'); 16 | 17 | logger.debug('Exit validateRequest'); 18 | return; 19 | } 20 | 21 | getRequestType(){ 22 | return 'ANetApiRequest'; 23 | } 24 | } 25 | 26 | module.exports.ANetApiController = ANetApiController; 27 | 28 | class ARBCancelSubscriptionController extends APIOperationBase { 29 | constructor(apiRequest, externalConfig = null) { 30 | var logger = Logger.getLogger('ARBCancelSubscriptionController', externalConfig) 31 | logger.debug('Enter ARBCancelSubscriptionController constructor'); 32 | super(apiRequest, externalConfig); 33 | logger.debug('Exit ARBCancelSubscriptionController constructor'); 34 | } 35 | 36 | validateRequest(){ 37 | logger.debug('Enter validateRequest'); 38 | 39 | logger.debug('Exit validateRequest'); 40 | return; 41 | } 42 | 43 | getRequestType(){ 44 | return 'ARBCancelSubscriptionRequest'; 45 | } 46 | } 47 | 48 | module.exports.ARBCancelSubscriptionController = ARBCancelSubscriptionController; 49 | 50 | class ARBCreateSubscriptionController extends APIOperationBase { 51 | constructor(apiRequest, externalConfig = null) { 52 | var logger = Logger.getLogger('ARBCreateSubscriptionController', externalConfig) 53 | logger.debug('Enter ARBCreateSubscriptionController constructor'); 54 | super(apiRequest, externalConfig); 55 | logger.debug('Exit ARBCreateSubscriptionController constructor'); 56 | } 57 | 58 | validateRequest(){ 59 | logger.debug('Enter validateRequest'); 60 | 61 | logger.debug('Exit validateRequest'); 62 | return; 63 | } 64 | 65 | getRequestType(){ 66 | return 'ARBCreateSubscriptionRequest'; 67 | } 68 | } 69 | 70 | module.exports.ARBCreateSubscriptionController = ARBCreateSubscriptionController; 71 | 72 | class ARBGetSubscriptionController extends APIOperationBase { 73 | constructor(apiRequest, externalConfig = null) { 74 | var logger = Logger.getLogger('ARBGetSubscriptionController', externalConfig) 75 | logger.debug('Enter ARBGetSubscriptionController constructor'); 76 | super(apiRequest, externalConfig); 77 | logger.debug('Exit ARBGetSubscriptionController constructor'); 78 | } 79 | 80 | validateRequest(){ 81 | logger.debug('Enter validateRequest'); 82 | 83 | logger.debug('Exit validateRequest'); 84 | return; 85 | } 86 | 87 | getRequestType(){ 88 | return 'ARBGetSubscriptionRequest'; 89 | } 90 | } 91 | 92 | module.exports.ARBGetSubscriptionController = ARBGetSubscriptionController; 93 | 94 | class ARBGetSubscriptionListController extends APIOperationBase { 95 | constructor(apiRequest, externalConfig = null) { 96 | var logger = Logger.getLogger('ARBGetSubscriptionListController', externalConfig) 97 | logger.debug('Enter ARBGetSubscriptionListController constructor'); 98 | super(apiRequest, externalConfig); 99 | logger.debug('Exit ARBGetSubscriptionListController constructor'); 100 | } 101 | 102 | validateRequest(){ 103 | logger.debug('Enter validateRequest'); 104 | 105 | logger.debug('Exit validateRequest'); 106 | return; 107 | } 108 | 109 | getRequestType(){ 110 | return 'ARBGetSubscriptionListRequest'; 111 | } 112 | } 113 | 114 | module.exports.ARBGetSubscriptionListController = ARBGetSubscriptionListController; 115 | 116 | class ARBGetSubscriptionStatusController extends APIOperationBase { 117 | constructor(apiRequest, externalConfig = null) { 118 | var logger = Logger.getLogger('ARBGetSubscriptionStatusController', externalConfig) 119 | logger.debug('Enter ARBGetSubscriptionStatusController constructor'); 120 | super(apiRequest, externalConfig); 121 | logger.debug('Exit ARBGetSubscriptionStatusController constructor'); 122 | } 123 | 124 | validateRequest(){ 125 | logger.debug('Enter validateRequest'); 126 | 127 | logger.debug('Exit validateRequest'); 128 | return; 129 | } 130 | 131 | getRequestType(){ 132 | return 'ARBGetSubscriptionStatusRequest'; 133 | } 134 | } 135 | 136 | module.exports.ARBGetSubscriptionStatusController = ARBGetSubscriptionStatusController; 137 | 138 | class ARBUpdateSubscriptionController extends APIOperationBase { 139 | constructor(apiRequest, externalConfig = null) { 140 | var logger = Logger.getLogger('ARBUpdateSubscriptionController', externalConfig) 141 | logger.debug('Enter ARBUpdateSubscriptionController constructor'); 142 | super(apiRequest, externalConfig); 143 | logger.debug('Exit ARBUpdateSubscriptionController constructor'); 144 | } 145 | 146 | validateRequest(){ 147 | logger.debug('Enter validateRequest'); 148 | 149 | logger.debug('Exit validateRequest'); 150 | return; 151 | } 152 | 153 | getRequestType(){ 154 | return 'ARBUpdateSubscriptionRequest'; 155 | } 156 | } 157 | 158 | module.exports.ARBUpdateSubscriptionController = ARBUpdateSubscriptionController; 159 | 160 | class AuthenticateTestController extends APIOperationBase { 161 | constructor(apiRequest, externalConfig = null) { 162 | var logger = Logger.getLogger('AuthenticateTestController', externalConfig) 163 | logger.debug('Enter AuthenticateTestController constructor'); 164 | super(apiRequest, externalConfig); 165 | logger.debug('Exit AuthenticateTestController constructor'); 166 | } 167 | 168 | validateRequest(){ 169 | logger.debug('Enter validateRequest'); 170 | 171 | logger.debug('Exit validateRequest'); 172 | return; 173 | } 174 | 175 | getRequestType(){ 176 | return 'AuthenticateTestRequest'; 177 | } 178 | } 179 | 180 | module.exports.AuthenticateTestController = AuthenticateTestController; 181 | 182 | class CreateCustomerPaymentProfileController extends APIOperationBase { 183 | constructor(apiRequest, externalConfig = null) { 184 | var logger = Logger.getLogger('CreateCustomerPaymentProfileController', externalConfig) 185 | logger.debug('Enter CreateCustomerPaymentProfileController constructor'); 186 | super(apiRequest, externalConfig); 187 | logger.debug('Exit CreateCustomerPaymentProfileController constructor'); 188 | } 189 | 190 | validateRequest(){ 191 | logger.debug('Enter validateRequest'); 192 | 193 | logger.debug('Exit validateRequest'); 194 | return; 195 | } 196 | 197 | getRequestType(){ 198 | return 'CreateCustomerPaymentProfileRequest'; 199 | } 200 | } 201 | 202 | module.exports.CreateCustomerPaymentProfileController = CreateCustomerPaymentProfileController; 203 | 204 | class CreateCustomerProfileController extends APIOperationBase { 205 | constructor(apiRequest, externalConfig = null) { 206 | var logger = Logger.getLogger('CreateCustomerProfileController', externalConfig) 207 | logger.debug('Enter CreateCustomerProfileController constructor'); 208 | super(apiRequest, externalConfig); 209 | logger.debug('Exit CreateCustomerProfileController constructor'); 210 | } 211 | 212 | validateRequest(){ 213 | logger.debug('Enter validateRequest'); 214 | 215 | logger.debug('Exit validateRequest'); 216 | return; 217 | } 218 | 219 | getRequestType(){ 220 | return 'CreateCustomerProfileRequest'; 221 | } 222 | } 223 | 224 | module.exports.CreateCustomerProfileController = CreateCustomerProfileController; 225 | 226 | class CreateCustomerProfileFromTransactionController extends APIOperationBase { 227 | constructor(apiRequest, externalConfig = null) { 228 | var logger = Logger.getLogger('CreateCustomerProfileFromTransactionController', externalConfig) 229 | logger.debug('Enter CreateCustomerProfileFromTransactionController constructor'); 230 | super(apiRequest, externalConfig); 231 | logger.debug('Exit CreateCustomerProfileFromTransactionController constructor'); 232 | } 233 | 234 | validateRequest(){ 235 | logger.debug('Enter validateRequest'); 236 | 237 | logger.debug('Exit validateRequest'); 238 | return; 239 | } 240 | 241 | getRequestType(){ 242 | return 'CreateCustomerProfileFromTransactionRequest'; 243 | } 244 | } 245 | 246 | module.exports.CreateCustomerProfileFromTransactionController = CreateCustomerProfileFromTransactionController; 247 | 248 | class CreateCustomerProfileTransactionController extends APIOperationBase { 249 | constructor(apiRequest, externalConfig = null) { 250 | var logger = Logger.getLogger('CreateCustomerProfileTransactionController', externalConfig) 251 | logger.debug('Enter CreateCustomerProfileTransactionController constructor'); 252 | super(apiRequest, externalConfig); 253 | logger.debug('Exit CreateCustomerProfileTransactionController constructor'); 254 | } 255 | 256 | validateRequest(){ 257 | logger.debug('Enter validateRequest'); 258 | 259 | logger.debug('Exit validateRequest'); 260 | return; 261 | } 262 | 263 | getRequestType(){ 264 | return 'CreateCustomerProfileTransactionRequest'; 265 | } 266 | } 267 | 268 | module.exports.CreateCustomerProfileTransactionController = CreateCustomerProfileTransactionController; 269 | 270 | class CreateCustomerShippingAddressController extends APIOperationBase { 271 | constructor(apiRequest, externalConfig = null) { 272 | var logger = Logger.getLogger('CreateCustomerShippingAddressController', externalConfig) 273 | logger.debug('Enter CreateCustomerShippingAddressController constructor'); 274 | super(apiRequest, externalConfig); 275 | logger.debug('Exit CreateCustomerShippingAddressController constructor'); 276 | } 277 | 278 | validateRequest(){ 279 | logger.debug('Enter validateRequest'); 280 | 281 | logger.debug('Exit validateRequest'); 282 | return; 283 | } 284 | 285 | getRequestType(){ 286 | return 'CreateCustomerShippingAddressRequest'; 287 | } 288 | } 289 | 290 | module.exports.CreateCustomerShippingAddressController = CreateCustomerShippingAddressController; 291 | 292 | class CreateTransactionController extends APIOperationBase { 293 | constructor(apiRequest, externalConfig = null) { 294 | var logger = Logger.getLogger('CreateTransactionController', externalConfig) 295 | logger.debug('Enter CreateTransactionController constructor'); 296 | super(apiRequest, externalConfig); 297 | logger.debug('Exit CreateTransactionController constructor'); 298 | } 299 | 300 | validateRequest(){ 301 | logger.debug('Enter validateRequest'); 302 | 303 | logger.debug('Exit validateRequest'); 304 | return; 305 | } 306 | 307 | getRequestType(){ 308 | return 'CreateTransactionRequest'; 309 | } 310 | } 311 | 312 | module.exports.CreateTransactionController = CreateTransactionController; 313 | 314 | class DecryptPaymentDataController extends APIOperationBase { 315 | constructor(apiRequest, externalConfig = null) { 316 | var logger = Logger.getLogger('DecryptPaymentDataController', externalConfig) 317 | logger.debug('Enter DecryptPaymentDataController constructor'); 318 | super(apiRequest, externalConfig); 319 | logger.debug('Exit DecryptPaymentDataController constructor'); 320 | } 321 | 322 | validateRequest(){ 323 | logger.debug('Enter validateRequest'); 324 | 325 | logger.debug('Exit validateRequest'); 326 | return; 327 | } 328 | 329 | getRequestType(){ 330 | return 'DecryptPaymentDataRequest'; 331 | } 332 | } 333 | 334 | module.exports.DecryptPaymentDataController = DecryptPaymentDataController; 335 | 336 | class DeleteCustomerPaymentProfileController extends APIOperationBase { 337 | constructor(apiRequest, externalConfig = null) { 338 | var logger = Logger.getLogger('DeleteCustomerPaymentProfileController', externalConfig) 339 | logger.debug('Enter DeleteCustomerPaymentProfileController constructor'); 340 | super(apiRequest, externalConfig); 341 | logger.debug('Exit DeleteCustomerPaymentProfileController constructor'); 342 | } 343 | 344 | validateRequest(){ 345 | logger.debug('Enter validateRequest'); 346 | 347 | logger.debug('Exit validateRequest'); 348 | return; 349 | } 350 | 351 | getRequestType(){ 352 | return 'DeleteCustomerPaymentProfileRequest'; 353 | } 354 | } 355 | 356 | module.exports.DeleteCustomerPaymentProfileController = DeleteCustomerPaymentProfileController; 357 | 358 | class DeleteCustomerProfileController extends APIOperationBase { 359 | constructor(apiRequest, externalConfig = null) { 360 | var logger = Logger.getLogger('DeleteCustomerProfileController', externalConfig) 361 | logger.debug('Enter DeleteCustomerProfileController constructor'); 362 | super(apiRequest, externalConfig); 363 | logger.debug('Exit DeleteCustomerProfileController constructor'); 364 | } 365 | 366 | validateRequest(){ 367 | logger.debug('Enter validateRequest'); 368 | 369 | logger.debug('Exit validateRequest'); 370 | return; 371 | } 372 | 373 | getRequestType(){ 374 | return 'DeleteCustomerProfileRequest'; 375 | } 376 | } 377 | 378 | module.exports.DeleteCustomerProfileController = DeleteCustomerProfileController; 379 | 380 | class DeleteCustomerShippingAddressController extends APIOperationBase { 381 | constructor(apiRequest, externalConfig = null) { 382 | var logger = Logger.getLogger('DeleteCustomerShippingAddressController', externalConfig) 383 | logger.debug('Enter DeleteCustomerShippingAddressController constructor'); 384 | super(apiRequest, externalConfig); 385 | logger.debug('Exit DeleteCustomerShippingAddressController constructor'); 386 | } 387 | 388 | validateRequest(){ 389 | logger.debug('Enter validateRequest'); 390 | 391 | logger.debug('Exit validateRequest'); 392 | return; 393 | } 394 | 395 | getRequestType(){ 396 | return 'DeleteCustomerShippingAddressRequest'; 397 | } 398 | } 399 | 400 | module.exports.DeleteCustomerShippingAddressController = DeleteCustomerShippingAddressController; 401 | 402 | class GetAUJobDetailsController extends APIOperationBase { 403 | constructor(apiRequest, externalConfig = null) { 404 | var logger = Logger.getLogger('GetAUJobDetailsController', externalConfig) 405 | logger.debug('Enter GetAUJobDetailsController constructor'); 406 | super(apiRequest, externalConfig); 407 | logger.debug('Exit GetAUJobDetailsController constructor'); 408 | } 409 | 410 | validateRequest(){ 411 | logger.debug('Enter validateRequest'); 412 | 413 | logger.debug('Exit validateRequest'); 414 | return; 415 | } 416 | 417 | getRequestType(){ 418 | return 'GetAUJobDetailsRequest'; 419 | } 420 | } 421 | 422 | module.exports.GetAUJobDetailsController = GetAUJobDetailsController; 423 | 424 | class GetAUJobSummaryController extends APIOperationBase { 425 | constructor(apiRequest, externalConfig = null) { 426 | var logger = Logger.getLogger('GetAUJobSummaryController', externalConfig) 427 | logger.debug('Enter GetAUJobSummaryController constructor'); 428 | super(apiRequest, externalConfig); 429 | logger.debug('Exit GetAUJobSummaryController constructor'); 430 | } 431 | 432 | validateRequest(){ 433 | logger.debug('Enter validateRequest'); 434 | 435 | logger.debug('Exit validateRequest'); 436 | return; 437 | } 438 | 439 | getRequestType(){ 440 | return 'GetAUJobSummaryRequest'; 441 | } 442 | } 443 | 444 | module.exports.GetAUJobSummaryController = GetAUJobSummaryController; 445 | 446 | class GetBatchStatisticsController extends APIOperationBase { 447 | constructor(apiRequest, externalConfig = null) { 448 | var logger = Logger.getLogger('GetBatchStatisticsController', externalConfig) 449 | logger.debug('Enter GetBatchStatisticsController constructor'); 450 | super(apiRequest, externalConfig); 451 | logger.debug('Exit GetBatchStatisticsController constructor'); 452 | } 453 | 454 | validateRequest(){ 455 | logger.debug('Enter validateRequest'); 456 | 457 | logger.debug('Exit validateRequest'); 458 | return; 459 | } 460 | 461 | getRequestType(){ 462 | return 'GetBatchStatisticsRequest'; 463 | } 464 | } 465 | 466 | module.exports.GetBatchStatisticsController = GetBatchStatisticsController; 467 | 468 | class GetCustomerPaymentProfileController extends APIOperationBase { 469 | constructor(apiRequest, externalConfig = null) { 470 | var logger = Logger.getLogger('GetCustomerPaymentProfileController', externalConfig) 471 | logger.debug('Enter GetCustomerPaymentProfileController constructor'); 472 | super(apiRequest, externalConfig); 473 | logger.debug('Exit GetCustomerPaymentProfileController constructor'); 474 | } 475 | 476 | validateRequest(){ 477 | logger.debug('Enter validateRequest'); 478 | 479 | logger.debug('Exit validateRequest'); 480 | return; 481 | } 482 | 483 | getRequestType(){ 484 | return 'GetCustomerPaymentProfileRequest'; 485 | } 486 | } 487 | 488 | module.exports.GetCustomerPaymentProfileController = GetCustomerPaymentProfileController; 489 | 490 | class GetCustomerPaymentProfileListController extends APIOperationBase { 491 | constructor(apiRequest, externalConfig = null) { 492 | var logger = Logger.getLogger('GetCustomerPaymentProfileListController', externalConfig) 493 | logger.debug('Enter GetCustomerPaymentProfileListController constructor'); 494 | super(apiRequest, externalConfig); 495 | logger.debug('Exit GetCustomerPaymentProfileListController constructor'); 496 | } 497 | 498 | validateRequest(){ 499 | logger.debug('Enter validateRequest'); 500 | 501 | logger.debug('Exit validateRequest'); 502 | return; 503 | } 504 | 505 | getRequestType(){ 506 | return 'GetCustomerPaymentProfileListRequest'; 507 | } 508 | } 509 | 510 | module.exports.GetCustomerPaymentProfileListController = GetCustomerPaymentProfileListController; 511 | 512 | class GetCustomerPaymentProfileNonceController extends APIOperationBase { 513 | constructor(apiRequest, externalConfig = null) { 514 | var logger = Logger.getLogger('GetCustomerPaymentProfileNonceController', externalConfig) 515 | logger.debug('Enter GetCustomerPaymentProfileNonceController constructor'); 516 | super(apiRequest, externalConfig); 517 | logger.debug('Exit GetCustomerPaymentProfileNonceController constructor'); 518 | } 519 | 520 | validateRequest(){ 521 | logger.debug('Enter validateRequest'); 522 | 523 | logger.debug('Exit validateRequest'); 524 | return; 525 | } 526 | 527 | getRequestType(){ 528 | return 'GetCustomerPaymentProfileNonceRequest'; 529 | } 530 | } 531 | 532 | module.exports.GetCustomerPaymentProfileNonceController = GetCustomerPaymentProfileNonceController; 533 | 534 | class GetCustomerProfileController extends APIOperationBase { 535 | constructor(apiRequest, externalConfig = null) { 536 | var logger = Logger.getLogger('GetCustomerProfileController', externalConfig) 537 | logger.debug('Enter GetCustomerProfileController constructor'); 538 | super(apiRequest, externalConfig); 539 | logger.debug('Exit GetCustomerProfileController constructor'); 540 | } 541 | 542 | validateRequest(){ 543 | logger.debug('Enter validateRequest'); 544 | 545 | logger.debug('Exit validateRequest'); 546 | return; 547 | } 548 | 549 | getRequestType(){ 550 | return 'GetCustomerProfileRequest'; 551 | } 552 | } 553 | 554 | module.exports.GetCustomerProfileController = GetCustomerProfileController; 555 | 556 | class GetCustomerProfileIdsController extends APIOperationBase { 557 | constructor(apiRequest, externalConfig = null) { 558 | var logger = Logger.getLogger('GetCustomerProfileIdsController', externalConfig) 559 | logger.debug('Enter GetCustomerProfileIdsController constructor'); 560 | super(apiRequest, externalConfig); 561 | logger.debug('Exit GetCustomerProfileIdsController constructor'); 562 | } 563 | 564 | validateRequest(){ 565 | logger.debug('Enter validateRequest'); 566 | 567 | logger.debug('Exit validateRequest'); 568 | return; 569 | } 570 | 571 | getRequestType(){ 572 | return 'GetCustomerProfileIdsRequest'; 573 | } 574 | } 575 | 576 | module.exports.GetCustomerProfileIdsController = GetCustomerProfileIdsController; 577 | 578 | class GetCustomerShippingAddressController extends APIOperationBase { 579 | constructor(apiRequest, externalConfig = null) { 580 | var logger = Logger.getLogger('GetCustomerShippingAddressController', externalConfig) 581 | logger.debug('Enter GetCustomerShippingAddressController constructor'); 582 | super(apiRequest, externalConfig); 583 | logger.debug('Exit GetCustomerShippingAddressController constructor'); 584 | } 585 | 586 | validateRequest(){ 587 | logger.debug('Enter validateRequest'); 588 | 589 | logger.debug('Exit validateRequest'); 590 | return; 591 | } 592 | 593 | getRequestType(){ 594 | return 'GetCustomerShippingAddressRequest'; 595 | } 596 | } 597 | 598 | module.exports.GetCustomerShippingAddressController = GetCustomerShippingAddressController; 599 | 600 | class GetHostedPaymentPageController extends APIOperationBase { 601 | constructor(apiRequest, externalConfig = null) { 602 | var logger = Logger.getLogger('GetHostedPaymentPageController', externalConfig) 603 | logger.debug('Enter GetHostedPaymentPageController constructor'); 604 | super(apiRequest, externalConfig); 605 | logger.debug('Exit GetHostedPaymentPageController constructor'); 606 | } 607 | 608 | validateRequest(){ 609 | logger.debug('Enter validateRequest'); 610 | 611 | logger.debug('Exit validateRequest'); 612 | return; 613 | } 614 | 615 | getRequestType(){ 616 | return 'GetHostedPaymentPageRequest'; 617 | } 618 | } 619 | 620 | module.exports.GetHostedPaymentPageController = GetHostedPaymentPageController; 621 | 622 | class GetHostedProfilePageController extends APIOperationBase { 623 | constructor(apiRequest, externalConfig = null) { 624 | var logger = Logger.getLogger('GetHostedProfilePageController', externalConfig) 625 | logger.debug('Enter GetHostedProfilePageController constructor'); 626 | super(apiRequest, externalConfig); 627 | logger.debug('Exit GetHostedProfilePageController constructor'); 628 | } 629 | 630 | validateRequest(){ 631 | logger.debug('Enter validateRequest'); 632 | 633 | logger.debug('Exit validateRequest'); 634 | return; 635 | } 636 | 637 | getRequestType(){ 638 | return 'GetHostedProfilePageRequest'; 639 | } 640 | } 641 | 642 | module.exports.GetHostedProfilePageController = GetHostedProfilePageController; 643 | 644 | class GetMerchantDetailsController extends APIOperationBase { 645 | constructor(apiRequest, externalConfig = null) { 646 | var logger = Logger.getLogger('GetMerchantDetailsController', externalConfig) 647 | logger.debug('Enter GetMerchantDetailsController constructor'); 648 | super(apiRequest, externalConfig); 649 | logger.debug('Exit GetMerchantDetailsController constructor'); 650 | } 651 | 652 | validateRequest(){ 653 | logger.debug('Enter validateRequest'); 654 | 655 | logger.debug('Exit validateRequest'); 656 | return; 657 | } 658 | 659 | getRequestType(){ 660 | return 'GetMerchantDetailsRequest'; 661 | } 662 | } 663 | 664 | module.exports.GetMerchantDetailsController = GetMerchantDetailsController; 665 | 666 | class GetSettledBatchListController extends APIOperationBase { 667 | constructor(apiRequest, externalConfig = null) { 668 | var logger = Logger.getLogger('GetSettledBatchListController', externalConfig) 669 | logger.debug('Enter GetSettledBatchListController constructor'); 670 | super(apiRequest, externalConfig); 671 | logger.debug('Exit GetSettledBatchListController constructor'); 672 | } 673 | 674 | validateRequest(){ 675 | logger.debug('Enter validateRequest'); 676 | 677 | logger.debug('Exit validateRequest'); 678 | return; 679 | } 680 | 681 | getRequestType(){ 682 | return 'GetSettledBatchListRequest'; 683 | } 684 | } 685 | 686 | module.exports.GetSettledBatchListController = GetSettledBatchListController; 687 | 688 | class GetTransactionDetailsController extends APIOperationBase { 689 | constructor(apiRequest, externalConfig = null) { 690 | var logger = Logger.getLogger('GetTransactionDetailsController', externalConfig) 691 | logger.debug('Enter GetTransactionDetailsController constructor'); 692 | super(apiRequest, externalConfig); 693 | logger.debug('Exit GetTransactionDetailsController constructor'); 694 | } 695 | 696 | validateRequest(){ 697 | logger.debug('Enter validateRequest'); 698 | 699 | logger.debug('Exit validateRequest'); 700 | return; 701 | } 702 | 703 | getRequestType(){ 704 | return 'GetTransactionDetailsRequest'; 705 | } 706 | } 707 | 708 | module.exports.GetTransactionDetailsController = GetTransactionDetailsController; 709 | 710 | class GetTransactionListController extends APIOperationBase { 711 | constructor(apiRequest, externalConfig = null) { 712 | var logger = Logger.getLogger('GetTransactionListController', externalConfig) 713 | logger.debug('Enter GetTransactionListController constructor'); 714 | super(apiRequest, externalConfig); 715 | logger.debug('Exit GetTransactionListController constructor'); 716 | } 717 | 718 | validateRequest(){ 719 | logger.debug('Enter validateRequest'); 720 | 721 | logger.debug('Exit validateRequest'); 722 | return; 723 | } 724 | 725 | getRequestType(){ 726 | return 'GetTransactionListRequest'; 727 | } 728 | } 729 | 730 | module.exports.GetTransactionListController = GetTransactionListController; 731 | 732 | class GetTransactionListForCustomerController extends APIOperationBase { 733 | constructor(apiRequest, externalConfig = null) { 734 | var logger = Logger.getLogger('GetTransactionListForCustomerController', externalConfig) 735 | logger.debug('Enter GetTransactionListForCustomerController constructor'); 736 | super(apiRequest, externalConfig); 737 | logger.debug('Exit GetTransactionListForCustomerController constructor'); 738 | } 739 | 740 | validateRequest(){ 741 | logger.debug('Enter validateRequest'); 742 | 743 | logger.debug('Exit validateRequest'); 744 | return; 745 | } 746 | 747 | getRequestType(){ 748 | return 'GetTransactionListForCustomerRequest'; 749 | } 750 | } 751 | 752 | module.exports.GetTransactionListForCustomerController = GetTransactionListForCustomerController; 753 | 754 | class GetUnsettledTransactionListController extends APIOperationBase { 755 | constructor(apiRequest, externalConfig = null) { 756 | var logger = Logger.getLogger('GetUnsettledTransactionListController', externalConfig) 757 | logger.debug('Enter GetUnsettledTransactionListController constructor'); 758 | super(apiRequest, externalConfig); 759 | logger.debug('Exit GetUnsettledTransactionListController constructor'); 760 | } 761 | 762 | validateRequest(){ 763 | logger.debug('Enter validateRequest'); 764 | 765 | logger.debug('Exit validateRequest'); 766 | return; 767 | } 768 | 769 | getRequestType(){ 770 | return 'GetUnsettledTransactionListRequest'; 771 | } 772 | } 773 | 774 | module.exports.GetUnsettledTransactionListController = GetUnsettledTransactionListController; 775 | 776 | class IsAliveController extends APIOperationBase { 777 | constructor(apiRequest, externalConfig = null) { 778 | var logger = Logger.getLogger('IsAliveController', externalConfig) 779 | logger.debug('Enter IsAliveController constructor'); 780 | super(apiRequest, externalConfig); 781 | logger.debug('Exit IsAliveController constructor'); 782 | } 783 | 784 | validateRequest(){ 785 | logger.debug('Enter validateRequest'); 786 | 787 | logger.debug('Exit validateRequest'); 788 | return; 789 | } 790 | 791 | getRequestType(){ 792 | return 'IsAliveRequest'; 793 | } 794 | } 795 | 796 | module.exports.IsAliveController = IsAliveController; 797 | 798 | class LogoutController extends APIOperationBase { 799 | constructor(apiRequest, externalConfig = null) { 800 | var logger = Logger.getLogger('LogoutController', externalConfig) 801 | logger.debug('Enter LogoutController constructor'); 802 | super(apiRequest, externalConfig); 803 | logger.debug('Exit LogoutController constructor'); 804 | } 805 | 806 | validateRequest(){ 807 | logger.debug('Enter validateRequest'); 808 | 809 | logger.debug('Exit validateRequest'); 810 | return; 811 | } 812 | 813 | getRequestType(){ 814 | return 'LogoutRequest'; 815 | } 816 | } 817 | 818 | module.exports.LogoutController = LogoutController; 819 | 820 | class MobileDeviceLoginController extends APIOperationBase { 821 | constructor(apiRequest, externalConfig = null) { 822 | var logger = Logger.getLogger('MobileDeviceLoginController', externalConfig) 823 | logger.debug('Enter MobileDeviceLoginController constructor'); 824 | super(apiRequest, externalConfig); 825 | logger.debug('Exit MobileDeviceLoginController constructor'); 826 | } 827 | 828 | validateRequest(){ 829 | logger.debug('Enter validateRequest'); 830 | 831 | logger.debug('Exit validateRequest'); 832 | return; 833 | } 834 | 835 | getRequestType(){ 836 | return 'MobileDeviceLoginRequest'; 837 | } 838 | } 839 | 840 | module.exports.MobileDeviceLoginController = MobileDeviceLoginController; 841 | 842 | class MobileDeviceRegistrationController extends APIOperationBase { 843 | constructor(apiRequest, externalConfig = null) { 844 | var logger = Logger.getLogger('MobileDeviceRegistrationController', externalConfig) 845 | logger.debug('Enter MobileDeviceRegistrationController constructor'); 846 | super(apiRequest, externalConfig); 847 | logger.debug('Exit MobileDeviceRegistrationController constructor'); 848 | } 849 | 850 | validateRequest(){ 851 | logger.debug('Enter validateRequest'); 852 | 853 | logger.debug('Exit validateRequest'); 854 | return; 855 | } 856 | 857 | getRequestType(){ 858 | return 'MobileDeviceRegistrationRequest'; 859 | } 860 | } 861 | 862 | module.exports.MobileDeviceRegistrationController = MobileDeviceRegistrationController; 863 | 864 | class SecurePaymentContainerController extends APIOperationBase { 865 | constructor(apiRequest, externalConfig = null) { 866 | var logger = Logger.getLogger('SecurePaymentContainerController', externalConfig) 867 | logger.debug('Enter SecurePaymentContainerController constructor'); 868 | super(apiRequest, externalConfig); 869 | logger.debug('Exit SecurePaymentContainerController constructor'); 870 | } 871 | 872 | validateRequest(){ 873 | logger.debug('Enter validateRequest'); 874 | 875 | logger.debug('Exit validateRequest'); 876 | return; 877 | } 878 | 879 | getRequestType(){ 880 | return 'SecurePaymentContainerRequest'; 881 | } 882 | } 883 | 884 | module.exports.SecurePaymentContainerController = SecurePaymentContainerController; 885 | 886 | class SendCustomerTransactionReceiptController extends APIOperationBase { 887 | constructor(apiRequest, externalConfig = null) { 888 | var logger = Logger.getLogger('SendCustomerTransactionReceiptController', externalConfig) 889 | logger.debug('Enter SendCustomerTransactionReceiptController constructor'); 890 | super(apiRequest, externalConfig); 891 | logger.debug('Exit SendCustomerTransactionReceiptController constructor'); 892 | } 893 | 894 | validateRequest(){ 895 | logger.debug('Enter validateRequest'); 896 | 897 | logger.debug('Exit validateRequest'); 898 | return; 899 | } 900 | 901 | getRequestType(){ 902 | return 'SendCustomerTransactionReceiptRequest'; 903 | } 904 | } 905 | 906 | module.exports.SendCustomerTransactionReceiptController = SendCustomerTransactionReceiptController; 907 | 908 | class UpdateCustomerPaymentProfileController extends APIOperationBase { 909 | constructor(apiRequest, externalConfig = null) { 910 | var logger = Logger.getLogger('UpdateCustomerPaymentProfileController', externalConfig) 911 | logger.debug('Enter UpdateCustomerPaymentProfileController constructor'); 912 | super(apiRequest, externalConfig); 913 | logger.debug('Exit UpdateCustomerPaymentProfileController constructor'); 914 | } 915 | 916 | validateRequest(){ 917 | logger.debug('Enter validateRequest'); 918 | 919 | logger.debug('Exit validateRequest'); 920 | return; 921 | } 922 | 923 | getRequestType(){ 924 | return 'UpdateCustomerPaymentProfileRequest'; 925 | } 926 | } 927 | 928 | module.exports.UpdateCustomerPaymentProfileController = UpdateCustomerPaymentProfileController; 929 | 930 | class UpdateCustomerProfileController extends APIOperationBase { 931 | constructor(apiRequest, externalConfig = null) { 932 | var logger = Logger.getLogger('UpdateCustomerProfileController', externalConfig) 933 | logger.debug('Enter UpdateCustomerProfileController constructor'); 934 | super(apiRequest, externalConfig); 935 | logger.debug('Exit UpdateCustomerProfileController constructor'); 936 | } 937 | 938 | validateRequest(){ 939 | logger.debug('Enter validateRequest'); 940 | 941 | logger.debug('Exit validateRequest'); 942 | return; 943 | } 944 | 945 | getRequestType(){ 946 | return 'UpdateCustomerProfileRequest'; 947 | } 948 | } 949 | 950 | module.exports.UpdateCustomerProfileController = UpdateCustomerProfileController; 951 | 952 | class UpdateCustomerShippingAddressController extends APIOperationBase { 953 | constructor(apiRequest, externalConfig = null) { 954 | var logger = Logger.getLogger('UpdateCustomerShippingAddressController', externalConfig) 955 | logger.debug('Enter UpdateCustomerShippingAddressController constructor'); 956 | super(apiRequest, externalConfig); 957 | logger.debug('Exit UpdateCustomerShippingAddressController constructor'); 958 | } 959 | 960 | validateRequest(){ 961 | logger.debug('Enter validateRequest'); 962 | 963 | logger.debug('Exit validateRequest'); 964 | return; 965 | } 966 | 967 | getRequestType(){ 968 | return 'UpdateCustomerShippingAddressRequest'; 969 | } 970 | } 971 | 972 | module.exports.UpdateCustomerShippingAddressController = UpdateCustomerShippingAddressController; 973 | 974 | class UpdateHeldTransactionController extends APIOperationBase { 975 | constructor(apiRequest, externalConfig = null) { 976 | var logger = Logger.getLogger('UpdateHeldTransactionController', externalConfig) 977 | logger.debug('Enter UpdateHeldTransactionController constructor'); 978 | super(apiRequest, externalConfig); 979 | logger.debug('Exit UpdateHeldTransactionController constructor'); 980 | } 981 | 982 | validateRequest(){ 983 | logger.debug('Enter validateRequest'); 984 | 985 | logger.debug('Exit validateRequest'); 986 | return; 987 | } 988 | 989 | getRequestType(){ 990 | return 'UpdateHeldTransactionRequest'; 991 | } 992 | } 993 | 994 | module.exports.UpdateHeldTransactionController = UpdateHeldTransactionController; 995 | 996 | class UpdateMerchantDetailsController extends APIOperationBase { 997 | constructor(apiRequest, externalConfig = null) { 998 | var logger = Logger.getLogger('UpdateMerchantDetailsController', externalConfig) 999 | logger.debug('Enter UpdateMerchantDetailsController constructor'); 1000 | super(apiRequest, externalConfig); 1001 | logger.debug('Exit UpdateMerchantDetailsController constructor'); 1002 | } 1003 | 1004 | validateRequest(){ 1005 | logger.debug('Enter validateRequest'); 1006 | 1007 | logger.debug('Exit validateRequest'); 1008 | return; 1009 | } 1010 | 1011 | getRequestType(){ 1012 | return 'UpdateMerchantDetailsRequest'; 1013 | } 1014 | } 1015 | 1016 | module.exports.UpdateMerchantDetailsController = UpdateMerchantDetailsController; 1017 | 1018 | class UpdateSplitTenderGroupController extends APIOperationBase { 1019 | constructor(apiRequest, externalConfig = null) { 1020 | var logger = Logger.getLogger('UpdateSplitTenderGroupController', externalConfig) 1021 | logger.debug('Enter UpdateSplitTenderGroupController constructor'); 1022 | super(apiRequest, externalConfig); 1023 | logger.debug('Exit UpdateSplitTenderGroupController constructor'); 1024 | } 1025 | 1026 | validateRequest(){ 1027 | logger.debug('Enter validateRequest'); 1028 | 1029 | logger.debug('Exit validateRequest'); 1030 | return; 1031 | } 1032 | 1033 | getRequestType(){ 1034 | return 'UpdateSplitTenderGroupRequest'; 1035 | } 1036 | } 1037 | 1038 | module.exports.UpdateSplitTenderGroupController = UpdateSplitTenderGroupController; 1039 | 1040 | class ValidateCustomerPaymentProfileController extends APIOperationBase { 1041 | constructor(apiRequest, externalConfig = null) { 1042 | var logger = Logger.getLogger('ValidateCustomerPaymentProfileController', externalConfig) 1043 | logger.debug('Enter ValidateCustomerPaymentProfileController constructor'); 1044 | super(apiRequest, externalConfig); 1045 | logger.debug('Exit ValidateCustomerPaymentProfileController constructor'); 1046 | } 1047 | 1048 | validateRequest(){ 1049 | logger.debug('Enter validateRequest'); 1050 | 1051 | logger.debug('Exit validateRequest'); 1052 | return; 1053 | } 1054 | 1055 | getRequestType(){ 1056 | return 'ValidateCustomerPaymentProfileRequest'; 1057 | } 1058 | } 1059 | 1060 | module.exports.ValidateCustomerPaymentProfileController = ValidateCustomerPaymentProfileController; 1061 | 1062 | -------------------------------------------------------------------------------- /lib/apicontrollersbase.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var axios = require('axios'); 4 | var HttpsProxyAgent = require('https-proxy-agent').HttpsProxyAgent; 5 | const Logger = require('./logger.js'); 6 | var config = require('./config').config; 7 | var constants = require('./constants').constants; 8 | 9 | var logger; 10 | 11 | class APIOperationBase { 12 | constructor(apiRequest, externalConfig = null) { 13 | logger = Logger.getLogger('ApiOperationBase', externalConfig); 14 | logger.debug('Enter APIOperationBase constructor'); 15 | 16 | this._request = null; 17 | this._response = null; 18 | this._error = null; 19 | this._endpoint = constants.endpoint.sandbox; 20 | 21 | if (externalConfig) config = externalConfig; 22 | 23 | if (null == apiRequest) 24 | logger.error('Input request cannot be null'); 25 | 26 | this._request = apiRequest; 27 | 28 | logger.debug('Exit APIOperationBase constructor'); 29 | } 30 | 31 | //abstract 32 | validateRequest() { 33 | return; 34 | } 35 | 36 | validate() { 37 | return; 38 | } 39 | 40 | getResponse() { 41 | return this._response; 42 | } 43 | 44 | getError() { 45 | return this._error; 46 | } 47 | 48 | getResultcode() { 49 | var resultcode = null; 50 | 51 | if (this._response) 52 | resultcode = this._response.resultCode; 53 | 54 | return resultcode; 55 | } 56 | 57 | getMessagetype() { 58 | var message = null; 59 | 60 | if (this._response) { 61 | message = this._response.message; 62 | } 63 | 64 | return message; 65 | } 66 | 67 | beforeExecute() { 68 | } 69 | 70 | setClientId() { 71 | for (var obj in this._request) { 72 | this._request[obj]['clientId'] = config.clientId; 73 | break; 74 | } 75 | } 76 | 77 | setEnvironment(env) { 78 | this._endpoint = env; 79 | } 80 | 81 | execute(callback) { 82 | logger.debug('Enter APIOperationBase execute'); 83 | 84 | logger.debug('Endpoint : ' + this._endpoint); 85 | 86 | this.beforeExecute(); 87 | 88 | this.setClientId(); 89 | 90 | var obj = this; 91 | 92 | logger.debug(JSON.stringify(this._request, 2, null)); 93 | 94 | var axiosConfig = { 95 | baseURL: this._endpoint, 96 | method: 'POST', 97 | proxy: false, 98 | timeout: config.timeout, 99 | data: JSON.parse(JSON.stringify(this._request)) 100 | }; 101 | 102 | if (config.proxy.setProxy) { 103 | const agent = new HttpsProxyAgent(config.proxy.proxyUrl); 104 | axiosConfig.httpsAgent = agent; 105 | } 106 | 107 | axios.request(axiosConfig).then((response) => { 108 | if (typeof response.data !== 'undefined') { 109 | var responseObj = JSON.parse(JSON.stringify(response.data)); 110 | logger.debug(JSON.stringify(responseObj, 2, null)); 111 | obj._response = responseObj; 112 | callback(); 113 | } else { 114 | logger.error("Undefined Response"); 115 | } 116 | }).catch(error => { 117 | obj._error = error; 118 | logger.error(error); 119 | }); 120 | 121 | logger.debug('Exit APIOperationBase execute'); 122 | } 123 | } 124 | 125 | module.exports.APIOperationBase = APIOperationBase; 126 | -------------------------------------------------------------------------------- /lib/authorizenet.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | APIContracts: require('./apicontracts.js'), 5 | APIControllers: require('./apicontrollers.js'), 6 | Constants: require('./constants.js').constants 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /lib/config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var pkg = require('../package.json'); 3 | 4 | var config = { 5 | 'timeout': 120000, 6 | 'clientId': 'sdk-node-' + pkg.version, 7 | 'logger': { 8 | 'enabled': false, 9 | 'location': './', 10 | //logging levels - { error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 11 | 'level': 'debug' 12 | }, 13 | 'proxy': { 14 | 'setProxy':false, 15 | 'proxyUrl':'http://proxy.yourcompany.com:80' 16 | } 17 | }; 18 | 19 | module.exports.config = config; 20 | -------------------------------------------------------------------------------- /lib/constants.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var constants = { 4 | 'endpoint': { 5 | 'sandbox': 'https://apitest.authorize.net/xml/v1/request.api', 6 | 'production': 'https://api2.authorize.net/xml/v1/request.api' 7 | } 8 | }; 9 | 10 | module.exports.constants = constants; -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | var winston = require('winston'); 2 | const { format } = require('winston'); 3 | const { combine, timestamp, label, printf } = format; 4 | require('winston-daily-rotate-file'); 5 | var config = require('./config').config; 6 | 7 | var sensitiveFields = ['cardCode', 'cardNumber', 'expirationDate', 'accountNumber', 'nameOnAccount', 'transactionKey', 'email', 'phoneNumber', 'faxNumber', 'dateOfBirth']; 8 | 9 | const maskedLoggingFormat = printf(({ level, message, label, timestamp }) => { 10 | if (isJson(message)) { 11 | return `[${timestamp}] [${level.toUpperCase()}] [${label}] : ${maskSensitiveFields(JSON.parse(message))}`; 12 | } else { 13 | return `[${timestamp}] [${level.toUpperCase()}] [${label}] : ${message}`; 14 | } 15 | }); 16 | 17 | function isJson(str) { 18 | try { 19 | JSON.parse(str); 20 | } catch (e) { 21 | return false; 22 | } 23 | return true; 24 | } 25 | 26 | function createTransportFromConfig(tempConfig) { 27 | var transports = []; 28 | 29 | var enableLog = tempConfig.logger.enabled; 30 | var loggingLevel = tempConfig.logger.level; 31 | var logDirectory = tempConfig.logger.location; 32 | 33 | transports.push(new winston.transports.DailyRotateFile({ 34 | level: loggingLevel, 35 | filename: 'sdk-node-%DATE%.log', 36 | datePattern: 'YYYY-MM-DD', 37 | zippedArchive: true, 38 | dirname: logDirectory, 39 | silent: !enableLog 40 | })); 41 | 42 | return transports; 43 | } 44 | 45 | exports.getLogger = function (loggerCategory = 'LoggerInstance', mconfig = null) { 46 | var loggerConfig = mconfig ? mconfig : config; 47 | 48 | var enableLog = loggerConfig.logger.enabled; 49 | var loggingLevel = loggerConfig.logger.level; 50 | 51 | var loggerCategoryRandomiser = Math.floor(Math.random() * (1000000000 - 100 + 1)) + 100; 52 | loggerCategory = loggerCategory + loggerCategoryRandomiser; 53 | 54 | var newLogger; 55 | 56 | if (enableLog) { 57 | var appTransports = createTransportFromConfig(loggerConfig); 58 | 59 | newLogger = winston.loggers.get(loggerCategory, { 60 | level: loggingLevel, 61 | format: combine( 62 | label({ label: loggerCategory }), 63 | timestamp(), 64 | maskedLoggingFormat 65 | ), 66 | transports: appTransports 67 | }); 68 | } else { 69 | newLogger = winston.loggers.get(loggerCategory, { 70 | level: loggingLevel, 71 | format: combine( 72 | label({ label: loggerCategory }), 73 | timestamp(), 74 | maskedLoggingFormat 75 | ), 76 | transports: [new winston.transports.Console({ 77 | silent: !enableLog 78 | })] 79 | }); 80 | } 81 | 82 | return newLogger; 83 | } 84 | 85 | function maskSensitiveFields(jsonMsg) { 86 | if (jsonMsg instanceof Object) { 87 | var prop; 88 | 89 | for (prop in jsonMsg) { 90 | var isFieldSensitive = (sensitiveFields.indexOf(prop) > -1); 91 | 92 | if (isFieldSensitive === true) { 93 | jsonMsg[prop] = new Array(jsonMsg[prop].length + 1).join('X'); 94 | } 95 | else if (jsonMsg.hasOwnProperty(prop)) { 96 | maskSensitiveFields(jsonMsg[prop]); 97 | } 98 | } 99 | } 100 | 101 | return JSON.stringify(jsonMsg); 102 | } 103 | 104 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function delete_null_properties(test, recurse) { 4 | for (var i in test) { 5 | //skip clientId here, as we are setting it in apicontrollerbase.js 6 | if(i == 'clientId') 7 | continue; 8 | if (test[i] === null) { 9 | delete test[i]; 10 | } else if (recurse && typeof test[i] === 'object') { 11 | delete_null_properties(test[i], recurse); 12 | } 13 | } 14 | } 15 | 16 | module.exports.delete_null_properties = delete_null_properties; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "authorizenet", 3 | "version": "1.0.10", 4 | "description": "nodejs sdk for Authorize.Net", 5 | "main": "lib/authorizenet.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "dependencies": { 10 | "axios": "1.8.3", 11 | "https-proxy-agent": "^7.0.0", 12 | "winston": "^3.11.0", 13 | "winston-daily-rotate-file": "^4.7.1" 14 | }, 15 | "devDependencies": { 16 | "chai": "^3.5.0", 17 | "eslint": "^6.6.0", 18 | "jsonix": "^3.0.0", 19 | "mocha": "^8.2.1" 20 | }, 21 | "scripts": { 22 | "test": "mocha" 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/AuthorizeNet/sdk-node.git" 27 | }, 28 | "keywords": [ 29 | "nodejs", 30 | "Authorize.Net" 31 | ], 32 | "author": "", 33 | "license": "ISC", 34 | "bugs": { 35 | "url": "https://github.com/AuthorizeNet/sdk-node/issues" 36 | }, 37 | "homepage": "https://github.com/AuthorizeNet/sdk-node#readme" 38 | } 39 | -------------------------------------------------------------------------------- /sample/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var AuthenticateTestController = require('../lib/apicontrollers.js').AuthenticateTestController; 4 | 5 | var ApiContracts = require('../lib/apicontracts.js'); 6 | var Constants = require('../lib/constants.js').constants; 7 | 8 | var merchant = new ApiContracts.MerchantAuthenticationType(); 9 | merchant.setName('5KP3u95bQpv'); 10 | merchant.setTransactionKey('346HZ32z3fP4hTG2'); 11 | 12 | var request = new ApiContracts.AuthenticateTestRequest(); 13 | request.setMerchantAuthentication(merchant); 14 | 15 | var ctrl = new AuthenticateTestController(request.getJSON()); 16 | //ctrl.setEnvironment(Constants.endpoint.sandbox); 17 | 18 | ctrl.execute(function() { 19 | 20 | var apiResponse = ctrl.getResponse(); 21 | 22 | var response = new ApiContracts.AuthenticateTestResponse(apiResponse); 23 | 24 | console.log('Result Code: '+ JSON.stringify(response.getMessages().getResultCode())); 25 | console.log('Message List: '+ JSON.stringify(response.getMessages().getMessage())); 26 | console.log('Code: '+ JSON.stringify(response.getMessages().getMessage()[0].getCode())); 27 | console.log('Text: '+ JSON.stringify(response.getMessages().getMessage()[0].getText())); 28 | }); 29 | -------------------------------------------------------------------------------- /scripts/ControllerTemplate.jst: -------------------------------------------------------------------------------- 1 | class APICONTROLLERNAMEController extends APIOperationBase { 2 | constructor(apiRequest, externalConfig = null) { 3 | var logger = Logger.getLogger('APICONTROLLERNAMEController', externalConfig) 4 | logger.debug('Enter APICONTROLLERNAMEController constructor'); 5 | super(apiRequest, externalConfig); 6 | logger.debug('Exit APICONTROLLERNAMEController constructor'); 7 | } 8 | 9 | validateRequest(){ 10 | logger.debug('Enter validateRequest'); 11 | 12 | logger.debug('Exit validateRequest'); 13 | return; 14 | } 15 | 16 | getRequestType(){ 17 | return 'APICONTROLLERNAMERequest'; 18 | } 19 | } 20 | 21 | module.exports.APICONTROLLERNAMEController = APICONTROLLERNAMEController; 22 | 23 | -------------------------------------------------------------------------------- /scripts/generateControllersFromSchema.js: -------------------------------------------------------------------------------- 1 | var schema = require('../mappings/Schema.js').Schema; 2 | 3 | var controllerSet = new Set(); 4 | 5 | for (var i = 0; i < schema.elementInfos.length; i++) { 6 | var obj = schema.elementInfos[i]; 7 | if (obj['typeInfo'] != null) { 8 | var objName = ''; 9 | if (obj['typeInfo'].match('Request' + '$') == 'Request') { 10 | objName = obj['typeInfo'].replace(/Request$/, ''); 11 | //console.log(objName); 12 | controllerSet.add(objName.slice(1)); 13 | } 14 | 15 | if (obj['typeInfo'].match('Response' + '$') == 'Response') { 16 | objName = obj['typeInfo'].replace(/Response$/, ''); 17 | //console.log(objName); 18 | controllerSet.add(objName.slice(1)); 19 | } 20 | } 21 | } 22 | 23 | Array.from(controllerSet).sort().forEach(function (value) { 24 | console.log(value); 25 | }); 26 | 27 | -------------------------------------------------------------------------------- /scripts/generateControllersFromSchema.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script to generate controllers from the generated bindings file, and uses template 4 | currdir=`pwd` 5 | 6 | dt=`date '+%m/%d/%Y %H:%M:%S'` 7 | echo Starting ${dt} 8 | 9 | CDIR=`pwd` 10 | SRCDIR=${CDIR} 11 | TEMPCONTROLLERFOLDER=controllertemp 12 | SRCLOG=${CDIR}/log/Objects.log 13 | NEWCONTROLLERFILE=apicontrollers.new.js 14 | 15 | mkdir -p ${CDIR}/log 16 | 17 | mkdir -p ${SRCDIR}/${TEMPCONTROLLERFOLDER} 18 | 19 | node scripts/generateControllersFromSchema.js > "${SRCLOG}" 20 | 21 | echo Creating Controllers 22 | for cntrls in `cat "${SRCLOG}"`; 23 | do 24 | echo Generating Code for ${cntrls}Controller.js 25 | cp ${SRCDIR}/scripts/ControllerTemplate.jst ${SRCDIR}/${TEMPCONTROLLERFOLDER}/${cntrls}Controller.js 26 | perl -pi -w -e "s/APICONTROLLERNAME/$cntrls/g;" ${SRCDIR}/${TEMPCONTROLLERFOLDER}/${cntrls}Controller.js 27 | done 28 | 29 | cat ${SRCDIR}/scripts/headertemplate.jst ${SRCDIR}/${TEMPCONTROLLERFOLDER}/*.js > ${SRCDIR}/lib/${NEWCONTROLLERFILE} 30 | 31 | rm -rf ${CDIR}/log 32 | 33 | rm -rf ${SRCDIR}/${TEMPCONTROLLERFOLDER} 34 | 35 | echo Controllers generated in module: ${SRCDIR}/lib/${NEWCONTROLLERFILE} 36 | echo Check difference between ${NEWCONTROLLERFILE} and apicontrollers.js and apply to apicontrollers.js 37 | 38 | echo Finished ${dt} 39 | 40 | -------------------------------------------------------------------------------- /scripts/generateObjectsFromSchema.js: -------------------------------------------------------------------------------- 1 | var schema = require('../mappings/Schema.js').Schema; 2 | 3 | var newline = '\n'; 4 | var tabcount = 1; 5 | var tab = '\t'; 6 | 7 | console.log('\'use strict\';' + newline); 8 | console.log('var utils = require(\'./utils.js\');' + newline); 9 | console.log('const Logger = require(\'./logger.js\');' + newline); 10 | 11 | 12 | var elementInfo = {}; 13 | var baseInfo = {}; 14 | 15 | var classes = []; 16 | var level1InnerClasses = []; 17 | var level2InnerClasses = []; 18 | var level1ExtendedClasses = []; 19 | var level2ExtendedClasses = []; 20 | var enums = []; 21 | 22 | var i = 0; 23 | for (i = 0; i < schema.elementInfos.length; i++) { 24 | var info = schema.elementInfos[i]; 25 | elementInfo[info['typeInfo'].slice(1)] = info['elementName']; 26 | } 27 | 28 | for (i = 0; i < schema.typeInfos.length; i++) { 29 | var info = schema.typeInfos[i]; 30 | if (info['baseTypeInfo'] != null) 31 | baseInfo[info['localName']] = info['baseTypeInfo'].slice(1); 32 | else 33 | baseInfo[info['localName']] = null; 34 | } 35 | 36 | for (i = 0; i < schema.typeInfos.length; i++) { 37 | var obj = schema.typeInfos[i]; 38 | tabcount = 1; 39 | 40 | var classDefinition = new String(); 41 | 42 | if ((obj['type'] != null) && obj['type'] == 'enumInfo') { 43 | classDefinition = 'const ' + obj['localName'] + ' = { ' + newline; 44 | for (var k = 0; k < obj['values'].length; k++) { 45 | var val = obj['values'][k]; 46 | if (k != 0) 47 | classDefinition += ',' + newline; 48 | classDefinition += tab.repeat(tabcount) + val.toUpperCase() + ' : \'' + val + '\''; 49 | } 50 | classDefinition += newline + '};' + newline; 51 | classDefinition += 'module.exports.' + obj['localName'] + ' = ' + obj['localName'] + ';' + newline; 52 | 53 | enums.push(classDefinition); 54 | continue; 55 | } 56 | 57 | if (obj['localName'].indexOf('.') > -1) 58 | classDefinition = obj['localName'] + ' = ' + 'class'; 59 | else 60 | classDefinition = 'class ' + obj['localName']; 61 | 62 | if (obj['baseTypeInfo'] != null) 63 | classDefinition += ' extends ' + obj['baseTypeInfo'].slice(1); 64 | 65 | classDefinition += ' {'; 66 | 67 | classDefinition += newline; 68 | 69 | if ((obj['localName'].match('Request' + '$') == 'Request') || (obj['localName'].match('Response' + '$') == 'Response')) { 70 | if (elementInfo[obj['localName']] != null) { 71 | var getJSONfunc = tab.repeat(tabcount) + 'getJSON() { ' + newline; 72 | tabcount++; 73 | getJSONfunc += tab.repeat(tabcount) + 'var logger = Logger.getLogger(\'' + obj['localName'] + '\');' + newline; 74 | getJSONfunc += tab.repeat(tabcount) + 'logger.debug(\'Enter ' + obj['localName'] + ' getJSON\');' + newline; 75 | getJSONfunc += tab.repeat(tabcount) + 'utils.delete_null_properties(this, true);' + newline; 76 | getJSONfunc += tab.repeat(tabcount) + 'var obj = { \'' + elementInfo[obj['localName']] + '\' : this };' + newline; 77 | getJSONfunc += tab.repeat(tabcount) + 'logger.debug(\'Exit ' + obj['localName'] + ' getJSON\');' + newline; 78 | getJSONfunc += tab.repeat(tabcount) + 'return obj;' + newline; 79 | tabcount--; 80 | getJSONfunc += tab.repeat(tabcount) + '}' + newline; 81 | classDefinition += getJSONfunc + newline; 82 | } 83 | } 84 | 85 | if (obj.propertyInfos != null) { 86 | /* 87 | var defaultCtor = new String('constructor('); 88 | for(var j=0;j -1) 223 | classDefinition += ';'; 224 | 225 | classDefinition += newline + newline; 226 | 227 | classDefinition += 'module.exports.' + obj['localName'] + ' = ' + obj['localName'] + ';' + newline; 228 | 229 | //console.log(classDefinition); 230 | if (obj['baseTypeInfo'] != null) { 231 | if (baseInfo[obj['baseTypeInfo'].slice(1)] != null) 232 | level2ExtendedClasses.push(classDefinition); 233 | else 234 | level1ExtendedClasses.push(classDefinition); 235 | } 236 | else if ((obj['localName'].split('.').length - 1) == 1) { 237 | //console.log('level 1 : ' + obj['localName']); 238 | level1InnerClasses.push(classDefinition); 239 | } 240 | else if ((obj['localName'].split('.').length - 1) == 2) { 241 | //console.log('level 2 : ' + obj['localName']); 242 | level2InnerClasses.push(classDefinition); 243 | } 244 | else 245 | classes.push(classDefinition); 246 | } 247 | 248 | classes.sort().forEach(function (item) { 249 | console.log(item); 250 | //console.log('classes'); 251 | }); 252 | 253 | level1InnerClasses.sort().forEach(function (item) { 254 | console.log(item); 255 | //console.log('level1InnerClasses'); 256 | }); 257 | 258 | level2InnerClasses.sort().forEach(function (item) { 259 | console.log(item); 260 | // console.log('level2InnerClasses'); 261 | }); 262 | 263 | level1ExtendedClasses.sort().forEach(function (item) { 264 | console.log(item); 265 | // console.log('level1ExtendedClasses'); 266 | }); 267 | 268 | level2ExtendedClasses.sort().forEach(function (item) { 269 | console.log(item); 270 | // console.log('level2ExtendedClasses'); 271 | }); 272 | 273 | enums.sort().forEach(function (item) { 274 | console.log(item); 275 | // console.log('level2ExtendedClasses'); 276 | }); 277 | -------------------------------------------------------------------------------- /scripts/generateObjectsFromSchema.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script to generate objects from the xsd file 4 | # to be executed from root folder of sdk 5 | 6 | currdir=`pwd` 7 | 8 | dt=`date '+%m/%d/%Y %H:%M:%S'` 9 | echo Starting ${dt} 10 | 11 | CDIR=`pwd` 12 | SRCDIR=${CDIR} 13 | 14 | # HOST=apitest.authorize.net 15 | # PROTOCOL=https 16 | # LOCALXSD=mappings/AnetApiSchema.xsd 17 | 18 | # XSD=${PROTOCOL}://${HOST}/xml/v1/schema/AnetApiSchema.xsd 19 | 20 | # echo Get Latest XSD from path - ${XSD} 21 | 22 | # wget -O ${LOCALXSD} ${XSD} 23 | 24 | # ERRORCODE=$? 25 | ERRORCODE=0 26 | 27 | if [ $ERRORCODE -eq 0 ]; then 28 | echo Generating Schema.js from XSD 29 | java -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar -d mappings -p Schema mappings/AnetApiSchema.xsd 30 | 31 | ERRORCODE=$? 32 | if [ $ERRORCODE -eq 0 ]; then 33 | echo Creating Schema Classes 34 | node scripts/generateObjectsFromSchema.js > ${SRCDIR}/lib/apicontracts.js 35 | 36 | ERRORCODE=$? 37 | if [ $ERRORCODE -ne 0 ]; then 38 | echo Failed Creating Schema Classes 39 | exit $ERRORCODE 40 | fi 41 | else 42 | echo Failed Generating Schema.js from XSD 43 | exit $ERRORCODE 44 | fi 45 | else 46 | echo Failed downloading the XSD. 47 | exit $ERRORCODE 48 | fi 49 | 50 | echo Finished ${dt} 51 | 52 | -------------------------------------------------------------------------------- /scripts/headertemplate.jst: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var APIOperationBase = require('./apicontrollersbase.js').APIOperationBase; 4 | const Logger = require('./logger.js'); 5 | 6 | -------------------------------------------------------------------------------- /scripts/masterUpdate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # master update script to update sdk for new API changes. 4 | # to be executed from root folder of sdk. 5 | 6 | currdir=`pwd` 7 | 8 | dt=`date '+%m/%d/%Y %H:%M:%S'` 9 | echo Starting ${dt} 10 | 11 | CDIR=`pwd` 12 | 13 | echo Running generateObjectsFromSchema 14 | 15 | bash scripts/generateObjectsFromSchema.sh 16 | ERRORCODE=$? 17 | if [ $ERRORCODE -ne 0 ];then 18 | echo "########################################################################" 19 | echo "Encountered error during execution of generateObjectsFromSchema.sh" 20 | exit $ERRORCODE 21 | fi 22 | 23 | echo Running generateControllersFromSchema.sh 24 | 25 | bash scripts/generateControllersFromSchema.sh 26 | 27 | ERRORCODE=$? 28 | if [ $ERRORCODE -ne 0 ];then 29 | echo "########################################################################" 30 | echo "Encountered error during execution of generateControllersFromSchema.sh" 31 | exit $ERRORCODE 32 | fi 33 | 34 | echo Finished ${dt} 35 | 36 | -------------------------------------------------------------------------------- /test/constants.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var apiLoginKey = '5KP3u95bQpv'; 4 | var transactionKey = '346HZ32z3fP4hTG2'; 5 | 6 | module.exports.apiLoginKey = apiLoginKey; 7 | module.exports.transactionKey = transactionKey; -------------------------------------------------------------------------------- /test/test-AuthenticateTest.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('assert'); 4 | var ApiContracts = require('../lib/apicontracts.js'); 5 | var ApiControllers = require('../lib/apicontrollers.js'); 6 | var constants = require('./constants.js'); 7 | 8 | var apiLoginKey = constants.apiLoginKey; 9 | var transactionKey = constants.transactionKey; 10 | 11 | describe('AuthenticateTest', function() { 12 | this.timeout(120000); 13 | describe('request', function () { 14 | var response; 15 | 16 | before(function(done){ 17 | var merchant = new ApiContracts.MerchantAuthenticationType(); 18 | merchant.setName(apiLoginKey); 19 | merchant.setTransactionKey(transactionKey); 20 | 21 | var request = new ApiContracts.AuthenticateTestRequest(); 22 | request.setMerchantAuthentication(merchant); 23 | 24 | var ctrl = new ApiControllers.AuthenticateTestController(request.getJSON()); 25 | ctrl.execute(function(){ 26 | var apiResponse = ctrl.getResponse(); 27 | 28 | response = new ApiContracts.AuthenticateTestResponse(apiResponse); 29 | 30 | //console.log(JSON.stringify(response.getMessages().getResultCode())); 31 | done(); 32 | }); 33 | }); 34 | it('should return resultcode Ok when successful', function () { 35 | assert.equal(response.getMessages().getResultCode(),'Ok'); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/test-applepaytransactions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var utils = require('./utils.js'); 5 | var constants = require('./constants.js'); 6 | var ApiControllers = require('../lib/apicontrollers.js'); 7 | var ApiContracts = require('../lib/apicontracts.js'); 8 | 9 | var apiLoginKey = constants.apiLoginKey; 10 | var transactionKey = constants.transactionKey; 11 | 12 | class ApplePayTestData { 13 | 14 | constructor(){ 15 | 16 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 17 | this.merchantAuthenticationType.setName(apiLoginKey); 18 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 19 | 20 | this.op = new ApiContracts.OpaqueDataType(); 21 | this.op.setDataDescriptor('COMMON.APPLE.INAPP.PAYMENT'); 22 | this.op.setDataValue('eyJkYXRhIjoiQkRQTldTdE1tR2V3UVVXR2c0bzdFXC9qKzFjcTFUNzhxeVU4NGI2N2l0amNZSTh3UFlBT2hzaGpoWlBycWRVcjRYd1BNYmo0emNHTWR5KysxSDJWa1BPWStCT01GMjV1YjE5Y1g0bkN2a1hVVU9UakRsbEIxVGdTcjhKSFp4Z3A5ckNnc1NVZ2JCZ0tmNjBYS3V0WGY2YWpcL284WkliS25yS1E4U2gwb3VMQUtsb1VNbit2UHU0K0E3V0tycXJhdXo5SnZPUXA2dmhJcStIS2pVY1VOQ0lUUHlGaG1PRXRxK0grdzB2UmExQ0U2V2hGQk5uQ0hxenpXS2NrQlwvMG5xTFpSVFliRjBwK3Z5QmlWYVdIZWdoRVJmSHhSdGJ6cGVjelJQUHVGc2ZwSFZzNDhvUExDXC9rXC8xTU5kNDdrelwvcEhEY1JcL0R5NmFVTStsTmZvaWx5XC9RSk4rdFMzbTBIZk90SVNBUHFPbVhlbXZyNnhKQ2pDWmxDdXcwQzltWHpcL29iSHBvZnVJRVM4cjljcUdHc1VBUERwdzdnNjQybTRQendLRitIQnVZVW5lV0RCTlNEMnU2amJBRzMiLCJ2ZXJzaW9uIjoiRUNfdjEiLCJoZWFkZXIiOnsiYXBwbGljYXRpb25EYXRhIjoiOTRlZTA1OTMzNWU1ODdlNTAxY2M0YmY5MDYxM2UwODE0ZjAwYTdiMDhiYzdjNjQ4ZmQ4NjVhMmFmNmEyMmNjMiIsInRyYW5zYWN0aW9uSWQiOiJjMWNhZjVhZTcyZjAwMzlhODJiYWQ5MmI4MjgzNjM3MzRmODViZjJmOWNhZGYxOTNkMWJhZDlkZGNiNjBhNzk1IiwiZXBoZW1lcmFsUHVibGljS2V5IjoiTUlJQlN6Q0NBUU1HQnlxR1NNNDlBZ0V3Z2ZjQ0FRRXdMQVlIS29aSXpqMEJBUUloQVBcL1wvXC9cLzhBQUFBQkFBQUFBQUFBQUFBQUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL01Gc0VJUFwvXC9cL1wvOEFBQUFCQUFBQUFBQUFBQUFBQUFBQVwvXC9cL1wvXC9cL1wvXC9cL1wvXC9cL1wvXC9cLzhCQ0JheGpYWXFqcVQ1N1BydlZWMm1JYThaUjBHc014VHNQWTd6ancrSjlKZ1N3TVZBTVNkTmdpRzV3U1RhbVo0NFJPZEpyZUJuMzZRQkVFRWF4ZlI4dUVzUWtmNHZPYmxZNlJBOG5jRGZZRXQ2ek9nOUtFNVJkaVl3cFpQNDBMaVwvaHBcL200N242MHA4RDU0V0s4NHpWMnN4WHM3THRrQm9ONzlSOVFJaEFQXC9cL1wvXC84QUFBQUFcL1wvXC9cL1wvXC9cL1wvXC9cLys4NXZxdHB4ZWVoUE81eXNMOFl5VlJBZ0VCQTBJQUJHbStnc2wwUFpGVFwva0RkVVNreHd5Zm84SnB3VFFRekJtOWxKSm5tVGw0REdVdkFENEdzZUdqXC9wc2hCWjBLM1RldXFEdFwvdERMYkUrOFwvbTB5Q21veHc9IiwicHVibGljS2V5SGFzaCI6IlwvYmI5Q05DMzZ1QmhlSEZQYm1vaEI3T28xT3NYMkora0pxdjQ4ek9WVmlRPSJ9LCJzaWduYXR1cmUiOiJNSUlEUWdZSktvWklodmNOQVFjQ29JSURNekNDQXk4Q0FRRXhDekFKQmdVckRnTUNHZ1VBTUFzR0NTcUdTSWIzRFFFSEFhQ0NBaXN3Z2dJbk1JSUJsS0FEQWdFQ0FoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQXdKekVsTUNNR0ExVUVBeDRjQUdNQWFBQnRBR0VBYVFCQUFIWUFhUUJ6QUdFQUxnQmpBRzhBYlRBZUZ3MHhOREF4TURFd05qQXdNREJhRncweU5EQXhNREV3TmpBd01EQmFNQ2N4SlRBakJnTlZCQU1lSEFCakFHZ0FiUUJoQUdrQVFBQjJBR2tBY3dCaEFDNEFZd0J2QUcwd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFOQzgra2d0Z212V0YxT3pqZ0ROcmpURUJSdW9cLzVNS3ZsTTE0NnBBZjdHeDQxYmxFOXc0ZklYSkFEN0ZmTzdRS2pJWFlOdDM5ckx5eTd4RHdiXC81SWtaTTYwVFoyaUkxcGo1NVVjOGZkNGZ6T3BrM2Z0WmFRR1hOTFlwdEcxZDlWN0lTODJPdXA5TU1vMUJQVnJYVFBITmNzTTk5RVBVblBxZGJlR2M4N20wckFnTUJBQUdqWERCYU1GZ0dBMVVkQVFSUk1FK0FFSFpXUHJXdEpkN1laNDMxaENnN1lGU2hLVEFuTVNVd0l3WURWUVFESGh3QVl3Qm9BRzBBWVFCcEFFQUFkZ0JwQUhNQVlRQXVBR01BYndCdGdoQmNsK1BmMytVNHBrMTNuVkQ5bndRUU1Ba0dCU3NPQXdJZEJRQURnWUVBYlVLWUNrdUlLUzlRUTJtRmNNWVJFSW0ybCtYZzhcL0pYditHQlZRSmtPS29zY1k0aU5ERkFcL2JRbG9nZjlMTFU4NFRId05SbnN2VjNQcnY3UlRZODFncTBkdEM4elljQWFBa0NISUkzeXFNbko0QU91NkVPVzlrSmsyMzJnU0U3V2xDdEhiZkxTS2Z1U2dRWDhLWFFZdVpMazJScjYzTjhBcFhzWHdCTDNjSjB4Z2VBd2dkMENBUUV3T3pBbk1TVXdJd1lEVlFRREhod0FZd0JvQUcwQVlRQnBBRUFBZGdCcEFITUFZUUF1QUdNQWJ3QnRBaEJjbCtQZjMrVTRwazEzblZEOW53UVFNQWtHQlNzT0F3SWFCUUF3RFFZSktvWklodmNOQVFFQkJRQUVnWUJhSzNFbE9zdGJIOFdvb3NlREFCZitKZ1wvMTI5SmNJYXdtN2M2VnhuN1phc05iQXEzdEF0OFB0eSt1UUNnc3NYcVprTEE3a3oyR3pNb2xOdHY5d1ltdTlVandhcjFQSFlTK0JcL29Hbm96NTkxd2phZ1hXUnowbk1vNXkzTzFLelgwZDhDUkhBVmE4OFNyVjFhNUpJaVJldjNvU3RJcXd2NXh1WmxkYWc2VHI4dz09In0='); 23 | 24 | this.paymentOne = new ApiContracts.PaymentType(); 25 | this.paymentOne.setOpaqueData(this.op); 26 | } 27 | } 28 | 29 | describe('Apple Pay', function() { 30 | this.timeout(120000); 31 | var testData = new ApplePayTestData(); 32 | 33 | describe.skip('Create an Apple Pay Transaction', function () { 34 | var response; 35 | 36 | before(function(done){ 37 | var transactionRequest = new ApiContracts.TransactionRequestType(); 38 | transactionRequest.setAmount(utils.getRandomAmount()); 39 | transactionRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 40 | transactionRequest.setPayment(testData.paymentOne); 41 | 42 | var createRequest = new ApiContracts.CreateTransactionRequest(); 43 | createRequest.setTransactionRequest(transactionRequest); 44 | 45 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 46 | 47 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 48 | 49 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 50 | 51 | ctrl.execute(function(){ 52 | 53 | var apiResponse = ctrl.getResponse(); 54 | 55 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 56 | 57 | //console.log(JSON.stringify(response, null, 2)); 58 | done(); 59 | }); 60 | }); 61 | 62 | it('should return resultcode Ok when successful', function () { 63 | 64 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 65 | }); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /test/test-customerprofiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var utils = require('./utils.js'); 5 | var constants = require('./constants.js'); 6 | var ApiControllers = require('../lib/apicontrollers.js'); 7 | var ApiContracts = require('../lib/apicontracts.js'); 8 | 9 | var apiLoginKey = constants.apiLoginKey; 10 | var transactionKey = constants.transactionKey; 11 | 12 | class CustomerProfilesTestData { 13 | 14 | constructor(){ 15 | 16 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 17 | this.merchantAuthenticationType.setName(apiLoginKey); 18 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 19 | 20 | this.creditCard = new ApiContracts.CreditCardType(); 21 | this.creditCard.setCardNumber('4242424242424242'); 22 | this.creditCard.setExpirationDate('0845'); 23 | 24 | this.paymentType = new ApiContracts.PaymentType(); 25 | this.paymentType.setCreditCard(this.creditCard); 26 | 27 | this.customerPaymentProfileType = new ApiContracts.CustomerPaymentProfileType(); 28 | this.customerPaymentProfileType.setCustomerType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); 29 | this.customerPaymentProfileType.setPayment(this.paymentType); 30 | 31 | this.customerProfileType = new ApiContracts.CustomerProfileType(); 32 | this.customerProfileType.setMerchantCustomerId('M_' + utils.getRandomString('cust')); 33 | this.customerProfileType.setDescription('Profile description here'); 34 | this.customerProfileType.setEmail(utils.getRandomString('cust')+'@anet.net'); 35 | 36 | var paymentProfilesList = []; 37 | paymentProfilesList.push(this.customerPaymentProfileType); 38 | 39 | this.customerProfileType.setPaymentProfiles(paymentProfilesList); 40 | 41 | this.customerAddress = new ApiContracts.CustomerAddressType(); 42 | this.customerAddress.setFirstName('test'); 43 | this.customerAddress.setLastName('scenario'); 44 | this.customerAddress.setAddress('123 Main Street'); 45 | this.customerAddress.setCity('Bellevue'); 46 | this.customerAddress.setState('WA'); 47 | this.customerAddress.setZip('98004'); 48 | this.customerAddress.setCountry('USA'); 49 | this.customerAddress.setPhoneNumber('000-000-0000'); 50 | 51 | this.customerAddressForUpdate = new ApiContracts.CustomerAddressType(); 52 | this.customerAddressForUpdate.setFirstName('John'); 53 | this.customerAddressForUpdate.setLastName('Doe'); 54 | this.customerAddressForUpdate.setAddress('123 Main Street'); 55 | this.customerAddressForUpdate.setCity('Bellevue'); 56 | this.customerAddressForUpdate.setState('WA'); 57 | this.customerAddressForUpdate.setZip('98004'); 58 | this.customerAddressForUpdate.setCountry('USA'); 59 | this.customerAddressForUpdate.setPhoneNumber('111-111-1111'); 60 | 61 | //credit card details 62 | this.creditCardForUpdate = new ApiContracts.CreditCardType(); 63 | this.creditCardForUpdate.setCardNumber('4111111111111111'); 64 | this.creditCardForUpdate.setExpirationDate('2045-12'); 65 | 66 | this.customerAddressType = new ApiContracts.CustomerAddressType(); 67 | this.customerAddressType.setFirstName('Johny'); 68 | this.customerAddressType.setLastName('Bravo'); 69 | this.customerAddressType.setAddress('123 Main St.'); 70 | this.customerAddressType.setCity('Seattle'); 71 | this.customerAddressType.setState('WA'); 72 | this.customerAddressType.setZip('98004'); 73 | this.customerAddressType.setCountry('USA'); 74 | this.customerAddressType.setPhoneNumber('222-222-2222'); 75 | 76 | this.refId = '123456'; 77 | } 78 | } 79 | 80 | describe('Customer Profiles', function() { 81 | this.timeout(120000); 82 | var customerDataForUpdate; 83 | var customerShippingAddressForUpdate; 84 | var createCustomerProfileResponse; 85 | var createCustomerPaymentProfileResponse; 86 | var createCustomerShippingAddressResponse; 87 | var createTransactionResponse; 88 | var testData = new CustomerProfilesTestData(); 89 | 90 | describe('Create Customer Profile', function () { 91 | var response; 92 | 93 | before(function(done){ 94 | 95 | var createRequest = new ApiContracts.CreateCustomerProfileRequest(); 96 | createRequest.setProfile(testData.customerProfileType); 97 | createRequest.setValidationMode(ApiContracts.ValidationModeEnum.TESTMODE); 98 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 99 | 100 | // console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 101 | 102 | var ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON()); 103 | 104 | ctrl.execute(function(){ 105 | 106 | var apiResponse = ctrl.getResponse(); 107 | 108 | response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); 109 | 110 | createCustomerProfileResponse = response; 111 | 112 | // console.log(JSON.stringify(response, null, 2)); 113 | done(); 114 | }); 115 | }); 116 | 117 | it('should return resultcode Ok when successful', function () { 118 | 119 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 120 | }); 121 | 122 | it('should return not null customer profile id when successful', function () { 123 | 124 | assert.isNotNull(response.getCustomerProfileId()); 125 | assert.isDefined(response.getCustomerProfileId()); 126 | }); 127 | 128 | it('should return not null customer payment profile id when successful', function () { 129 | 130 | assert.isNotNull(response.getCustomerPaymentProfileIdList()); 131 | assert.isDefined(response.getCustomerPaymentProfileIdList()); 132 | assert.isAbove(response.getCustomerPaymentProfileIdList().getNumericString().length, 0); 133 | assert.isNotNull(response.getCustomerPaymentProfileIdList().getNumericString()[0]); 134 | assert.isDefined(response.getCustomerPaymentProfileIdList().getNumericString()[0]); 135 | }); 136 | }); 137 | 138 | describe('Get Customer Profile', function () { 139 | var response; 140 | 141 | before(function(done){ 142 | 143 | var getRequest = new ApiContracts.GetCustomerProfileRequest(); 144 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 145 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 146 | 147 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 148 | 149 | var ctrl = new ApiControllers.GetCustomerProfileController(getRequest.getJSON()); 150 | 151 | ctrl.execute(function(){ 152 | 153 | var apiResponse = ctrl.getResponse(); 154 | 155 | response = new ApiContracts.GetCustomerProfileResponse(apiResponse); 156 | 157 | //console.log(JSON.stringify(response, null, 2)); 158 | done(); 159 | }); 160 | }); 161 | 162 | it('should return resultcode Ok when successful', function () { 163 | 164 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 165 | }); 166 | 167 | it('should return customer profile id same as in create response when successful', function () { 168 | 169 | assert.equal(response.getProfile().getCustomerProfileId(), createCustomerProfileResponse.getCustomerProfileId()); 170 | }); 171 | 172 | it('should return customer email id same as in create request when successful', function () { 173 | 174 | assert.equal(response.getProfile().getEmail(), testData.customerProfileType.getEmail()); 175 | }); 176 | }); 177 | 178 | describe('Get Customer Profile IDs', function () { 179 | var response; 180 | 181 | before(function(done){ 182 | 183 | var getRequest = new ApiContracts.GetCustomerProfileIdsRequest(); 184 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 185 | 186 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 187 | 188 | var ctrl = new ApiControllers.GetCustomerProfileIdsController(getRequest.getJSON()); 189 | 190 | ctrl.execute(function(){ 191 | 192 | var apiResponse = ctrl.getResponse(); 193 | 194 | response = new ApiContracts.GetCustomerProfileIdsResponse(apiResponse); 195 | 196 | // console.log(JSON.stringify(response, null, 2)); 197 | done(); 198 | }); 199 | }); 200 | 201 | it('should return resultcode Ok when successful', function () { 202 | 203 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 204 | }); 205 | 206 | it('should return not null customer profile id when successful', function () { 207 | 208 | assert.isNotNull(response.getIds().getNumericString()); 209 | assert.isDefined(response.getIds().getNumericString()); 210 | }); 211 | }); 212 | 213 | describe('Update Customer Profile', function () { 214 | var response; 215 | 216 | before(function(done){ 217 | 218 | customerDataForUpdate = new ApiContracts.CustomerProfileExType(); 219 | customerDataForUpdate.setMerchantCustomerId('custId123'); 220 | customerDataForUpdate.setDescription('some description'); 221 | customerDataForUpdate.setEmail('newaddress@example.com'); 222 | customerDataForUpdate.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 223 | 224 | var updateRequest = new ApiContracts.UpdateCustomerProfileRequest(); 225 | updateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 226 | updateRequest.setProfile(customerDataForUpdate); 227 | 228 | //console.log(JSON.stringify(updateRequest.getJSON(), null, 2)); 229 | 230 | var ctrl = new ApiControllers.UpdateCustomerProfileController(updateRequest.getJSON()); 231 | 232 | ctrl.execute(function(){ 233 | 234 | var apiResponse = ctrl.getResponse(); 235 | 236 | response = new ApiContracts.UpdateCustomerProfileResponse(apiResponse); 237 | 238 | //console.log(JSON.stringify(response, null, 2)); 239 | done(); 240 | }); 241 | }); 242 | 243 | it('should return resultcode Ok when successful', function () { 244 | 245 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 246 | }); 247 | }); 248 | 249 | describe('Get Customer Profile After Update', function () { 250 | var response; 251 | 252 | before(function(done){ 253 | 254 | var getRequest = new ApiContracts.GetCustomerProfileRequest(); 255 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 256 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 257 | 258 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 259 | 260 | var ctrl = new ApiControllers.GetCustomerProfileController(getRequest.getJSON()); 261 | 262 | ctrl.execute(function(){ 263 | 264 | var apiResponse = ctrl.getResponse(); 265 | 266 | response = new ApiContracts.GetCustomerProfileResponse(apiResponse); 267 | 268 | //console.log(JSON.stringify(response, null, 2)); 269 | done(); 270 | }); 271 | 272 | }); 273 | 274 | it('should return resultcode Ok when successful', function () { 275 | 276 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 277 | }); 278 | 279 | it('should return updated merchant customer id when successful', function () { 280 | 281 | assert.equal(response.getProfile().getMerchantCustomerId(), customerDataForUpdate.getMerchantCustomerId()); 282 | }); 283 | 284 | it('should return updated description when successful', function () { 285 | 286 | assert.equal(response.getProfile().getDescription(), customerDataForUpdate.getDescription()); 287 | }); 288 | 289 | it('should return same email id when successful', function () { 290 | 291 | assert.equal(response.getProfile().getEmail(), customerDataForUpdate.getEmail()); 292 | }); 293 | }); 294 | 295 | describe('Create Customer Payment Profile', function () { 296 | var response; 297 | 298 | before(function(done){ 299 | 300 | var profile = new ApiContracts.CustomerPaymentProfileType(); 301 | profile.setBillTo(testData.customerAddress); 302 | profile.setPayment(testData.paymentType); 303 | 304 | var createRequest = new ApiContracts.CreateCustomerPaymentProfileRequest(); 305 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 306 | createRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 307 | createRequest.setPaymentProfile(profile); 308 | 309 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 310 | 311 | var ctrl = new ApiControllers.CreateCustomerPaymentProfileController(createRequest.getJSON()); 312 | 313 | ctrl.execute(function(){ 314 | 315 | var apiResponse = ctrl.getResponse(); 316 | 317 | response = new ApiContracts.CreateCustomerPaymentProfileResponse(apiResponse); 318 | 319 | createCustomerPaymentProfileResponse = response; 320 | 321 | //console.log(JSON.stringify(response, null, 2)); 322 | done(); 323 | }); 324 | }); 325 | 326 | it('should return resultcode Ok when successful', function () { 327 | 328 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 329 | }); 330 | 331 | it('should return same customer Profile Id as input when successful', function () { 332 | 333 | assert.equal(response.getCustomerProfileId(), createCustomerProfileResponse.getCustomerProfileId()); 334 | }); 335 | 336 | it('should return not null customer Payment Profile Id when successful', function () { 337 | 338 | assert.isNotNull(response.getCustomerPaymentProfileId()); 339 | assert.isDefined(response.getCustomerPaymentProfileId()); 340 | }); 341 | }); 342 | 343 | describe('Get Customer Payment Profile', function () { 344 | var response; 345 | 346 | before(function(done){ 347 | 348 | var getRequest = new ApiContracts.GetCustomerPaymentProfileRequest(); 349 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 350 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 351 | getRequest.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 352 | 353 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 354 | 355 | var ctrl = new ApiControllers.GetCustomerPaymentProfileController(getRequest.getJSON()); 356 | 357 | ctrl.execute(function(){ 358 | 359 | var apiResponse = ctrl.getResponse(); 360 | 361 | response = new ApiContracts.GetCustomerPaymentProfileResponse(apiResponse); 362 | 363 | //console.log(JSON.stringify(response, null, 2)); 364 | done(); 365 | }); 366 | 367 | }); 368 | 369 | it('should return resultcode Ok when successful', function () { 370 | 371 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 372 | }); 373 | 374 | it('should return same customer Profile Id as input when successful', function () { 375 | 376 | assert.equal(response.getPaymentProfile().getCustomerProfileId(), createCustomerProfileResponse.getCustomerProfileId()); 377 | }); 378 | 379 | it('should return same customer payment Profile Id as input when successful', function () { 380 | 381 | assert.equal(response.getPaymentProfile().getCustomerPaymentProfileId(), createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 382 | }); 383 | 384 | it('should return billTo address same as input when successful', function () { 385 | 386 | assert.equal(response.getPaymentProfile().getBillTo().getFirstName(), testData.customerAddress.getFirstName()); 387 | }); 388 | }); 389 | 390 | describe('Get Customer Payment Profile List', function () { 391 | var response; 392 | 393 | before(function(done){ 394 | 395 | var paging = new ApiContracts.Paging(); 396 | paging.setLimit(100); 397 | paging.setOffset(1); 398 | 399 | var sorting = new ApiContracts.CustomerPaymentProfileSorting(); 400 | sorting.setOrderBy(ApiContracts.CustomerPaymentProfileOrderFieldEnum.ID); 401 | sorting.setOrderDescending(false); 402 | 403 | var getRequest = new ApiContracts.GetCustomerPaymentProfileListRequest(); 404 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 405 | getRequest.setPaging(paging); 406 | getRequest.setSearchType(ApiContracts.CustomerPaymentProfileSearchTypeEnum.CARDSEXPIRINGINMONTH); 407 | getRequest.setSorting(sorting); 408 | getRequest.setMonth('2020-12'); 409 | 410 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 411 | 412 | var ctrl = new ApiControllers.GetCustomerPaymentProfileListController(getRequest.getJSON()); 413 | 414 | ctrl.execute(function(){ 415 | 416 | var apiResponse = ctrl.getResponse(); 417 | 418 | response = new ApiContracts.GetCustomerPaymentProfileListResponse(apiResponse); 419 | 420 | //console.log(JSON.stringify(response, null, 2)); 421 | done(); 422 | }); 423 | 424 | }); 425 | 426 | it('should return resultcode Ok when successful', function () { 427 | 428 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 429 | }); 430 | }); 431 | 432 | describe('Validate Customer Payment Profile', function () { 433 | var response; 434 | 435 | before(function(done){ 436 | 437 | var validateRequest = new ApiContracts.ValidateCustomerPaymentProfileRequest(); 438 | validateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 439 | validateRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 440 | validateRequest.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 441 | validateRequest.setValidationMode(ApiContracts.ValidationModeEnum.LIVEMODE); 442 | validateRequest.setCardCode('122'); 443 | 444 | //console.log(JSON.stringify(validateRequest.getJSON(), null, 2)); 445 | 446 | var ctrl = new ApiControllers.ValidateCustomerPaymentProfileController(validateRequest.getJSON()); 447 | 448 | ctrl.execute(function(){ 449 | 450 | var apiResponse = ctrl.getResponse(); 451 | 452 | response = new ApiContracts.ValidateCustomerPaymentProfileResponse(apiResponse); 453 | 454 | //console.log(JSON.stringify(response, null, 2)); 455 | done(); 456 | }); 457 | 458 | }); 459 | 460 | it('should return resultcode Ok when successful', function () { 461 | 462 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 463 | }); 464 | }); 465 | 466 | describe('Update Customer Payment Profile', function () { 467 | var response; 468 | 469 | before(function(done){ 470 | 471 | var paymentType = new ApiContracts.PaymentType(); 472 | paymentType.setCreditCard(testData.creditCardForUpdate); 473 | 474 | var customerForUpdate = new ApiContracts.CustomerPaymentProfileExType(); 475 | customerForUpdate.setPayment(paymentType); 476 | customerForUpdate.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 477 | customerForUpdate.setBillTo(testData.customerAddressForUpdate); 478 | 479 | var updateRequest = new ApiContracts.UpdateCustomerPaymentProfileRequest(); 480 | updateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 481 | updateRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 482 | updateRequest.setPaymentProfile(customerForUpdate); 483 | updateRequest.setValidationMode(ApiContracts.ValidationModeEnum.LIVEMODE); 484 | 485 | //console.log(JSON.stringify(updateRequest.getJSON(), null, 2)); 486 | 487 | var ctrl = new ApiControllers.UpdateCustomerPaymentProfileController(updateRequest.getJSON()); 488 | 489 | ctrl.execute(function(){ 490 | 491 | var apiResponse = ctrl.getResponse(); 492 | 493 | response = new ApiContracts.UpdateCustomerPaymentProfileResponse(apiResponse); 494 | 495 | //console.log(JSON.stringify(response, null, 2)); 496 | done(); 497 | }); 498 | 499 | }); 500 | 501 | it('should return resultcode Ok when successful', function () { 502 | 503 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 504 | }); 505 | }); 506 | 507 | describe('Get Customer Payment Profile After Update', function () { 508 | var response; 509 | 510 | before(function(done){ 511 | 512 | var getRequest = new ApiContracts.GetCustomerPaymentProfileRequest(); 513 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 514 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 515 | getRequest.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 516 | 517 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 518 | 519 | var ctrl = new ApiControllers.GetCustomerPaymentProfileController(getRequest.getJSON()); 520 | 521 | ctrl.execute(function(){ 522 | 523 | var apiResponse = ctrl.getResponse(); 524 | 525 | response = new ApiContracts.GetCustomerPaymentProfileResponse(apiResponse); 526 | 527 | //console.log(JSON.stringify(response, null, 2)); 528 | done(); 529 | }); 530 | 531 | }); 532 | 533 | it('should return resultcode Ok when successful', function () { 534 | 535 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 536 | }); 537 | 538 | it('should return same customer Profile Id as input when successful', function () { 539 | 540 | assert.equal(response.getPaymentProfile().getCustomerProfileId(), createCustomerProfileResponse.getCustomerProfileId()); 541 | }); 542 | 543 | it('should return same customer payment Profile Id as input when successful', function () { 544 | 545 | assert.equal(response.getPaymentProfile().getCustomerPaymentProfileId(), createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 546 | }); 547 | 548 | it('should return updated billTo address when successful', function () { 549 | 550 | assert.equal(response.getPaymentProfile().getBillTo().getFirstName(), testData.customerAddressForUpdate.getFirstName()); 551 | }); 552 | }); 553 | 554 | describe('Create Customer Shipping Address', function () { 555 | var response; 556 | 557 | before(function(done){ 558 | 559 | var createRequest = new ApiContracts.CreateCustomerShippingAddressRequest(); 560 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 561 | createRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 562 | createRequest.setAddress(testData.customerAddressType); 563 | 564 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 565 | 566 | var ctrl = new ApiControllers.CreateCustomerShippingAddressController(createRequest.getJSON()); 567 | 568 | ctrl.execute(function(){ 569 | 570 | var apiResponse = ctrl.getResponse(); 571 | 572 | response = new ApiContracts.CreateCustomerShippingAddressResponse(apiResponse); 573 | 574 | createCustomerShippingAddressResponse = response; 575 | 576 | //console.log(JSON.stringify(response, null, 2)); 577 | done(); 578 | }); 579 | }); 580 | 581 | it('should return resultcode Ok when successful', function () { 582 | 583 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 584 | }); 585 | 586 | it('should return same customer Profile Id as input when successful', function () { 587 | 588 | assert.equal(response.getCustomerProfileId(), createCustomerProfileResponse.getCustomerProfileId()); 589 | }); 590 | 591 | it('should return not null customer address Id when successful', function () { 592 | 593 | assert.isNotNull(response.getCustomerAddressId()); 594 | assert.isDefined(response.getCustomerAddressId()); 595 | }); 596 | }); 597 | 598 | describe('Get Customer Shipping Address', function () { 599 | var response; 600 | 601 | before(function(done){ 602 | 603 | var getRequest = new ApiContracts.GetCustomerShippingAddressRequest(); 604 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 605 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 606 | getRequest.setCustomerAddressId(createCustomerShippingAddressResponse.getCustomerAddressId()); 607 | 608 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 609 | 610 | var ctrl = new ApiControllers.GetCustomerShippingAddressController(getRequest.getJSON()); 611 | 612 | ctrl.execute(function(){ 613 | 614 | var apiResponse = ctrl.getResponse(); 615 | 616 | response = new ApiContracts.GetCustomerShippingAddressResponse(apiResponse); 617 | 618 | //console.log(JSON.stringify(response, null, 2)); 619 | done(); 620 | }); 621 | 622 | }); 623 | 624 | it('should return resultcode Ok when successful', function () { 625 | 626 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 627 | }); 628 | 629 | it('should return same customer address Id as input when successful', function () { 630 | 631 | assert.equal(response.getAddress().getCustomerAddressId(), createCustomerShippingAddressResponse.getCustomerAddressId()); 632 | }); 633 | 634 | it('should return address same as input when successful', function () { 635 | 636 | assert.equal(response.getAddress().getFirstName(), testData.customerAddressType.getFirstName()); 637 | }); 638 | }); 639 | 640 | describe('Update Customer Shipping Address', function () { 641 | var response; 642 | 643 | before(function(done){ 644 | 645 | var paymentType = new ApiContracts.PaymentType(); 646 | paymentType.setCreditCard(testData.creditCardForUpdate); 647 | 648 | customerShippingAddressForUpdate = new ApiContracts.CustomerAddressExType(); 649 | customerShippingAddressForUpdate.setFirstName('Will'); 650 | customerShippingAddressForUpdate.setLastName('Smith'); 651 | customerShippingAddressForUpdate.setAddress('345 Main St.'); 652 | customerShippingAddressForUpdate.setCity('Bellevue'); 653 | customerShippingAddressForUpdate.setState('WA'); 654 | customerShippingAddressForUpdate.setZip('98004'); 655 | customerShippingAddressForUpdate.setCountry('USA'); 656 | customerShippingAddressForUpdate.setPhoneNumber('333-333-3333'); 657 | customerShippingAddressForUpdate.setCustomerAddressId(createCustomerShippingAddressResponse.getCustomerAddressId()); 658 | 659 | var updateRequest = new ApiContracts.UpdateCustomerShippingAddressRequest(); 660 | updateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 661 | updateRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 662 | updateRequest.setAddress(customerShippingAddressForUpdate); 663 | 664 | //console.log(JSON.stringify(updateRequest.getJSON(), null, 2)); 665 | 666 | var ctrl = new ApiControllers.UpdateCustomerShippingAddressController(updateRequest.getJSON()); 667 | 668 | ctrl.execute(function(){ 669 | 670 | var apiResponse = ctrl.getResponse(); 671 | 672 | response = new ApiContracts.UpdateCustomerShippingAddressResponse(apiResponse); 673 | 674 | //console.log(JSON.stringify(response, null, 2)); 675 | done(); 676 | }); 677 | 678 | }); 679 | 680 | it('should return resultcode Ok when successful', function () { 681 | 682 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 683 | }); 684 | }); 685 | 686 | describe('Get Customer Shipping Address After Update', function () { 687 | var response; 688 | 689 | before(function(done){ 690 | 691 | var getRequest = new ApiContracts.GetCustomerShippingAddressRequest(); 692 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 693 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 694 | getRequest.setCustomerAddressId(createCustomerShippingAddressResponse.getCustomerAddressId()); 695 | 696 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 697 | 698 | var ctrl = new ApiControllers.GetCustomerShippingAddressController(getRequest.getJSON()); 699 | 700 | ctrl.execute(function(){ 701 | 702 | var apiResponse = ctrl.getResponse(); 703 | 704 | response = new ApiContracts.GetCustomerShippingAddressResponse(apiResponse); 705 | 706 | //console.log(JSON.stringify(response, null, 2)); 707 | done(); 708 | }); 709 | 710 | }); 711 | 712 | it('should return resultcode Ok when successful', function () { 713 | 714 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 715 | }); 716 | 717 | it('should return same customer address Id as input when successful', function () { 718 | 719 | assert.equal(response.getAddress().getCustomerAddressId(), createCustomerShippingAddressResponse.getCustomerAddressId()); 720 | }); 721 | 722 | it('should return updated shipping address when successful', function () { 723 | 724 | assert.equal(response.getAddress().getFirstName(), customerShippingAddressForUpdate.getFirstName()); 725 | }); 726 | }); 727 | 728 | describe('Get Hosted Profile Page', function () { 729 | var response; 730 | 731 | before(function(done){ 732 | 733 | var setting = new ApiContracts.SettingType(); 734 | setting.setSettingName('hostedProfileReturnUrl'); 735 | setting.setSettingValue('https://returnurl.com/return/'); 736 | 737 | var settingList = []; 738 | settingList.push(setting); 739 | 740 | var alist = new ApiContracts.ArrayOfSetting(); 741 | alist.setSetting(settingList); 742 | 743 | var getRequest = new ApiContracts.GetHostedProfilePageRequest(); 744 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 745 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 746 | getRequest.setHostedProfileSettings(alist); 747 | 748 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 749 | 750 | var ctrl = new ApiControllers.GetHostedProfilePageController(getRequest.getJSON()); 751 | 752 | ctrl.execute(function(){ 753 | 754 | var apiResponse = ctrl.getResponse(); 755 | 756 | response = new ApiContracts.GetHostedProfilePageResponse(apiResponse); 757 | 758 | //console.log(JSON.stringify(response, null, 2)); 759 | done(); 760 | }); 761 | 762 | }); 763 | 764 | it('should return resultcode Ok when successful', function () { 765 | 766 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 767 | }); 768 | 769 | it('should return not null token when successful', function () { 770 | 771 | assert.isNotNull(response.getToken()); 772 | assert.isDefined(response.getToken()); 773 | }); 774 | 775 | // it('should return address same as input when successful', function () { 776 | 777 | // assert.equal(response.getAddress().getFirstName(), testData.customerAddressType.getFirstName()); 778 | // }); 779 | }); 780 | 781 | describe('Delete Customer Shipping Address', function () { 782 | var response; 783 | 784 | before(function(done){ 785 | 786 | var deleteRequest = new ApiContracts.DeleteCustomerShippingAddressRequest(); 787 | deleteRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 788 | deleteRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 789 | deleteRequest.setCustomerAddressId(createCustomerShippingAddressResponse.getCustomerAddressId()); 790 | 791 | //console.log(JSON.stringify(deleteRequest.getJSON(), null, 2)); 792 | 793 | var ctrl = new ApiControllers.DeleteCustomerShippingAddressController(deleteRequest.getJSON()); 794 | 795 | ctrl.execute(function(){ 796 | 797 | var apiResponse = ctrl.getResponse(); 798 | 799 | response = new ApiContracts.DeleteCustomerShippingAddressResponse(apiResponse); 800 | 801 | //console.log(JSON.stringify(response, null, 2)); 802 | done(); 803 | }); 804 | 805 | }); 806 | 807 | it('should return resultcode Ok when successful', function () { 808 | 809 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 810 | }); 811 | }); 812 | 813 | describe('Get Customer Shipping Address After Delete', function () { 814 | var response; 815 | 816 | before(function(done){ 817 | 818 | var getRequest = new ApiContracts.GetCustomerShippingAddressRequest(); 819 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 820 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 821 | getRequest.setCustomerAddressId(createCustomerShippingAddressResponse.getCustomerAddressId()); 822 | 823 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 824 | 825 | var ctrl = new ApiControllers.GetCustomerShippingAddressController(getRequest.getJSON()); 826 | 827 | ctrl.execute(function(){ 828 | 829 | var apiResponse = ctrl.getResponse(); 830 | 831 | response = new ApiContracts.GetCustomerShippingAddressResponse(apiResponse); 832 | 833 | //console.log(JSON.stringify(response, null, 2)); 834 | done(); 835 | }); 836 | 837 | }); 838 | 839 | it('should return resultcode ERROR when successful', function () { 840 | 841 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.ERROR); 842 | }); 843 | 844 | it('should return error code E00040 when successful', function () { 845 | 846 | assert.equal(response.getMessages().getMessage()[0].getCode(), 'E00040'); 847 | }); 848 | }); 849 | 850 | describe('Delete Customer Payment Profile', function () { 851 | var response; 852 | 853 | before(function(done){ 854 | 855 | var deleteRequest = new ApiContracts.DeleteCustomerPaymentProfileRequest(); 856 | deleteRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 857 | deleteRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 858 | deleteRequest.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 859 | 860 | //console.log(JSON.stringify(deleteRequest.getJSON(), null, 2)); 861 | 862 | var ctrl = new ApiControllers.DeleteCustomerPaymentProfileController(deleteRequest.getJSON()); 863 | 864 | ctrl.execute(function(){ 865 | 866 | var apiResponse = ctrl.getResponse(); 867 | 868 | response = new ApiContracts.DeleteCustomerPaymentProfileResponse(apiResponse); 869 | 870 | //console.log(JSON.stringify(response, null, 2)); 871 | done(); 872 | }); 873 | 874 | }); 875 | 876 | it('should return resultcode Ok when successful', function () { 877 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 878 | }); 879 | }); 880 | 881 | describe('Get Customer Payment Profile After Delete', function () { 882 | var response; 883 | 884 | before(function(done){ 885 | 886 | var getRequest = new ApiContracts.GetCustomerPaymentProfileRequest(); 887 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 888 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 889 | getRequest.setCustomerPaymentProfileId(createCustomerPaymentProfileResponse.getCustomerPaymentProfileId()); 890 | 891 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 892 | 893 | var ctrl = new ApiControllers.GetCustomerPaymentProfileController(getRequest.getJSON()); 894 | 895 | ctrl.execute(function(){ 896 | 897 | var apiResponse = ctrl.getResponse(); 898 | 899 | response = new ApiContracts.GetCustomerPaymentProfileResponse(apiResponse); 900 | 901 | //console.log(JSON.stringify(response, null, 2)); 902 | done(); 903 | }); 904 | 905 | }); 906 | 907 | it('should return resultcode ERROR when successful', function () { 908 | 909 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.ERROR); 910 | }); 911 | 912 | it('should return error code E00040 when successful', function () { 913 | 914 | assert.equal(response.getMessages().getMessage()[0].getCode(), 'E00040'); 915 | }); 916 | }); 917 | 918 | describe('Delete Customer Profile', function () { 919 | var response; 920 | 921 | before(function(done){ 922 | 923 | var deleteRequest = new ApiContracts.DeleteCustomerProfileRequest(); 924 | deleteRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 925 | deleteRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 926 | 927 | //console.log(JSON.stringify(deleteRequest.getJSON(), null, 2)); 928 | 929 | var ctrl = new ApiControllers.DeleteCustomerProfileController(deleteRequest.getJSON()); 930 | 931 | ctrl.execute(function(){ 932 | 933 | var apiResponse = ctrl.getResponse(); 934 | 935 | response = new ApiContracts.DeleteCustomerProfileResponse(apiResponse); 936 | 937 | //console.log(JSON.stringify(response, null, 2)); 938 | done(); 939 | }); 940 | 941 | }); 942 | 943 | it('should return resultcode Ok when successful', function () { 944 | 945 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 946 | }); 947 | }); 948 | 949 | describe('Get Customer Profile After Delete', function () { 950 | var response; 951 | 952 | before(function(done){ 953 | 954 | var getRequest = new ApiContracts.GetCustomerProfileRequest(); 955 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 956 | getRequest.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 957 | 958 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 959 | 960 | var ctrl = new ApiControllers.GetCustomerProfileController(getRequest.getJSON()); 961 | 962 | ctrl.execute(function(){ 963 | 964 | var apiResponse = ctrl.getResponse(); 965 | 966 | response = new ApiContracts.GetCustomerProfileResponse(apiResponse); 967 | 968 | //console.log(JSON.stringify(response, null, 2)); 969 | done(); 970 | }); 971 | 972 | }); 973 | 974 | it('should return resultcode ERROR when successful', function () { 975 | 976 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.ERROR); 977 | }); 978 | 979 | it('should return error code E00040 when successful', function () { 980 | 981 | assert.equal(response.getMessages().getMessage()[0].getCode(), 'E00040'); 982 | }); 983 | }); 984 | 985 | describe('Create Transaction for Create Customer Profile from a Transaction', function () { 986 | var response; 987 | 988 | before(function(done){ 989 | 990 | var customer = new ApiContracts.CustomerDataType(); 991 | customer.setEmail(utils.getRandomString('test') + '@anet.net'); 992 | 993 | var requestInternal = new ApiContracts.TransactionRequestType(); 994 | requestInternal.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHONLYTRANSACTION); 995 | requestInternal.setPayment(testData.paymentType); 996 | requestInternal.setAmount(utils.getRandomAmount()); 997 | requestInternal.setCustomer(customer); 998 | 999 | var createRequest = new ApiContracts.CreateTransactionRequest(); 1000 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 1001 | createRequest.setTransactionRequest(requestInternal); 1002 | 1003 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 1004 | 1005 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 1006 | 1007 | ctrl.execute(function(){ 1008 | 1009 | var apiResponse = ctrl.getResponse(); 1010 | 1011 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 1012 | 1013 | createTransactionResponse = response; 1014 | 1015 | //console.log(JSON.stringify(response, null, 2)); 1016 | done(); 1017 | }); 1018 | }); 1019 | 1020 | it('should return resultcode Ok when successful', function () { 1021 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 1022 | }); 1023 | }); 1024 | 1025 | describe('Create Customer Profile from a Transaction', function () { 1026 | var response; 1027 | 1028 | before(function(done){ 1029 | 1030 | var createRequest = new ApiContracts.CreateCustomerProfileFromTransactionRequest(); 1031 | createRequest.setTransId(createTransactionResponse.getTransactionResponse().getTransId()); 1032 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 1033 | 1034 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 1035 | 1036 | var ctrl = new ApiControllers.CreateCustomerProfileFromTransactionController(createRequest.getJSON()); 1037 | 1038 | ctrl.execute(function(){ 1039 | 1040 | var apiResponse = ctrl.getResponse(); 1041 | 1042 | response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); 1043 | 1044 | //console.log(JSON.stringify(response, null, 2)); 1045 | done(); 1046 | }); 1047 | }); 1048 | 1049 | it('should return resultcode Ok when successful', function () { 1050 | 1051 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 1052 | }); 1053 | }); 1054 | }); 1055 | -------------------------------------------------------------------------------- /test/test-paymenttransactions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var utils = require('./utils.js'); 5 | var constants = require('./constants.js'); 6 | var ApiControllers = require('../lib/apicontrollers.js'); 7 | var ApiContracts = require('../lib/apicontracts.js'); 8 | 9 | var apiLoginKey = constants.apiLoginKey; 10 | var transactionKey = constants.transactionKey; 11 | 12 | class PaymentTransactionsTestData { 13 | 14 | constructor(){ 15 | 16 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 17 | this.merchantAuthenticationType.setName(apiLoginKey); 18 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 19 | 20 | this.creditCard = new ApiContracts.CreditCardType(); 21 | this.creditCard.setCardNumber('4242424242424242'); 22 | this.creditCard.setExpirationDate('0845'); 23 | 24 | this.paymentType = new ApiContracts.PaymentType(); 25 | this.paymentType.setCreditCard(this.creditCard); 26 | 27 | this.authCode = 'ROHNFQ'; 28 | this.splitTenderId = '115901'; 29 | this.refId = '123456'; 30 | } 31 | } 32 | 33 | describe('Payment Transactions', function() { 34 | this.timeout(120000); 35 | var authOnlyTransactionId; 36 | var authOnlyTransactionIdForVoid; 37 | var authAndCaptureTransactionId; 38 | var debitTransactionId; 39 | var debitTransactionAmount; 40 | var createCustomerProfileResponse; 41 | var testData = new PaymentTransactionsTestData(); 42 | 43 | describe('Charge a credit card', function () { 44 | var response; 45 | 46 | before(function(done){ 47 | 48 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 49 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 50 | transactionRequestType.setPayment(testData.paymentType); 51 | transactionRequestType.setAmount(utils.getRandomAmount()); 52 | 53 | var createRequest = new ApiContracts.CreateTransactionRequest(); 54 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 55 | createRequest.setTransactionRequest(transactionRequestType); 56 | 57 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 58 | 59 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 60 | 61 | ctrl.execute(function(){ 62 | 63 | var apiResponse = ctrl.getResponse(); 64 | 65 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 66 | 67 | authAndCaptureTransactionId = response.getTransactionResponse().getTransId(); 68 | 69 | //console.log(JSON.stringify(response, null, 2)); 70 | done(); 71 | }); 72 | }); 73 | 74 | it('should return resultcode Ok when successful', function () { 75 | 76 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 77 | }); 78 | 79 | it('should return not null transaction id when successful', function () { 80 | 81 | assert.isNotNull(response.getTransactionResponse()); 82 | assert.isDefined(response.getTransactionResponse()); 83 | assert.isNotNull(response.getTransactionResponse().getTransId()); 84 | assert.isDefined(response.getTransactionResponse().getTransId()); 85 | }); 86 | }); 87 | 88 | describe('Authorize a credit card', function () { 89 | var response; 90 | 91 | before(function(done){ 92 | 93 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 94 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHONLYTRANSACTION); 95 | transactionRequestType.setPayment(testData.paymentType); 96 | transactionRequestType.setAmount(utils.getRandomAmount()); 97 | 98 | var createRequest = new ApiContracts.CreateTransactionRequest(); 99 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 100 | createRequest.setTransactionRequest(transactionRequestType); 101 | 102 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 103 | 104 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 105 | 106 | ctrl.execute(function(){ 107 | 108 | var apiResponse = ctrl.getResponse(); 109 | 110 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 111 | 112 | authOnlyTransactionId = response.getTransactionResponse().getTransId(); 113 | 114 | //console.log(JSON.stringify(response, null, 2)); 115 | done(); 116 | }); 117 | }); 118 | 119 | it('should return resultcode Ok when successful', function () { 120 | 121 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 122 | }); 123 | 124 | it('should return not null transaction id when successful', function () { 125 | 126 | assert.isNotNull(response.getTransactionResponse()); 127 | assert.isDefined(response.getTransactionResponse()); 128 | assert.isNotNull(response.getTransactionResponse().getTransId()); 129 | assert.isDefined(response.getTransactionResponse().getTransId()); 130 | }); 131 | }); 132 | 133 | describe('Capture a previously authorized amount', function () { 134 | var response; 135 | 136 | before(function(done){ 137 | 138 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 139 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.PRIORAUTHCAPTURETRANSACTION); 140 | transactionRequestType.setRefTransId(authOnlyTransactionId); 141 | 142 | var createRequest = new ApiContracts.CreateTransactionRequest(); 143 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 144 | createRequest.setTransactionRequest(transactionRequestType); 145 | 146 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 147 | 148 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 149 | 150 | ctrl.execute(function(){ 151 | 152 | var apiResponse = ctrl.getResponse(); 153 | 154 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 155 | 156 | //console.log(JSON.stringify(response, null, 2)); 157 | done(); 158 | }); 159 | }); 160 | 161 | it('should return resultcode Ok when successful', function () { 162 | 163 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 164 | }); 165 | 166 | it('should return not null transaction id when successful', function () { 167 | 168 | assert.isNotNull(response.getTransactionResponse()); 169 | assert.isDefined(response.getTransactionResponse()); 170 | assert.isNotNull(response.getTransactionResponse().getTransId()); 171 | assert.isDefined(response.getTransactionResponse().getTransId()); 172 | }); 173 | }); 174 | 175 | describe('Capture funds authorized through another channel', function () { 176 | var response; 177 | 178 | before(function(done){ 179 | 180 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 181 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.CAPTUREONLYTRANSACTION); 182 | transactionRequestType.setPayment(testData.paymentType); 183 | transactionRequestType.setAmount(utils.getRandomAmount()); 184 | transactionRequestType.setAuthCode(testData.authCode); 185 | 186 | var createRequest = new ApiContracts.CreateTransactionRequest(); 187 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 188 | createRequest.setTransactionRequest(transactionRequestType); 189 | 190 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 191 | 192 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 193 | 194 | ctrl.execute(function(){ 195 | 196 | var apiResponse = ctrl.getResponse(); 197 | 198 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 199 | 200 | //console.log(JSON.stringify(response, null, 2)); 201 | done(); 202 | }); 203 | }); 204 | 205 | it('should return resultcode Ok when successful', function () { 206 | 207 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 208 | }); 209 | 210 | it('should return not null transaction id when successful', function () { 211 | 212 | assert.isNotNull(response.getTransactionResponse()); 213 | assert.isDefined(response.getTransactionResponse()); 214 | assert.isNotNull(response.getTransactionResponse().getTransId()); 215 | assert.isDefined(response.getTransactionResponse().getTransId()); 216 | }); 217 | 218 | it('should return authCode same as input when successful', function () { 219 | assert.equal(response.getTransactionResponse().getAuthCode(), testData.authCode); 220 | }); 221 | }); 222 | 223 | describe('Refund Transaction', function () { 224 | var response; 225 | 226 | before(function(done){ 227 | 228 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 229 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.REFUNDTRANSACTION); 230 | transactionRequestType.setPayment(testData.paymentType); 231 | transactionRequestType.setAmount(utils.getRandomAmount()); 232 | transactionRequestType.setRefTransId(authOnlyTransactionId); 233 | 234 | var createRequest = new ApiContracts.CreateTransactionRequest(); 235 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 236 | createRequest.setTransactionRequest(transactionRequestType); 237 | 238 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 239 | 240 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 241 | 242 | ctrl.execute(function(){ 243 | 244 | var apiResponse = ctrl.getResponse(); 245 | 246 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 247 | 248 | //console.log(JSON.stringify(response, null, 2)); 249 | done(); 250 | }); 251 | }); 252 | 253 | it('should return resultcode Error', function () { 254 | 255 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.ERROR); 256 | }); 257 | 258 | it('should return error code 54', function () { 259 | 260 | assert.isAbove(response.getTransactionResponse().getErrors().getError().length, 0); 261 | assert.equal(response.getTransactionResponse().getErrors().getError()[0].getErrorCode(), '54'); 262 | }); 263 | }); 264 | 265 | describe('Authorize a credit card for void', function () { 266 | var response; 267 | 268 | before(function(done){ 269 | 270 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 271 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHONLYTRANSACTION); 272 | transactionRequestType.setPayment(testData.paymentType); 273 | transactionRequestType.setAmount(utils.getRandomAmount()); 274 | 275 | var createRequest = new ApiContracts.CreateTransactionRequest(); 276 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 277 | createRequest.setTransactionRequest(transactionRequestType); 278 | 279 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 280 | 281 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 282 | 283 | ctrl.execute(function(){ 284 | 285 | var apiResponse = ctrl.getResponse(); 286 | 287 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 288 | 289 | authOnlyTransactionIdForVoid = response.getTransactionResponse().getTransId(); 290 | 291 | //console.log(JSON.stringify(response, null, 2)); 292 | done(); 293 | }); 294 | }); 295 | 296 | it('should return resultcode Ok when successful', function () { 297 | 298 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 299 | }); 300 | 301 | it('should return not null transaction id when successful', function () { 302 | 303 | assert.isNotNull(response.getTransactionResponse()); 304 | assert.isDefined(response.getTransactionResponse()); 305 | assert.isNotNull(response.getTransactionResponse().getTransId()); 306 | assert.isDefined(response.getTransactionResponse().getTransId()); 307 | }); 308 | }); 309 | 310 | describe('Void Transaction', function () { 311 | var response; 312 | 313 | before(function(done){ 314 | 315 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 316 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.VOIDTRANSACTION); 317 | transactionRequestType.setRefTransId(authOnlyTransactionIdForVoid); 318 | 319 | var createRequest = new ApiContracts.CreateTransactionRequest(); 320 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 321 | createRequest.setTransactionRequest(transactionRequestType); 322 | 323 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 324 | 325 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 326 | 327 | ctrl.execute(function(){ 328 | 329 | var apiResponse = ctrl.getResponse(); 330 | 331 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 332 | 333 | //console.log(JSON.stringify(response, null, 2)); 334 | done(); 335 | }); 336 | }); 337 | 338 | it('should return resultcode Ok when successful', function () { 339 | 340 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 341 | }); 342 | }); 343 | 344 | describe('Update Split Tender Group', function () { 345 | var response; 346 | 347 | before(function(done){ 348 | 349 | var updateRequest = new ApiContracts.UpdateSplitTenderGroupRequest(); 350 | updateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 351 | updateRequest.setSplitTenderId(testData.splitTenderId); 352 | updateRequest.setSplitTenderStatus(ApiContracts.SplitTenderStatusEnum.VOIDED); 353 | 354 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 355 | 356 | var ctrl = new ApiControllers.UpdateSplitTenderGroupController(updateRequest.getJSON()); 357 | 358 | ctrl.execute(function(){ 359 | 360 | var apiResponse = ctrl.getResponse(); 361 | 362 | response = new ApiContracts.UpdateSplitTenderGroupResponse(apiResponse); 363 | 364 | //console.log(JSON.stringify(response, null, 2)); 365 | done(); 366 | }); 367 | }); 368 | 369 | it('should return resultcode Ok when successful', function () { 370 | 371 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 372 | }); 373 | }); 374 | 375 | describe('Debit a Bank Account', function () { 376 | var response; 377 | 378 | before(function(done){ 379 | 380 | var paymentType = new ApiContracts.PaymentType(); 381 | 382 | var bankAccountType = new ApiContracts.BankAccountType(); 383 | bankAccountType.setAccountType(ApiContracts.BankAccountTypeEnum.CHECKING); 384 | bankAccountType.setRoutingNumber('125008547'); 385 | bankAccountType.setAccountNumber('8256571452'); 386 | bankAccountType.setNameOnAccount('John Doe'); 387 | bankAccountType.setEcheckType('WEB'); 388 | bankAccountType.setBankName('Wells Fargo Bank NA'); 389 | paymentType.setBankAccount(bankAccountType); 390 | 391 | debitTransactionAmount = utils.getRandomAmount(); 392 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 393 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 394 | transactionRequestType.setPayment(paymentType); 395 | transactionRequestType.setAmount(debitTransactionAmount); 396 | 397 | var createRequest = new ApiContracts.CreateTransactionRequest(); 398 | createRequest.setRefId(testData.refId); 399 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 400 | createRequest.setTransactionRequest(transactionRequestType); 401 | 402 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 403 | 404 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 405 | 406 | ctrl.execute(function(){ 407 | 408 | var apiResponse = ctrl.getResponse(); 409 | 410 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 411 | 412 | debitTransactionId = response.getTransactionResponse().getTransId(); 413 | 414 | //console.log(JSON.stringify(response, null, 2)); 415 | done(); 416 | }); 417 | }); 418 | 419 | it('should return resultcode Ok when successful', function () { 420 | 421 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 422 | }); 423 | 424 | it('should return not null transaction id when successful', function () { 425 | 426 | assert.isNotNull(response.getTransactionResponse()); 427 | assert.isDefined(response.getTransactionResponse()); 428 | assert.isNotNull(response.getTransactionResponse().getTransId()); 429 | assert.isDefined(response.getTransactionResponse().getTransId()); 430 | }); 431 | 432 | it('should return same refId as input when successful', function () { 433 | 434 | assert.equal(response.getRefId(), testData.refId); 435 | }); 436 | }); 437 | 438 | describe('Credit a Bank Account', function () { 439 | var response; 440 | 441 | before(function(done){ 442 | 443 | var paymentType = new ApiContracts.PaymentType(); 444 | 445 | var bankAccountType = new ApiContracts.BankAccountType(); 446 | bankAccountType.setAccountType(ApiContracts.BankAccountTypeEnum.CHECKING); 447 | bankAccountType.setRoutingNumber('125008547'); 448 | bankAccountType.setAccountNumber('8256571452'); 449 | bankAccountType.setNameOnAccount('John Doe'); 450 | paymentType.setBankAccount(bankAccountType); 451 | 452 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 453 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.REFUNDTRANSACTION); 454 | transactionRequestType.setPayment(paymentType); 455 | // Transaction is can be used only in case of trnsaction is settled. 456 | // transactionRequestType.setRefTransId(debitTransactionId); 457 | transactionRequestType.setAmount(debitTransactionAmount); 458 | 459 | var createRequest = new ApiContracts.CreateTransactionRequest(); 460 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 461 | createRequest.setTransactionRequest(transactionRequestType); 462 | 463 | // console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 464 | 465 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 466 | 467 | ctrl.execute(function(){ 468 | 469 | var apiResponse = ctrl.getResponse(); 470 | 471 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 472 | 473 | // console.log(JSON.stringify(response, null, 2)); 474 | done(); 475 | }); 476 | }); 477 | 478 | it('should return resultcode Ok when successful', function () { 479 | 480 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 481 | }); 482 | 483 | it('should return not null transaction id when successful', function () { 484 | 485 | assert.isNotNull(response.getTransactionResponse()); 486 | assert.isDefined(response.getTransactionResponse()); 487 | assert.isNotNull(response.getTransactionResponse().getTransId()); 488 | assert.isDefined(response.getTransactionResponse().getTransId()); 489 | }); 490 | }); 491 | 492 | describe('Create Customer Profile for - Charge a Customer Profile', function () { 493 | var response; 494 | 495 | before(function(done){ 496 | 497 | var customerPaymentProfileType = new ApiContracts.CustomerPaymentProfileType(); 498 | customerPaymentProfileType.setCustomerType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); 499 | customerPaymentProfileType.setPayment(testData.paymentType); 500 | 501 | var customerProfileType = new ApiContracts.CustomerProfileType(); 502 | customerProfileType.setMerchantCustomerId('M_' + utils.getRandomString('cust')); 503 | customerProfileType.setDescription('Profile description here'); 504 | customerProfileType.setEmail(utils.getRandomString('cust')+'@anet.net'); 505 | 506 | var paymentProfilesList = []; 507 | paymentProfilesList.push(customerPaymentProfileType); 508 | customerProfileType.setPaymentProfiles(paymentProfilesList); 509 | 510 | var createRequest = new ApiContracts.CreateCustomerProfileRequest(); 511 | createRequest.setProfile(customerProfileType); 512 | createRequest.setValidationMode(ApiContracts.ValidationModeEnum.TESTMODE); 513 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 514 | 515 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 516 | 517 | var ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON()); 518 | 519 | ctrl.execute(function(){ 520 | 521 | var apiResponse = ctrl.getResponse(); 522 | 523 | response = new ApiContracts.CreateCustomerProfileResponse(apiResponse); 524 | 525 | createCustomerProfileResponse = response; 526 | 527 | //console.log(JSON.stringify(response, null, 2)); 528 | done(); 529 | }); 530 | }); 531 | 532 | it('should return resultcode Ok when successful', function () { 533 | 534 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 535 | }); 536 | 537 | it('should return not null customer profile id when successful', function () { 538 | 539 | assert.isNotNull(response.getCustomerProfileId()); 540 | assert.isDefined(response.getCustomerProfileId()); 541 | }); 542 | 543 | it('should return not null customer payment profile id when successful', function () { 544 | 545 | assert.isNotNull(response.getCustomerPaymentProfileIdList()); 546 | assert.isDefined(response.getCustomerPaymentProfileIdList()); 547 | assert.isAbove(response.getCustomerPaymentProfileIdList().getNumericString().length, 0); 548 | assert.isNotNull(response.getCustomerPaymentProfileIdList().getNumericString()[0]); 549 | assert.isDefined(response.getCustomerPaymentProfileIdList().getNumericString()[0]); 550 | }); 551 | }); 552 | 553 | describe('Charge Customer Profile', function () { 554 | var response; 555 | 556 | before(function(done){ 557 | 558 | var profileToCharge = new ApiContracts.CustomerProfilePaymentType(); 559 | profileToCharge.setCustomerProfileId(createCustomerProfileResponse.getCustomerProfileId()); 560 | 561 | var paymentProfile = new ApiContracts.PaymentProfile(); 562 | paymentProfile.setPaymentProfileId(createCustomerProfileResponse.getCustomerPaymentProfileIdList().getNumericString()[0]); 563 | profileToCharge.setPaymentProfile(paymentProfile); 564 | 565 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 566 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 567 | transactionRequestType.setProfile(profileToCharge); 568 | transactionRequestType.setAmount(utils.getRandomAmount()); 569 | 570 | var createRequest = new ApiContracts.CreateTransactionRequest(); 571 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 572 | createRequest.setTransactionRequest(transactionRequestType); 573 | 574 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 575 | 576 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 577 | 578 | ctrl.execute(function(){ 579 | 580 | var apiResponse = ctrl.getResponse(); 581 | 582 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 583 | 584 | authAndCaptureTransactionId = response.getTransactionResponse().getTransId(); 585 | 586 | //console.log(JSON.stringify(response, null, 2)); 587 | done(); 588 | }); 589 | }); 590 | 591 | it('should return resultcode Ok when successful', function () { 592 | 593 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 594 | }); 595 | 596 | it('should return not null transaction id when successful', function () { 597 | 598 | assert.isNotNull(response.getTransactionResponse()); 599 | assert.isDefined(response.getTransactionResponse()); 600 | assert.isNotNull(response.getTransactionResponse().getTransId()); 601 | assert.isDefined(response.getTransactionResponse().getTransId()); 602 | }); 603 | }); 604 | 605 | describe('Charge a Tokenized Credit Card', function () { 606 | var response; 607 | 608 | before(function(done){ 609 | 610 | var creditCard = new ApiContracts.CreditCardType(); 611 | creditCard.setCardNumber('4242424242424242'); 612 | creditCard.setExpirationDate('0845'); 613 | creditCard.setCryptogram('EjRWeJASNFZ4kBI0VniQEjRWeJA='); 614 | 615 | var paymentType = new ApiContracts.PaymentType(); 616 | paymentType.setCreditCard(creditCard); 617 | 618 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 619 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 620 | transactionRequestType.setPayment(paymentType); 621 | transactionRequestType.setAmount(utils.getRandomAmount()); 622 | 623 | var createRequest = new ApiContracts.CreateTransactionRequest(); 624 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 625 | createRequest.setTransactionRequest(transactionRequestType); 626 | 627 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 628 | 629 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 630 | 631 | ctrl.execute(function(){ 632 | 633 | var apiResponse = ctrl.getResponse(); 634 | 635 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 636 | 637 | authAndCaptureTransactionId = response.getTransactionResponse().getTransId(); 638 | 639 | //console.log(JSON.stringify(response, null, 2)); 640 | done(); 641 | }); 642 | }); 643 | 644 | it('should return resultcode Ok when successful', function () { 645 | 646 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 647 | }); 648 | 649 | it('should return not null transaction id when successful', function () { 650 | 651 | assert.isNotNull(response.getTransactionResponse()); 652 | assert.isDefined(response.getTransactionResponse()); 653 | assert.isNotNull(response.getTransactionResponse().getTransId()); 654 | assert.isDefined(response.getTransactionResponse().getTransId()); 655 | }); 656 | }); 657 | 658 | }); 659 | -------------------------------------------------------------------------------- /test/test-paypalexpresscheckout.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var utils = require('./utils.js'); 5 | var constants = require('./constants.js'); 6 | var ApiControllers = require('../lib/apicontrollers.js'); 7 | var ApiContracts = require('../lib/apicontracts.js'); 8 | 9 | var apiLoginKey = constants.apiLoginKey; 10 | var transactionKey = constants.transactionKey; 11 | 12 | class PaypalTestData { 13 | 14 | constructor(){ 15 | 16 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 17 | this.merchantAuthenticationType.setName(apiLoginKey); 18 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 19 | 20 | this.payPal = new ApiContracts.PayPalType(); 21 | this.payPal.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 22 | this.payPal.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 23 | 24 | //standard api call to retrieve response 25 | this.paymentType = new ApiContracts.PaymentType(); 26 | this.paymentType.setPayPal(this.payPal); 27 | } 28 | } 29 | 30 | describe('Paypal Express Checkout', function() { 31 | this.timeout(120000); 32 | var transactionId; 33 | var authAndCaptureTransactionId; 34 | var testData = new PaypalTestData(); 35 | 36 | describe('Authorization Only', function () { 37 | var response; 38 | 39 | before(function(done){ 40 | 41 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 42 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHONLYTRANSACTION); 43 | transactionRequestType.setPayment(testData.paymentType); 44 | transactionRequestType.setAmount(utils.getRandomAmount()); 45 | 46 | var createRequest = new ApiContracts.CreateTransactionRequest(); 47 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 48 | createRequest.setTransactionRequest(transactionRequestType); 49 | 50 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 51 | 52 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 53 | 54 | ctrl.execute(function(){ 55 | 56 | var apiResponse = ctrl.getResponse(); 57 | 58 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 59 | 60 | transactionId = response.getTransactionResponse().getTransId(); 61 | 62 | // console.log(JSON.stringify(response, null, 2)); 63 | done(); 64 | }); 65 | }); 66 | 67 | it('should return resultcode Ok when successful', function () { 68 | 69 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 70 | }); 71 | 72 | it('should return not null transaction id when successful', function () { 73 | 74 | assert.isNotNull(response.getTransactionResponse()); 75 | assert.isDefined(response.getTransactionResponse()); 76 | assert.isNotNull(response.getTransactionResponse().getTransId()); 77 | assert.isDefined(response.getTransactionResponse().getTransId()); 78 | }); 79 | 80 | it('should return not null secure acceptance url when successful', function () { 81 | 82 | assert.isNotNull(response.getTransactionResponse().getSecureAcceptance().getSecureAcceptanceUrl()); 83 | assert.isDefined(response.getTransactionResponse().getSecureAcceptance().getSecureAcceptanceUrl()); 84 | }); 85 | }); 86 | 87 | describe('Authorization And Capture', function () { 88 | var response; 89 | 90 | before(function(done){ 91 | 92 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 93 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 94 | transactionRequestType.setPayment(testData.paymentType); 95 | transactionRequestType.setAmount(utils.getRandomAmount()); 96 | 97 | var createRequest = new ApiContracts.CreateTransactionRequest(); 98 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 99 | createRequest.setTransactionRequest(transactionRequestType); 100 | 101 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 102 | 103 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 104 | 105 | ctrl.execute(function(){ 106 | 107 | var apiResponse = ctrl.getResponse(); 108 | 109 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 110 | 111 | authAndCaptureTransactionId = response.getTransactionResponse().getTransId(); 112 | 113 | //console.log(JSON.stringify(response, null, 2)); 114 | done(); 115 | }); 116 | }); 117 | 118 | it('should return resultcode Ok when successful', function () { 119 | 120 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 121 | }); 122 | 123 | it('should return not null transaction id when successful', function () { 124 | 125 | assert.isNotNull(response.getTransactionResponse()); 126 | assert.isDefined(response.getTransactionResponse()); 127 | assert.isNotNull(response.getTransactionResponse().getTransId()); 128 | assert.isDefined(response.getTransactionResponse().getTransId()); 129 | }); 130 | 131 | it('should return not null secure acceptance url when successful', function () { 132 | 133 | assert.isNotNull(response.getTransactionResponse().getSecureAcceptance().getSecureAcceptanceUrl()); 134 | assert.isDefined(response.getTransactionResponse().getSecureAcceptance().getSecureAcceptanceUrl()); 135 | }); 136 | }); 137 | 138 | describe('Get Details', function () { 139 | var response; 140 | 141 | before(function(done){ 142 | 143 | var transactionRequestType = new ApiContracts.TransactionRequestType(); 144 | transactionRequestType.setTransactionType(ApiContracts.TransactionTypeEnum.GETDETAILSTRANSACTION); 145 | transactionRequestType.setPayment(testData.paymentType); 146 | transactionRequestType.setRefTransId(transactionId); 147 | 148 | var createRequest = new ApiContracts.CreateTransactionRequest(); 149 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 150 | createRequest.setTransactionRequest(transactionRequestType); 151 | 152 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 153 | 154 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 155 | 156 | ctrl.execute(function(){ 157 | 158 | var apiResponse = ctrl.getResponse(); 159 | 160 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 161 | 162 | // console.log(JSON.stringify(response, null, 2)); 163 | done(); 164 | }); 165 | }); 166 | 167 | it('should return resultcode Ok when successful', function () { 168 | 169 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 170 | }); 171 | 172 | it('should return not null transaction id when successful', function () { 173 | 174 | assert.isNotNull(response.getTransactionResponse()); 175 | assert.isDefined(response.getTransactionResponse()); 176 | assert.isNotNull(response.getTransactionResponse().getTransId()); 177 | assert.isDefined(response.getTransactionResponse().getTransId()); 178 | }); 179 | 180 | it('should return account type as paypal when successful', function () { 181 | 182 | assert.equal(response.getTransactionResponse().getAccountType(), 'PayPal'); 183 | }); 184 | }); 185 | 186 | describe.skip('Authorization Only Continued', function () { 187 | var response; 188 | 189 | before(function(done){ 190 | 191 | var payPalType = new ApiContracts.PayPalType(); 192 | payPalType.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 193 | payPalType.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 194 | payPalType.setPayerID('B2LA5T27DMX7G'); 195 | 196 | var paymentType = new ApiContracts.PaymentType(); 197 | paymentType.setPayPal(payPalType); 198 | 199 | var txnRequest = new ApiContracts.TransactionRequestType(); 200 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHONLYCONTINUETRANSACTION); 201 | txnRequest.setPayment(paymentType); 202 | txnRequest.setAmount(utils.getRandomAmount()); 203 | txnRequest.setRefTransId('2251413967'); 204 | 205 | var createRequest = new ApiContracts.CreateTransactionRequest(); 206 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 207 | createRequest.setTransactionRequest(txnRequest); 208 | 209 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 210 | 211 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 212 | 213 | ctrl.execute(function(){ 214 | 215 | var apiResponse = ctrl.getResponse(); 216 | 217 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 218 | 219 | //console.log(JSON.stringify(response, null, 2)); 220 | done(); 221 | }); 222 | }); 223 | 224 | it('should return resultcode Ok when successful', function () { 225 | 226 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 227 | }); 228 | }); 229 | 230 | describe.skip('Prior Authorization Capture', function () { 231 | var response; 232 | 233 | before(function(done){ 234 | 235 | var payPalType = new ApiContracts.PayPalType(); 236 | payPalType.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 237 | payPalType.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 238 | 239 | var paymentType = new ApiContracts.PaymentType(); 240 | paymentType.setPayPal(payPalType); 241 | 242 | var txnRequest = new ApiContracts.TransactionRequestType(); 243 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.PRIORAUTHCAPTURETRANSACTION); 244 | txnRequest.setPayment(paymentType); 245 | txnRequest.setAmount(utils.getRandomAmount()); 246 | txnRequest.setRefTransId(transactionId); 247 | 248 | var createRequest = new ApiContracts.CreateTransactionRequest(); 249 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 250 | createRequest.setTransactionRequest(txnRequest); 251 | 252 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 253 | 254 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 255 | 256 | ctrl.execute(function(){ 257 | 258 | var apiResponse = ctrl.getResponse(); 259 | 260 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 261 | 262 | //console.log(JSON.stringify(response, null, 2)); 263 | done(); 264 | }); 265 | }); 266 | 267 | it('should return resultcode Ok when successful', function () { 268 | 269 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 270 | }); 271 | }); 272 | 273 | describe('Authorization And Capture Continue', function () { 274 | var response; 275 | 276 | before(function(done){ 277 | 278 | var payPalType = new ApiContracts.PayPalType(); 279 | payPalType.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 280 | payPalType.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 281 | payPalType.setPayerID('B2LA5T27DMX7G'); 282 | 283 | var paymentType = new ApiContracts.PaymentType(); 284 | paymentType.setPayPal(payPalType); 285 | 286 | var txnRequest = new ApiContracts.TransactionRequestType(); 287 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURECONTINUETRANSACTION); 288 | txnRequest.setPayment(paymentType); 289 | txnRequest.setAmount(utils.getRandomAmount()); 290 | txnRequest.setRefTransId(authAndCaptureTransactionId); 291 | 292 | var createRequest = new ApiContracts.CreateTransactionRequest(); 293 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 294 | createRequest.setTransactionRequest(txnRequest); 295 | 296 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 297 | 298 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 299 | 300 | ctrl.execute(function(){ 301 | 302 | var apiResponse = ctrl.getResponse(); 303 | 304 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 305 | 306 | //console.log(JSON.stringify(response, null, 2)); 307 | done(); 308 | }); 309 | }); 310 | 311 | it('should return resultcode Ok when successful', function () { 312 | 313 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 314 | }); 315 | 316 | it('should return not null transaction id when successful', function () { 317 | 318 | assert.isNotNull(response.getTransactionResponse()); 319 | assert.isDefined(response.getTransactionResponse()); 320 | assert.isNotNull(response.getTransactionResponse().getTransId()); 321 | assert.isDefined(response.getTransactionResponse().getTransId()); 322 | }); 323 | }); 324 | 325 | describe('Void', function () { 326 | var response; 327 | 328 | before(function(done){ 329 | 330 | var payPalType = new ApiContracts.PayPalType(); 331 | payPalType.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 332 | payPalType.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 333 | 334 | var paymentType = new ApiContracts.PaymentType(); 335 | paymentType.setPayPal(payPalType); 336 | 337 | var txnRequest = new ApiContracts.TransactionRequestType(); 338 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.VOIDTRANSACTION); 339 | txnRequest.setPayment(paymentType); 340 | txnRequest.setRefTransId(authAndCaptureTransactionId); 341 | 342 | var createRequest = new ApiContracts.CreateTransactionRequest(); 343 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 344 | createRequest.setTransactionRequest(txnRequest); 345 | 346 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 347 | 348 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 349 | 350 | ctrl.execute(function(){ 351 | 352 | var apiResponse = ctrl.getResponse(); 353 | 354 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 355 | 356 | //console.log(JSON.stringify(response, null, 2)); 357 | done(); 358 | }); 359 | }); 360 | 361 | it.skip('should return resultcode Ok when successful', function () { 362 | 363 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 364 | }); 365 | 366 | it('should return not null transaction id when successful', function () { 367 | 368 | assert.isNotNull(response.getTransactionResponse()); 369 | assert.isDefined(response.getTransactionResponse()); 370 | assert.isNotNull(response.getTransactionResponse().getTransId()); 371 | assert.isDefined(response.getTransactionResponse().getTransId()); 372 | }); 373 | }); 374 | 375 | describe('Credit', function () { 376 | var response; 377 | 378 | before(function(done){ 379 | 380 | var payPalType = new ApiContracts.PayPalType(); 381 | payPalType.setCancelUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 382 | payPalType.setSuccessUrl('http://www.merchanteCommerceSite.com/Success/TC25262'); 383 | 384 | var paymentType = new ApiContracts.PaymentType(); 385 | paymentType.setPayPal(payPalType); 386 | 387 | var txnRequest = new ApiContracts.TransactionRequestType(); 388 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.REFUNDTRANSACTION); 389 | txnRequest.setPayment(paymentType); 390 | txnRequest.setAmount(utils.getRandomAmount()); 391 | txnRequest.setRefTransId(authAndCaptureTransactionId); 392 | 393 | var createRequest = new ApiContracts.CreateTransactionRequest(); 394 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 395 | createRequest.setTransactionRequest(txnRequest); 396 | 397 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 398 | 399 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 400 | 401 | ctrl.execute(function(){ 402 | 403 | var apiResponse = ctrl.getResponse(); 404 | 405 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 406 | 407 | //console.log(JSON.stringify(response, null, 2)); 408 | done(); 409 | }); 410 | }); 411 | 412 | it.skip('should return resultcode Ok when successful', function () { 413 | 414 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 415 | }); 416 | 417 | it('should return not null transaction id when successful', function () { 418 | 419 | assert.isNotNull(response.getTransactionResponse()); 420 | assert.isDefined(response.getTransactionResponse()); 421 | assert.isNotNull(response.getTransactionResponse().getTransId()); 422 | assert.isDefined(response.getTransactionResponse().getTransId()); 423 | }); 424 | }); 425 | }); 426 | -------------------------------------------------------------------------------- /test/test-recurringbilling.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var utils = require('./utils.js'); 5 | var constants = require('./constants.js'); 6 | var ApiControllers = require('../lib/apicontrollers.js'); 7 | var ApiContracts = require('../lib/apicontracts.js'); 8 | 9 | var apiLoginKey = constants.apiLoginKey; 10 | var transactionKey = constants.transactionKey; 11 | 12 | class ARBSubscriptionTestData { 13 | 14 | constructor(){ 15 | 16 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 17 | this.merchantAuthenticationType.setName(apiLoginKey); 18 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 19 | 20 | this.customerProfileType = new ApiContracts.CustomerProfileType(); 21 | this.customerProfileType.setDescription(utils.getRandomString('CustomerDescription')); 22 | this.customerProfileType.setMerchantCustomerId(utils.getRandomString('Customer')); 23 | this.customerProfileType.setEmail(utils.getRandomString('email')+'@anet.net'); 24 | 25 | this.creditCardOne = new ApiContracts.CreditCardType(); 26 | this.creditCardOne.setExpirationDate('2038-12'); 27 | this.creditCardOne.setCardNumber('4111111111111111'); 28 | 29 | this.bankAccountOne = new ApiContracts.BankAccountType(); 30 | this.bankAccountOne.setAccountType(ApiContracts.BankAccountTypeEnum.SAVINGS); 31 | this.bankAccountOne.setRoutingNumber('125000000'); 32 | this.bankAccountOne.setAccountNumber(utils.getRandomString('A/C#')); 33 | this.bankAccountOne.setNameOnAccount(utils.getRandomString('A/CName')); 34 | this.bankAccountOne.setEcheckType(ApiContracts.EcheckTypeEnum.WEB); 35 | this.bankAccountOne.setBankName(utils.getRandomString('Bank')); 36 | this.bankAccountOne.setCheckNumber(utils.getRandomInt()); 37 | 38 | this.trackDataOne = new ApiContracts.CreditCardTrackType(); 39 | this.trackDataOne.setTrack1(utils.getRandomString('Track1')); 40 | this.trackDataOne.setTrack2(utils.getRandomString('Track2')); 41 | 42 | this.encryptedTrackDataOne = new ApiContracts.EncryptedTrackDataType(); 43 | var keyBlock = new ApiContracts.KeyBlock(); 44 | //keyBlock.setValue(value); 45 | this.encryptedTrackDataOne.setFormOfPayment(keyBlock); 46 | 47 | this.payPalOne = new ApiContracts.PayPalType(); 48 | this.payPalOne.setSuccessUrl(utils.getRandomString('https://success.anet.net')); 49 | this.payPalOne.setCancelUrl(utils.getRandomString('https://cancel.anet.net')); 50 | this.payPalOne.setPaypalLc(utils.getRandomString('Lc')); 51 | this.payPalOne.setPaypalHdrImg(utils.getRandomString('Hdr')); 52 | this.payPalOne.setPaypalPayflowcolor(utils.getRandomString('flowClr')); 53 | this.payPalOne.setPayerID(utils.getRandomString('PayerId')); 54 | 55 | this.paymentOne = new ApiContracts.PaymentType(); 56 | this.paymentOne.setCreditCard(this.creditCardOne); 57 | 58 | this.customerAddressOne = new ApiContracts.CustomerAddressType(); 59 | this.customerAddressOne.setFirstName(utils.getRandomString('FName')); 60 | this.customerAddressOne.setLastName(utils.getRandomString('LName')); 61 | this.customerAddressOne.setCompany(utils.getRandomString('Company')); 62 | this.customerAddressOne.setAddress(utils.getRandomString('StreetAdd')); 63 | this.customerAddressOne.setCity('Bellevue'); 64 | this.customerAddressOne.setState('WA'); 65 | this.customerAddressOne.setZip('98000'); 66 | this.customerAddressOne.setCountry('USA'); 67 | this.customerAddressOne.setPhoneNumber('1232122122'); 68 | this.customerAddressOne.setFaxNumber('1232122122'); 69 | this.customerPaymentProfileOne = new ApiContracts.CustomerPaymentProfileType(); 70 | this.customerPaymentProfileOne.setCustomerType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); 71 | this.customerPaymentProfileOne.setPayment(this.paymentOne); 72 | 73 | this.customerOne = new ApiContracts.CustomerType(); 74 | this.customerOne.setType(ApiContracts.CustomerTypeEnum.INDIVIDUAL); 75 | this.customerOne.setId(utils.getRandomString('Id')); 76 | this.customerOne.setEmail(utils.getRandomInt()+'@test.this.anet.net'); 77 | this.customerOne.setPhoneNumber('1232122122'); 78 | this.customerOne.setFaxNumber('1232122122'); 79 | this.customerOne.setDriversLicense(this.driversLicenseOne); 80 | this.customerOne.setTaxId('911011011');//'123-45-6789');//TODO 81 | 82 | this.customerTwo = new ApiContracts.CustomerType(); 83 | 84 | var interval = new ApiContracts.PaymentScheduleType.Interval(); 85 | interval.setLength(1); 86 | interval.setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS); 87 | 88 | this.orderType = new ApiContracts.OrderType(); 89 | this.orderType.setInvoiceNumber(utils.getRandomString('Inv:')); 90 | this.orderType.setDescription(utils.getRandomString('Description')); 91 | 92 | this.nameAndAddressTypeOne = new ApiContracts.NameAndAddressType(); 93 | this.nameAndAddressTypeOne.setFirstName(utils.getRandomString('FName')); 94 | this.nameAndAddressTypeOne.setLastName(utils.getRandomString('LName')); 95 | this.nameAndAddressTypeOne.setCompany(utils.getRandomString('Company')); 96 | this.nameAndAddressTypeOne.setAddress(utils.getRandomString('Address')); 97 | this.nameAndAddressTypeOne.setCity(utils.getRandomString('City')); 98 | this.nameAndAddressTypeOne.setState(utils.getRandomString('State')); 99 | this.nameAndAddressTypeOne.setZip('98004'); 100 | this.nameAndAddressTypeOne.setCountry('USA'); 101 | 102 | this.nameAndAddressTypeTwo = new ApiContracts.NameAndAddressType(); 103 | this.nameAndAddressTypeTwo.setFirstName(utils.getRandomString('FName')); 104 | this.nameAndAddressTypeTwo.setLastName(utils.getRandomString('LName')); 105 | this.nameAndAddressTypeTwo.setCompany(utils.getRandomString('Company')); 106 | this.nameAndAddressTypeTwo.setAddress(utils.getRandomString('Address')); 107 | this.nameAndAddressTypeTwo.setCity(utils.getRandomString('City')); 108 | this.nameAndAddressTypeTwo.setState(utils.getRandomString('State')); 109 | this.nameAndAddressTypeTwo.setZip('98004'); 110 | this.nameAndAddressTypeTwo.setCountry('USA'); 111 | 112 | this.paymentScheduleTypeOne = new ApiContracts.PaymentScheduleType(); 113 | this.paymentScheduleTypeOne.setInterval(interval); 114 | this.paymentScheduleTypeOne.setStartDate(utils.getDate()); 115 | this.paymentScheduleTypeOne.setTotalOccurrences(5); 116 | this.paymentScheduleTypeOne.setTrialOccurrences(0); 117 | 118 | this.arbSubscriptionOne = new ApiContracts.ARBSubscriptionType(); 119 | this.arbSubscriptionOne.setName(utils.getRandomString('Name')); 120 | this.arbSubscriptionOne.setPaymentSchedule(this.paymentScheduleTypeOne); 121 | this.arbSubscriptionOne.setAmount(utils.getRandomAmount()); 122 | this.arbSubscriptionOne.setTrialAmount(utils.getRandomAmount()); 123 | this.arbSubscriptionOne.setPayment(this.paymentOne); 124 | this.arbSubscriptionOne.setOrder(this.orderType); 125 | this.arbSubscriptionOne.setCustomer(this.customerOne); 126 | this.arbSubscriptionOne.setBillTo(this.nameAndAddressTypeOne); 127 | this.arbSubscriptionOne.setShipTo(this.nameAndAddressTypeOne); 128 | 129 | this.customerDataOne = new ApiContracts.CustomerDataType(); 130 | this.customerDataOne.setDriversLicense(this.customerOne.getDriversLicense()); 131 | this.customerDataOne.setEmail(this.customerOne.getEmail()); 132 | this.customerDataOne.setId(this.customerOne.getId()); 133 | this.customerDataOne.setTaxId(this.customerOne.getTaxId()); 134 | this.customerDataOne.setType(this.customerOne.getType()); 135 | 136 | this.refId = utils.getRandomInt(); 137 | 138 | this.sorting = new ApiContracts.ARBGetSubscriptionListSorting(); 139 | this.sorting.setOrderDescending(true); 140 | this.sorting.setOrderBy(ApiContracts.ARBGetSubscriptionListOrderFieldEnum.CREATETIMESTAMPUTC); 141 | 142 | this.paging = new ApiContracts.Paging(); 143 | this.paging.setOffset(1); 144 | this.paging.setLimit(100); 145 | 146 | this.orderTypeTwo = new ApiContracts.OrderType(); 147 | this.orderTypeTwo.setInvoiceNumber(utils.getRandomString('Inv:')); 148 | this.orderTypeTwo.setDescription(utils.getRandomString('Description')); 149 | } 150 | } 151 | 152 | describe('Recurring Billing', function() { 153 | this.timeout(120000); 154 | var subscriptionId; 155 | var testData = new ARBSubscriptionTestData(); 156 | 157 | 158 | describe('create subscription', function () { 159 | var response; 160 | 161 | before(function(done){ 162 | 163 | var createRequest = new ApiContracts.ARBCreateSubscriptionRequest(); 164 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 165 | createRequest.setSubscription(testData.arbSubscriptionOne); 166 | 167 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 168 | 169 | var ctrl = new ApiControllers.ARBCreateSubscriptionController(createRequest.getJSON()); 170 | 171 | ctrl.execute(function(){ 172 | 173 | var apiResponse = ctrl.getResponse(); 174 | 175 | response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse); 176 | 177 | //console.log(JSON.stringify(response, null, 2)); 178 | 179 | subscriptionId = response.getSubscriptionId(); 180 | done(); 181 | }); 182 | }); 183 | 184 | it('should return resultcode Ok when successful', function () { 185 | 186 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 187 | }); 188 | 189 | it('should return not null subscriptionid when successful', function () { 190 | 191 | assert.isNotNull(response.getSubscriptionId()); 192 | assert.isDefined(response.getSubscriptionId()); 193 | }); 194 | }); 195 | 196 | describe('get subscription', function () { 197 | var response; 198 | 199 | before(function(done){ 200 | 201 | var getRequest = new ApiContracts.ARBGetSubscriptionRequest(); 202 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 203 | getRequest.setSubscriptionId(subscriptionId); 204 | 205 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 206 | 207 | var ctrl = new ApiControllers.ARBGetSubscriptionController(getRequest.getJSON()); 208 | 209 | ctrl.execute(function(){ 210 | 211 | var apiResponse = ctrl.getResponse(); 212 | 213 | response = new ApiContracts.ARBGetSubscriptionResponse(apiResponse); 214 | 215 | //console.log(JSON.stringify(response, null, 2)); 216 | done(); 217 | }); 218 | }); 219 | 220 | it('should return resultcode Ok when successful', function () { 221 | 222 | assert.equal(response.getMessages().getResultCode(),ApiContracts.MessageTypeEnum.OK); 223 | }); 224 | 225 | it('should return subscription name same as test data when successful', function () { 226 | 227 | assert.equal(response.getSubscription().getName(),testData.arbSubscriptionOne.getName()); 228 | }); 229 | 230 | it('should return subscription amount same as test data when successful', function () { 231 | 232 | assert.equal(response.getSubscription().getAmount(),testData.arbSubscriptionOne.getAmount()); 233 | }); 234 | 235 | it('should return order description same as test data when successful', function () { 236 | 237 | assert.equal(response.getSubscription().getOrder().getDescription(),testData.arbSubscriptionOne.getOrder().getDescription()); 238 | }); 239 | }); 240 | 241 | describe('get subscription status', function () { 242 | var response; 243 | 244 | before(function(done){ 245 | 246 | var getRequest = new ApiContracts.ARBGetSubscriptionStatusRequest(); 247 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 248 | getRequest.setSubscriptionId(subscriptionId); 249 | 250 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 251 | 252 | var ctrl = new ApiControllers.ARBGetSubscriptionStatusController(getRequest.getJSON()); 253 | 254 | ctrl.execute(function(){ 255 | 256 | var apiResponse = ctrl.getResponse(); 257 | 258 | response = new ApiContracts.ARBGetSubscriptionStatusResponse(apiResponse); 259 | 260 | //console.log(JSON.stringify(response, null, 2)); 261 | done(); 262 | }); 263 | }); 264 | 265 | it('should return resultcode Ok when successful', function () { 266 | 267 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 268 | }); 269 | 270 | it('should return subscription status as active when successful', function () { 271 | 272 | assert.equal(response.getStatus(),ApiContracts.ARBSubscriptionStatusEnum.ACTIVE); 273 | }); 274 | }); 275 | 276 | describe('get subscription list', function () { 277 | var response; 278 | 279 | before(function(done){ 280 | 281 | setTimeout(function() { 282 | var listRequest = new ApiContracts.ARBGetSubscriptionListRequest(); 283 | 284 | listRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 285 | 286 | listRequest.setRefId(testData.refId); 287 | listRequest.setSearchType(ApiContracts.ARBGetSubscriptionListSearchTypeEnum.SUBSCRIPTIONACTIVE); 288 | listRequest.setSorting(testData.sorting); 289 | listRequest.setPaging(testData.paging); 290 | 291 | //console.log(JSON.stringify(listRequest.getJSON())); 292 | 293 | var ctrl = new ApiControllers.ARBGetSubscriptionListController(listRequest.getJSON()); 294 | 295 | ctrl.execute(function(){ 296 | 297 | var apiResponse = ctrl.getResponse(); 298 | 299 | response = new ApiContracts.ARBGetSubscriptionListResponse(apiResponse); 300 | 301 | //console.log(JSON.stringify(response, null, 2)); 302 | done(); 303 | }); 304 | }, 20000); 305 | }); 306 | 307 | it('should return resultcode Ok when successful', function () { 308 | 309 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 310 | }); 311 | 312 | it('should return totalResultsInNumSet greater than 0 when successful', function () { 313 | 314 | assert.isAbove(response.getTotalNumInResultSet(),0); 315 | }); 316 | 317 | it('should return subsciption details when successful', function () { 318 | 319 | assert.isNotNull(response.getSubscriptionDetails()); 320 | assert.isDefined(response.getSubscriptionDetails()); 321 | }); 322 | 323 | it('should return newly created subscription when successful', function () { 324 | 325 | var found = false; 326 | var subscriptionsArray = response.getSubscriptionDetails().getSubscriptionDetail(); 327 | subscriptionsArray.forEach(function(subscription) { 328 | assert.isAbove(subscription.getId(), 0); 329 | if(subscription.getId() == subscriptionId) 330 | found = true; 331 | }); 332 | 333 | assert.isTrue(found); 334 | }); 335 | }); 336 | 337 | describe('update subscription', function () { 338 | var response; 339 | 340 | before(function(done){ 341 | 342 | var arbSubscriptionType = new ApiContracts.ARBSubscriptionType(); 343 | arbSubscriptionType.setOrder(testData.orderTypeTwo); 344 | 345 | var updateRequest = new ApiContracts.ARBUpdateSubscriptionRequest(); 346 | updateRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 347 | updateRequest.setSubscriptionId(subscriptionId); 348 | updateRequest.setSubscription(arbSubscriptionType); 349 | 350 | //console.log(JSON.stringify(updateRequest.getJSON(), null, 2)); 351 | 352 | var ctrl = new ApiControllers.ARBUpdateSubscriptionController(updateRequest.getJSON()); 353 | 354 | ctrl.execute(function(){ 355 | 356 | var apiResponse = ctrl.getResponse(); 357 | 358 | response = new ApiContracts.ARBUpdateSubscriptionResponse(apiResponse); 359 | 360 | //console.log(JSON.stringify(response, null, 2)); 361 | done(); 362 | }); 363 | }); 364 | 365 | it('should return resultcode Ok when successful', function () { 366 | 367 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 368 | }); 369 | }); 370 | 371 | describe('get updated subscription', function () { 372 | var response; 373 | 374 | before(function(done){ 375 | 376 | var getRequest = new ApiContracts.ARBGetSubscriptionRequest(); 377 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 378 | getRequest.setSubscriptionId(subscriptionId); 379 | 380 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 381 | 382 | var ctrl = new ApiControllers.ARBGetSubscriptionController(getRequest.getJSON()); 383 | 384 | ctrl.execute(function(){ 385 | 386 | var apiResponse = ctrl.getResponse(); 387 | 388 | response = new ApiContracts.ARBGetSubscriptionResponse(apiResponse); 389 | 390 | //console.log(JSON.stringify(response, null, 2)); 391 | done(); 392 | }); 393 | }); 394 | 395 | it('should return resultcode Ok when successful', function () { 396 | 397 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 398 | }); 399 | 400 | it('should return subscription name same as test data when successful', function () { 401 | 402 | assert.equal(response.getSubscription().getName(),testData.arbSubscriptionOne.getName()); 403 | }); 404 | 405 | it('should return subscription amount same as test data when successful', function () { 406 | 407 | assert.equal(response.getSubscription().getAmount(),testData.arbSubscriptionOne.getAmount()); 408 | }); 409 | 410 | it('should return updated order description when successful', function () { 411 | 412 | assert.equal(response.getSubscription().getOrder().getDescription(),testData.orderTypeTwo.getDescription()); 413 | }); 414 | 415 | it('should return updated order invoice number when successful', function () { 416 | 417 | assert.equal(response.getSubscription().getOrder().getInvoiceNumber(),testData.orderTypeTwo.getInvoiceNumber()); 418 | }); 419 | }); 420 | 421 | describe('cancel subscription', function () { 422 | var response; 423 | 424 | before(function(done){ 425 | 426 | var cancelRequest = new ApiContracts.ARBCancelSubscriptionRequest(); 427 | cancelRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 428 | cancelRequest.setSubscriptionId(subscriptionId); 429 | 430 | //console.log(JSON.stringify(cancelRequest.getJSON(), null, 2)); 431 | 432 | var ctrl = new ApiControllers.ARBCancelSubscriptionController(cancelRequest.getJSON()); 433 | 434 | ctrl.execute(function(){ 435 | 436 | var apiResponse = ctrl.getResponse(); 437 | 438 | response = new ApiContracts.ARBCancelSubscriptionResponse(apiResponse); 439 | 440 | //console.log(JSON.stringify(response, null, 2)); 441 | done(); 442 | }); 443 | }); 444 | 445 | it('should return resultcode Ok when successful', function () { 446 | 447 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 448 | }); 449 | 450 | }); 451 | }); 452 | -------------------------------------------------------------------------------- /test/test-transactionreporting.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var constants = require('./constants.js'); 5 | var ApiControllers = require('../lib/apicontrollers.js'); 6 | var ApiContracts = require('../lib/apicontracts.js'); 7 | 8 | var apiLoginKey = constants.apiLoginKey; 9 | var transactionKey = constants.transactionKey; 10 | 11 | class TransactionReportingTestData { 12 | constructor(){ 13 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 14 | this.merchantAuthenticationType.setName(apiLoginKey); 15 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 16 | } 17 | } 18 | 19 | describe('Transaction Reporting', function() { 20 | this.timeout(120000); 21 | var batchId; 22 | var transactionId; 23 | var testData = new TransactionReportingTestData(); 24 | 25 | describe('get Settled Batch List', function () { 26 | var response; 27 | 28 | before(function(done){ 29 | 30 | var createRequest = new ApiContracts.GetSettledBatchListRequest(); 31 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 32 | createRequest.setIncludeStatistics(true); 33 | // createRequest.setFirstSettlementDate('2015-05-01T16:00:00Z'); 34 | // createRequest.setLastSettlementDate('2015-05-31T16:00:00Z'); 35 | 36 | createRequest.setFirstSettlementDate(new Date(new Date().setDate(new Date().getDate()-30))); 37 | createRequest.setLastSettlementDate(new Date()); 38 | 39 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 40 | 41 | var ctrl = new ApiControllers.GetSettledBatchListController(createRequest.getJSON()); 42 | 43 | ctrl.execute(function(){ 44 | 45 | var apiResponse = ctrl.getResponse(); 46 | 47 | response = new ApiContracts.GetSettledBatchListResponse(apiResponse); 48 | 49 | //console.log(JSON.stringify(response, null, 2)); 50 | done(); 51 | }); 52 | }); 53 | 54 | it('should return resultcode Ok when successful', function () { 55 | 56 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 57 | }); 58 | 59 | it('should return not null batch list when successful', function () { 60 | 61 | assert.isNotNull(response.getBatchList()); 62 | assert.isDefined(response.getBatchList()); 63 | }); 64 | 65 | it('should return not null batch ids when successful', function () { 66 | 67 | var batchArray = response.getBatchList().getBatch(); 68 | batchArray.forEach(function(batch) { 69 | batchId = batch.getBatchId(); 70 | assert.isNotNull(batch.getBatchId()); 71 | assert.isDefined(batch.getBatchId()); 72 | }); 73 | }); 74 | 75 | it('should return not null batch statistics when successful', function () { 76 | 77 | var batchArray = response.getBatchList().getBatch(); 78 | batchArray.forEach(function(batch) { 79 | assert.isNotNull(batch.getStatistics()); 80 | assert.isDefined(batch.getStatistics()); 81 | }); 82 | }); 83 | }); 84 | 85 | describe('get Transaction List', function () { 86 | var response; 87 | 88 | before(function(done){ 89 | 90 | var getRequest = new ApiContracts.GetTransactionListRequest(); 91 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 92 | getRequest.setBatchId(batchId); 93 | 94 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 95 | 96 | var ctrl = new ApiControllers.GetTransactionListController(getRequest.getJSON()); 97 | 98 | ctrl.execute(function(){ 99 | 100 | var apiResponse = ctrl.getResponse(); 101 | 102 | response = new ApiContracts.GetTransactionListResponse(apiResponse); 103 | 104 | //console.log(JSON.stringify(response, null, 2)); 105 | done(); 106 | }); 107 | }); 108 | 109 | it('should return resultcode Ok when successful', function () { 110 | 111 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 112 | }); 113 | 114 | it('should return not null transaction list when successful', function () { 115 | 116 | assert.isNotNull(response.getTransactions()); 117 | assert.isDefined(response.getTransactions()); 118 | }); 119 | 120 | it('should return not null transaction ids when successful', function () { 121 | 122 | var transactionArray = response.getTransactions().getTransaction(); 123 | transactionArray.forEach(function(transaction) { 124 | transactionId = transaction.getTransId(); 125 | assert.isNotNull(transaction.getTransId()); 126 | assert.isDefined(transaction.getTransId()); 127 | }); 128 | }); 129 | }); 130 | 131 | describe('get Transaction List For Customer', function () { 132 | var response; 133 | 134 | before(function(done){ 135 | 136 | var getRequest = new ApiContracts.GetTransactionListForCustomerRequest(); 137 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 138 | getRequest.setCustomerProfileId('39931060'); 139 | 140 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 141 | 142 | var ctrl = new ApiControllers.GetTransactionListForCustomerController(getRequest.getJSON()); 143 | 144 | ctrl.execute(function(){ 145 | 146 | var apiResponse = ctrl.getResponse(); 147 | 148 | response = new ApiContracts.GetTransactionListResponse(apiResponse); 149 | 150 | //console.log(JSON.stringify(response, null, 2)); 151 | done(); 152 | }); 153 | }); 154 | 155 | it('should return resultcode Ok when successful', function () { 156 | 157 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 158 | }); 159 | 160 | it('should return not null transaction list when successful', function () { 161 | 162 | assert.isNotNull(response.getTransactions()); 163 | assert.isDefined(response.getTransactions()); 164 | }); 165 | 166 | it('should return not null transaction ids when successful', function () { 167 | 168 | var transactionArray = response.getTransactions().getTransaction(); 169 | transactionArray.forEach(function(transaction) { 170 | transactionId = transaction.getTransId(); 171 | assert.isNotNull(transaction.getTransId()); 172 | assert.isDefined(transaction.getTransId()); 173 | }); 174 | }); 175 | }); 176 | 177 | describe('get Transaction Details', function () { 178 | var response; 179 | 180 | before(function(done){ 181 | 182 | var getRequest = new ApiContracts.GetTransactionDetailsRequest(); 183 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 184 | getRequest.setTransId(transactionId); 185 | 186 | //console.log(JSON.stringify(getRequest.getJSON(), null, 2)); 187 | 188 | var ctrl = new ApiControllers.GetTransactionDetailsController(getRequest.getJSON()); 189 | 190 | ctrl.execute(function(){ 191 | 192 | var apiResponse = ctrl.getResponse(); 193 | 194 | response = new ApiContracts.GetTransactionDetailsResponse(apiResponse); 195 | 196 | //console.log(JSON.stringify(response, null, 2)); 197 | done(); 198 | }); 199 | }); 200 | 201 | it('should return resultcode Ok when successful', function () { 202 | 203 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 204 | }); 205 | 206 | it('should return not null transaction list when successful', function () { 207 | 208 | assert.isNotNull(response.getTransaction()); 209 | assert.isDefined(response.getTransaction()); 210 | }); 211 | 212 | it('should return transaction id same as input when successful', function () { 213 | 214 | assert.equal(response.getTransaction().getTransId(), transactionId); 215 | }); 216 | }); 217 | 218 | describe('get unsettled Transaction list', function () { 219 | var response; 220 | 221 | before(function(done){ 222 | 223 | var getRequest = new ApiContracts.GetUnsettledTransactionListRequest(); 224 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 225 | 226 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 227 | 228 | var ctrl = new ApiControllers.GetUnsettledTransactionListController(getRequest.getJSON()); 229 | 230 | ctrl.execute(function(){ 231 | 232 | var apiResponse = ctrl.getResponse(); 233 | 234 | response = new ApiContracts.GetUnsettledTransactionListResponse(apiResponse); 235 | 236 | //console.log(JSON.stringify(response, null, 2)); 237 | done(); 238 | }); 239 | }); 240 | 241 | it('should return resultcode Ok when successful', function () { 242 | 243 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 244 | }); 245 | 246 | it('should return not null transaction list when successful', function () { 247 | 248 | assert.isNotNull(response.getTransactions()); 249 | assert.isDefined(response.getTransactions()); 250 | }); 251 | 252 | it('should return not null transaction ids when successful', function () { 253 | 254 | var transactionArray = response.getTransactions().getTransaction(); 255 | transactionArray.forEach(function(transaction) { 256 | transactionId = transaction.getTransId(); 257 | assert.isNotNull(transaction.getTransId()); 258 | assert.isDefined(transaction.getTransId()); 259 | }); 260 | }); 261 | }); 262 | 263 | describe('get batch statistics', function () { 264 | var response; 265 | 266 | before(function(done){ 267 | 268 | var getRequest = new ApiContracts.GetBatchStatisticsRequest(); 269 | getRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 270 | getRequest.setBatchId(batchId); 271 | 272 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 273 | 274 | var ctrl = new ApiControllers.GetBatchStatisticsController(getRequest.getJSON()); 275 | 276 | ctrl.execute(function(){ 277 | 278 | var apiResponse = ctrl.getResponse(); 279 | 280 | response = new ApiContracts.GetBatchStatisticsResponse(apiResponse); 281 | 282 | //console.log(JSON.stringify(response, null, 2)); 283 | done(); 284 | }); 285 | }); 286 | 287 | it('should return resultcode Ok when successful', function () { 288 | 289 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 290 | }); 291 | 292 | it('should return not null batch details when successful', function () { 293 | 294 | assert.isNotNull(response.getBatch()); 295 | assert.isDefined(response.getBatch()); 296 | }); 297 | 298 | it('should return batch id same as input when successful', function () { 299 | 300 | assert.equal(response.getBatch().getBatchId(), batchId); 301 | }); 302 | }); 303 | }); 304 | -------------------------------------------------------------------------------- /test/test-visacheckout.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('chai').assert; 4 | var constants = require('./constants.js'); 5 | var ApiControllers = require('../lib/apicontrollers.js'); 6 | var ApiContracts = require('../lib/apicontracts.js'); 7 | 8 | var apiLoginKey = constants.apiLoginKey; 9 | var transactionKey = constants.transactionKey; 10 | 11 | class VisaCheckOutTestData { 12 | 13 | constructor(){ 14 | 15 | this.merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType(); 16 | this.merchantAuthenticationType.setName(apiLoginKey); 17 | this.merchantAuthenticationType.setTransactionKey(transactionKey); 18 | 19 | this.opaqueData = new ApiContracts.OpaqueDataType(); 20 | this.opaqueData.setDataDescriptor('COMMON.VCO.ONLINE.PAYMENT'); 21 | this.opaqueData.setDataValue('q1rx4GVCh0dqjZGgSBI8RB/VlI/1lwzTxDnrW/L1D4f/lfKZeQPo34eTB59akZXdRlRBW/dHVWgc2eVebvWpkAKmDrc+7Zr7lGXvHbLG78e0ZgfEReQNS4es6K7DxsDXp0UZSdnxw6g3stQhW2TqR6fcwLj7gWpZvAL3GAftP6QNCJfv6ohFPN9L/t84A1h8M0jClNq7DtDsUhuy35dEBdP8/MKOb7hSRkMqb/8qh7XUR+84FOoAKHAcG6KoRRdogTrYmPBuyDoaWUmDFgRFSSXN7Wj7evVsliis5H9y+tub/f5mAiZtl+fyFC7uIEZOLUcSWHfeX1lWxyWTEYxRq5TwnzewPNn0VbmqPh+/uaHooDQT891nUeZfm79Bunj+NfWtr06YIxW2LW3P6IWuyAhquAseL1hOv7vHT5QGogPuUJlv/+jY52tSsXrVccWu4rTjHShwvFmvxl82VZx55zcIrYFROiFVw+3sN88BL4hNnh3RCYrotWDiAwdJmJLdYhAzO2xiWLRRBgiGn27hi+G381EwLUy/6K1rx6iAN+x2bWWHgyKddSYLo0U7g+UfHBrvNSHZQcQM5LzjiZP86bx2SqQoLrqgSZQcChSy/T6C4vIvlFyomx9+7Soht6J61KoRvhM1yzlvwwjyF0ouamCRUBzrKR6j366TbdrAhAVLfuVc2XbE57Wc9bF0w4+K5I4kfA47XfRHlkA+6S4dpgp+fV+bC/jzrqIQwrs+wehzEaiR43lBQpyfPElX2SGfGk0WH4c4SbIhUY0KtyLmfgCbcAHyCAXN1ZNQvNb8Axw2j/C2B77cE81Dsi9DyGdGclM2u14UqxkXEINS2FoYQI4mZj04TR4oDG6axkp52d+ndagOS0kIH8SM71fPPiXSGw/zbm+JRdrTJLuYSvf1LbrFL2WPnHbuQuZIZDab0guanrVNjsEokJjffUPbvf+uCxytCZ148T5GWD2Daou/MK63mjl05XeySENdl3opaUj0joYFg+MkzaVYpvgiIxGEGuBdy+oA06Y/uxrgt2Xgcwwn2eo3YDUr4kqXWOI7SpqDDV1QWfd/anacjR9hCoqP2+sN2HbzbPi/jqR02etk/eSil2NiWORph2s8KneoQiMMoKfoUvi3SkzzaOxXYhD+UFdN69cxox7Y8enw++faUnDcxydr/Go5LmxJKrLH+Seez6m412ygABHzki+ooJiyYPRL+TuXzQuVDWwPh7qjrh9cU3ljkaWW2HZp+AFInyh65JHUZpSkjeXM+Sfz3VASBLTB8zq/Co737KT9t38lZEn/ffLLvD7NGW1dB3K8h4xhX7FhMLwFCt7WCvtpAXJ4J2FF55x4RDQdwdsPjXR9vHPmRsjU/eNAT8tRrJh8XTSFubyIYNd+67j+Y0u+PvVUCPK2mWTfDgU1ZNsGrI2asrVaStsER64lkfgSWD0bN4hbJaJVPAPaOxYkpzhfU34B2e3IUKdBccgqrXpMXe1r3OETmfLFnk2sIPZwBcDLVtAH5bePsu3wK3MtvmEWjGR4QQGI5oPlz9GnUaexOPAkRVJeOJIazGOgBeFDGDm7urxnKKYZzNKNnjXlij/ccWR9NYDB4TSZ1yxBZpXkLQ9TbOvrxnsy3ZrFhlJT4Nn/0YOPvfYt+sMcUXcB+09oRpFZdpVtPtkxMRiNjetZPjoXKq/2Jxj7yCAfYzRrrlbqbKXF8b06PcmFRb2dsZzbN+maEYhwWgRRa9yy7Ha2TGrH00jZ8tiowcBmnW6/UsuGn0ZMEgA02iaeIqQKf+Kqwa6EMN8HqED4IK38XKOr5RYthTaOcL9FA629MIAArVu5/LPj4b5abM3pTXk9gItVEuf5KfWceaSG1CFY1dD8/IRqIwWQGobQRpyTsYXiirkOIJnnlC8ph6eMIlCMu3wDfB4a2KrXDQuc06qRXi2KNHl8opawi2lpR/rjBfEyX5if47wNlEJkj+D/bCutN9APbSiFGs03X8cTb6CKVghQfx9PD/T+XZTA3yzBwHHZNiNJK2mhheEubgNYcnw1t9Lf9cx174OEayQrU+AORjPnEPGWYx+bYtK6XuQ9bt9gAo4HzaGRF1WB6Dr0p8gfqrxHe9HhjrbeHILmVtIJnv2jDds20pR/VRYs1IFJNWyDjgCe2uWBM+oC22YdSYyn3f2swouqqXz6yl9UTImzCM8KAzLpPGZVFlafJka8soKSxr9KBvAsBnfb34RPB7OMgSo+uqgvB3YGvOu5LpLoaVNxQ1d6GLeeQ9u9olb12Y2kPzGni99f04lI77qoleqzCcCFZC9Q'); 22 | this.opaqueData.setDataKey('KCSJeIab7wwH7mFcPM/YL+V9xBCDe4CmSjJ0MPHEodpWz4rmz78U8bR4Qqs1ipLBqH9mrfvLF4pytIcLOjKUtXvAII/xCze84INFMdtsVBgtEp5bZ4leehRQhNM+3/NH'); 23 | 24 | this.paymentType = new ApiContracts.PaymentType(); 25 | this.paymentType.setOpaqueData(this.opaqueData); 26 | } 27 | } 28 | 29 | describe('Visa Check Out', function() { 30 | this.timeout(120000); 31 | var testData = new VisaCheckOutTestData(); 32 | 33 | describe.skip('Decrypt Visa Checkout Data', function () { 34 | var response; 35 | 36 | before(function(done){ 37 | 38 | var decryptPaymentDataRequest = new ApiContracts.DecryptPaymentDataRequest(); 39 | decryptPaymentDataRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 40 | decryptPaymentDataRequest.setOpaqueData(this.opaqueData); 41 | decryptPaymentDataRequest.setCallId('1238408836021304101'); 42 | 43 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 44 | 45 | var ctrl = new ApiControllers.DecryptPaymentDataController(decryptPaymentDataRequest.getJSON()); 46 | 47 | ctrl.execute(function(){ 48 | 49 | var apiResponse = ctrl.getResponse(); 50 | 51 | response = new ApiContracts.DecryptPaymentDataResponse(apiResponse); 52 | 53 | //console.log(JSON.stringify(response, null, 2)); 54 | done(); 55 | }); 56 | }); 57 | 58 | it('should return resultcode Ok when successful', function () { 59 | 60 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 61 | }); 62 | 63 | }); 64 | 65 | describe.skip('Create a Visa Checkout Transaction', function () { 66 | var response; 67 | 68 | before(function(done){ 69 | 70 | var txnRequest = new ApiContracts.TransactionRequestType(); 71 | txnRequest.setTransactionType(ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION); 72 | txnRequest.setPayment(this.paymentType); 73 | 74 | var createRequest = new ApiContracts.CreateTransactionRequest(); 75 | createRequest.setTransactionRequest(txnRequest); 76 | 77 | createRequest.setMerchantAuthentication(testData.merchantAuthenticationType); 78 | 79 | //console.log(JSON.stringify(createRequest.getJSON(), null, 2)); 80 | 81 | var ctrl = new ApiControllers.CreateTransactionController(createRequest.getJSON()); 82 | 83 | ctrl.execute(function(){ 84 | 85 | var apiResponse = ctrl.getResponse(); 86 | 87 | response = new ApiContracts.CreateTransactionResponse(apiResponse); 88 | 89 | 90 | //console.log(JSON.stringify(response, null, 2)); 91 | done(); 92 | }); 93 | }); 94 | 95 | it('should return resultcode Ok when successful', function () { 96 | 97 | assert.equal(response.getMessages().getResultCode(), ApiContracts.MessageTypeEnum.OK); 98 | }); 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const crypto = require('crypto'); 4 | 5 | function getRandomString(text){ 6 | const randomInt = crypto.randomBytes(4).readUInt32BE(0); 7 | return text + randomInt; 8 | } 9 | 10 | function getRandomInt(){ 11 | return crypto.randomBytes(4).readUInt32BE(0); 12 | } 13 | 14 | function getRandomAmount(){ 15 | const randomFloat = crypto.randomBytes(4).readUInt32BE(0) / 0xFFFFFFFF; 16 | return ((randomFloat * 1000) + 1).toFixed(2); 17 | } 18 | 19 | function getDate(){ 20 | return (new Date()).toISOString().substring(0, 10) ; 21 | } 22 | 23 | 24 | module.exports.getRandomString = getRandomString; 25 | module.exports.getRandomInt = getRandomInt; 26 | module.exports.getRandomAmount = getRandomAmount; 27 | module.exports.getDate = getDate; --------------------------------------------------------------------------------