├── .coveragerc
├── .github
└── workflows
│ └── python-workflow.yml
├── .gitignore
├── .gitmodules
├── .project
├── .pydevproject
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── anet_python_sdk_properties_template.ini
├── authorizenet
├── __init__.py
├── apicontractsv1.py
├── apicontrollers.py
├── apicontrollersbase.py
├── constants.py
└── utility.py
├── generatingClasses.md
├── script
├── ControllerTemplate.pyt
├── addany.pl
├── generateObjectsFromXSD.bat
├── generatecontrollersfromtemplate.sh
├── generateobjectsfromxsd.sh
├── headertemplate.pyt
└── masterupdate.sh
├── setup.py
└── tests
├── __init__.py
├── apitestbase.py
├── testpyxb.py
├── testsmock.py
└── testssample.py
/.coveragerc:
--------------------------------------------------------------------------------
1 | [report]
2 | omit =
3 | */python?.?/*
4 | */site-packages/nose/*
5 | */tests/*
6 |
--------------------------------------------------------------------------------
/.github/workflows/python-workflow.yml:
--------------------------------------------------------------------------------
1 | name: Authorize.net Python CI
2 | on:
3 | push:
4 | pull_request:
5 | workflow_dispatch:
6 | env:
7 | sdk_python: 'sdk-python'
8 | sample_code_python: 'sample-code-python'
9 | jobs:
10 | workflow-job:
11 | defaults:
12 | run:
13 | shell: bash
14 | strategy:
15 | fail-fast: false
16 | matrix:
17 | operating-system: [ubuntu-latest, macos-latest, windows-latest]
18 | pyth-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
19 | include:
20 | - operating-system: ubuntu-20.04 # Checking support for ubuntu os with python 3.6
21 | pyth-version: '3.6'
22 | - operating-system: macos-13 # Checking support for mac os with python 3.6
23 | pyth-version: '3.6'
24 | - operating-system: macos-13 # Checking support for mac os with python 3.7
25 | pyth-version: '3.7'
26 | exclude:
27 | - operating-system: ubuntu-latest #arm 64 doesn't support python ver 3.7
28 | pyth-version: '3.6'
29 | - operating-system: macos-latest #arm 64 doesn't support python ver 3.6
30 | pyth-version: '3.6'
31 | - operating-system: macos-latest #arm 64 doesn't support python ver 3.7
32 | pyth-version: '3.7'
33 | runs-on: ${{matrix.operating-system}}
34 | steps:
35 | - name: Creating separate folders for SDK and Sample Codes
36 | run: |
37 | rm -rf $sdk_python
38 | rm -rf $sample_code_python
39 | mkdir $sdk_python $sample_code_python
40 |
41 | - name: Checkout authorizenet/sdk-python
42 | uses: actions/checkout@v4
43 | with:
44 | path: ${{env.sdk_python}}
45 |
46 | - name: Checkout authorizenet/sample-code-python
47 | uses: actions/checkout@v4
48 | with:
49 | repository: 'authorizenet/sample-code-python'
50 | ref: 'master'
51 | path: ${{env.sample_code_python}}
52 |
53 | - name: Install Python
54 | uses: actions/setup-python@v5
55 | with:
56 | python-version: ${{matrix.pyth-version}}
57 |
58 | - name: Install and Test
59 | run: |
60 | python -V
61 | python -m pip install --upgrade pip
62 | python -m venv virtual_env
63 | if [[ "$(uname -s)" == "Linux" ]]; then
64 | echo "OS: Linux"
65 | source virtual_env/bin/activate
66 | elif [[ "$(uname -s)" == "Darwin" ]]; then
67 | echo "OS: MacOS"
68 | source virtual_env/bin/activate
69 | else
70 | echo "OS: Windows"
71 | source virtual_env/Scripts/activate
72 | fi
73 | echo $VIRTUAL_ENV
74 |
75 | cd $sdk_python
76 | pip install -e .
77 |
78 | cd ../$sample_code_python
79 | python ./test-runner.py
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 |
5 | # C extensions
6 | *.so
7 |
8 | # Distribution / packaging
9 | .Python
10 | env/
11 | build/
12 | develop-eggs/
13 | dist/
14 | controllerstemporary/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | packages/
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *,cover
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 |
55 | # Sphinx documentation
56 | docs/_build/
57 |
58 | # PyBuilder
59 | target/
60 |
61 | # Operating system files
62 | .DS_Store
63 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "sample-code-python"]
2 | path = sample-code-python
3 | url = https://github.com/AuthorizeNet/sample-code-python
4 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | sdk-py
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /${PROJECT_DIR_NAME}
5 |
6 | python 2.7
7 | Default
8 |
9 | K:\PyXB-1.2.4\scripts
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 |
3 | dist: trusty
4 |
5 | sudo: false
6 | env:
7 | - TEST_SUITE=samples
8 | - TEST_SUITE=coverage
9 | python:
10 | - "2.7"
11 | - "3.4"
12 | - "3.5"
13 | - "3.6"
14 | - "pypy"
15 | - "pypy3"
16 |
17 | matrix:
18 | fast_finish: true
19 | allow_failures:
20 | - python: 3.7
21 | dist: xenial
22 | sudo: true
23 | - python: 3.8
24 | dist: xenial
25 | sudo: true
26 | - python: "pypy"
27 | - python: "pypy3"
28 | - python: "3.4"
29 | # pypy will just crash due to an incompatibility with lxml.
30 | # Newer versions of pypy seem to crash also, so we probably have to fix with a newer version of lxml
31 |
32 | before_install:
33 | # execute all of the commands which need to be executed
34 | # before installing dependencies
35 |
36 | install:
37 | # install all of the dependencies we need here
38 | - pip install nose==1.*
39 | - pip install pyxb==1.2.5
40 | # can't change the pyxb version without changing the version in setup.py
41 | # and regenerating the bindings in apicontractsv1.py
42 | - pip install lxml==4.*
43 | - pip install requests==2.*
44 | - if [[ "$TEST_SUITE" == "coverage" ]]; then pip install coveralls; fi
45 |
46 | before_script:
47 | # execute all of the commands which need to be executed
48 | # before running actual tests
49 | - if [[ "$TEST_SUITE" == "samples" ]]; then git submodule update --remote --recursive; fi
50 |
51 | script:
52 | # execute all of the tests or other commands to determine
53 | # whether the build will pass or fail
54 | - if [[ "$TEST_SUITE" == "coverage" ]]; then nosetests --with-coverage -cover-package=authorizenet; coveralls; fi
55 | - if [[ "$TEST_SUITE" == "samples" ]]; then python setup.py install; cd sample-code-python; python ./test-runner.py; fi
56 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | + Thanks for contributing to the Authorize.Net Python 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-python/authorizenet/apicontractsv1.py](https://github.com/AuthorizeNet/sdk-python/tree/master/authorizenet) and [sdk-python/authorizenet/apicontrollers.py](https://github.com/AuthorizeNet/sdk-python/tree/master/authorizenet) folders, except [sdk-python/authorizenet/apicontrollersbase.py](https://github.com/AuthorizeNet/sdk-python/tree/master/authorizenet).
7 | - Recent changes will be in [the future branch](https://github.com/AuthorizeNet/sdk-python/tree/future). Before submitting an issue or pull request, check the future branch first to see if a fix has already been merged.
8 | - **Always use the future branch for pull requests.** We will first merge pull requests to the future branch, before pushing to the master branch for the next release.
--------------------------------------------------------------------------------
/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 Python SDK
2 |
3 | [](https://github.com/AuthorizeNet/sdk-python/actions/workflows/python-workflow.yml)
4 | [](https://badge.fury.io/py/authorizenet)
5 |
6 |
7 | ## Requirements
8 | * Python 3.6 or later
9 | * OpenSSL 1.0.2 or greater
10 | * An Authorize.Net account (see _Registration & Configuration_ section below)
11 |
12 | _Note: Support for Python 2.x and Python <=3.5 has been discontinued, due to EOL of the Python package._
13 | ### Contribution
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 | - Before creating pull requests, please read [the contributors guide](CONTRIBUTING.md).
16 |
17 | ### TLS 1.2
18 | 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.
19 |
20 |
21 | ## Installation
22 | To install the AuthorizeNet Python SDK:
23 |
24 | `pip install authorizenet`
25 |
26 |
27 | ## Registration & Configuration
28 | 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.
29 | If you don't currently have a production Authorize.Net account, [sign up for a sandbox account](https://developer.authorize.net/sandbox/).
30 |
31 | ### Authentication
32 | To authenticate with the Authorize.Net API, use your account's API Login ID and Transaction Key. If you don't have these credentials, obtain them from the Merchant Interface. For production accounts, the Merchant Interface is located at (https://account.authorize.net/), and for sandbox accounts, at (https://sandbox.authorize.net).
33 |
34 | After you have your credentials, load them into the appropriate variables in your code. The below sample code shows how to set the credentials as part of the API request.
35 |
36 | #### To set your API credentials for an API request:
37 | ```python
38 | merchantAuth = apicontractsv1.merchantAuthenticationType()
39 | merchantAuth.name = 'YOUR_API_LOGIN_ID'
40 | merchantAuth.transactionKey = 'YOUR_TRANSACTION_KEY'
41 | ```
42 |
43 | Never include your API Login ID and Transaction Key directly in a file 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 your code.
44 |
45 | ### Switching between the sandbox environment and the production environment
46 | 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 the sandbox environment. To switch to the production environment, use the `setenvironment` method on the controller before executing. For example:
47 | ```python
48 | # For PRODUCTION use
49 | createtransactioncontroller.setenvironment(constants.PRODUCTION)
50 | ```
51 |
52 | API credentials are different for each environment, so be sure to switch to the appropriate credentials when switching environments.
53 |
54 | ### Enable Logging in the SDK
55 | Python SDK uses the logger _'authorizenet.sdk'_. By default, the logger in the SDK is not configured to write output. You can configure the logger in your code to start seeing logs from the SDK.
56 |
57 | A sample logger configuration is given as below:
58 |
59 | ```python
60 | import logging
61 | logger = logging.getLogger('authorizenet.sdk')
62 | handler = logging.FileHandler('anetSdk.log')
63 | formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
64 | handler.setFormatter(formatter)
65 | logger.addHandler(handler)
66 | logger.setLevel(logging.DEBUG)
67 | logger.debug('Logger set up for Authorizenet Python SDK complete')
68 | ```
69 |
70 |
71 | ## SDK Usage Examples and Sample Code
72 | When using this SDK, downloading the Authorize.Net sample code repository is recommended.
73 | * [Authorize.Net Python Sample Code Repository (on GitHub)](https://github.com/AuthorizeNet/sample-code-python)
74 |
75 | The repository contains comprehensive sample code for 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 | * [Developer Center API Reference](http://developer.authorize.net/api/reference/index.html)
79 |
80 | Use the examples in the API Reference to determine which methods and information to include in an API request using this SDK.
81 |
82 | ## Create a Chase Pay Transaction
83 |
84 | 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.
85 |
86 | The following information is required in the request:
87 | - The **payment token**,
88 | - The **expiration date**,
89 | - The **cryptogram** received from the token provider,
90 | - The **tokenRequestorName**,
91 | - The **tokenRequestorId**, and
92 | - The **tokenRequestorEci**.
93 |
94 | When using the SDK to submit Chase Pay transactions, consider the following points:
95 | - `tokenRequesterName` must be populated with **`”CHASE_PAY”`**
96 | - `tokenRequestorId` must be populated with the **`Token Requestor ID`** provided by Chase Pay services for each transaction during consumer checkout
97 | - `tokenRequesterEci` must be populated with the **`ECI Indicator`** provided by Chase Pay services for each transaction during consumer checkout
98 |
99 | ## Building & Testing the SDK
100 |
101 | ### Requirements
102 | - Python 3.6
103 | - PyXB-X
104 |
105 | ### Testing Guide
106 | 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.
107 |
108 | ### Transaction Hash Upgrade
109 | 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/).
110 |
111 | ## License
112 | This repository is distributed under a proprietary license. See the provided [`LICENSE.txt`](/LICENSE.txt) file.
113 |
--------------------------------------------------------------------------------
/anet_python_sdk_properties_template.ini:
--------------------------------------------------------------------------------
1 | [properties]
2 |
3 | #sandbox cradentials
4 | api.login.id : 6rF76h2U93AL
5 | transaction.key : 7jh86zEUhy7228FG
6 | md5.hash.key : MD5_HASH_KEY
7 |
8 | #log
9 | logfilename : logFile.log
10 |
11 | #proxy setup
12 | #http://proxy.yourcompany.com:80
13 | #https://proxy.yourcompany.com:443
14 |
15 |
16 |
--------------------------------------------------------------------------------
/authorizenet/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AuthorizeNet/sdk-python/2d7ee348c55216e2289662c8b45f134dc09ca816/authorizenet/__init__.py
--------------------------------------------------------------------------------
/authorizenet/apicontrollers.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Aug 28, 2024
3 |
4 | @author: gnongsie
5 | '''
6 | import logging
7 | from authorizenet.constants import constants
8 | from authorizenet import apicontractsv1
9 | from authorizenet import apicontrollersbase
10 |
11 | anetLogger = logging.getLogger(constants.defaultLoggerName)
12 |
13 | class ARBCancelSubscriptionController(apicontrollersbase.APIOperationBase):
14 |
15 | def __init__(self, apirequest):
16 | super(ARBCancelSubscriptionController, self).__init__(apirequest)
17 | return
18 |
19 | def validaterequest(self):
20 | anetLogger.debug('performing custom validation.')
21 | #validate required fields
22 | #if (self._request.xyz == "null"):
23 | # raise ValueError('xyz is required')
24 | return
25 |
26 | def getrequesttype(self):
27 | '''Returns request type'''
28 | return 'ARBCancelSubscriptionRequest'
29 |
30 | def getresponseclass(self):
31 | ''' Returns the response class '''
32 | return apicontractsv1.ARBCancelSubscriptionResponse()
33 |
34 | class ARBCreateSubscriptionController(apicontrollersbase.APIOperationBase):
35 |
36 | def __init__(self, apirequest):
37 | super(ARBCreateSubscriptionController, self).__init__(apirequest)
38 | return
39 |
40 | def validaterequest(self):
41 | anetLogger.debug('performing custom validation.')
42 | #validate required fields
43 | #if (self._request.xyz == "null"):
44 | # raise ValueError('xyz is required')
45 | return
46 |
47 | def getrequesttype(self):
48 | '''Returns request type'''
49 | return 'ARBCreateSubscriptionRequest'
50 |
51 | def getresponseclass(self):
52 | ''' Returns the response class '''
53 | return apicontractsv1.ARBCreateSubscriptionResponse()
54 |
55 | class ARBGetSubscriptionController(apicontrollersbase.APIOperationBase):
56 |
57 | def __init__(self, apirequest):
58 | super(ARBGetSubscriptionController, self).__init__(apirequest)
59 | return
60 |
61 | def validaterequest(self):
62 | anetLogger.debug('performing custom validation.')
63 | #validate required fields
64 | #if (self._request.xyz == "null"):
65 | # raise ValueError('xyz is required')
66 | return
67 |
68 | def getrequesttype(self):
69 | '''Returns request type'''
70 | return 'ARBGetSubscriptionRequest'
71 |
72 | def getresponseclass(self):
73 | ''' Returns the response class '''
74 | return apicontractsv1.ARBGetSubscriptionResponse()
75 | class ARBGetSubscriptionListController(apicontrollersbase.APIOperationBase):
76 |
77 | def __init__(self, apirequest):
78 | super(ARBGetSubscriptionListController, self).__init__(apirequest)
79 | return
80 |
81 | def validaterequest(self):
82 | anetLogger.debug('performing custom validation.')
83 | #validate required fields
84 | #if (self._request.xyz == "null"):
85 | # raise ValueError('xyz is required')
86 | return
87 |
88 | def getrequesttype(self):
89 | '''Returns request type'''
90 | return 'ARBGetSubscriptionListRequest'
91 |
92 | def getresponseclass(self):
93 | ''' Returns the response class '''
94 | return apicontractsv1.ARBGetSubscriptionListResponse()
95 |
96 | class ARBGetSubscriptionStatusController(apicontrollersbase.APIOperationBase):
97 |
98 | def __init__(self, apirequest):
99 | super(ARBGetSubscriptionStatusController, self).__init__(apirequest)
100 | return
101 |
102 | def validaterequest(self):
103 | anetLogger.debug('performing custom validation.')
104 | #validate required fields
105 | #if (self._request.xyz == "null"):
106 | # raise ValueError('xyz is required')
107 | return
108 |
109 | def getrequesttype(self):
110 | '''Returns request type'''
111 | return 'ARBGetSubscriptionStatusRequest'
112 |
113 | def getresponseclass(self):
114 | ''' Returns the response class '''
115 | return apicontractsv1.ARBGetSubscriptionStatusResponse()
116 |
117 | def afterexecute(self):
118 | response = self._httpResponse
119 | if constants.note in response:
120 | response = response.replace(constants.note, '')
121 |
122 | if constants.StatusStart in response:
123 | start = response.index(constants.StatusStart)
124 | end = response.index(constants.StatusEnd)
125 | response = response.replace(response[start:end+9], '')
126 |
127 | self._httpResponse = response
128 | return
129 |
130 | class ARBUpdateSubscriptionController(apicontrollersbase.APIOperationBase):
131 |
132 | def __init__(self, apirequest):
133 | super(ARBUpdateSubscriptionController, self).__init__(apirequest)
134 | return
135 |
136 | def validaterequest(self):
137 | anetLogger.debug('performing custom validation.')
138 | #validate required fields
139 | #if (self._request.xyz == "null"):
140 | # raise ValueError('xyz is required')
141 | return
142 |
143 | def getrequesttype(self):
144 | '''Returns request type'''
145 | return 'ARBUpdateSubscriptionRequest'
146 |
147 | def getresponseclass(self):
148 | ''' Returns the response class '''
149 | return apicontractsv1.ARBUpdateSubscriptionResponse()
150 | class authenticateTestController(apicontrollersbase.APIOperationBase):
151 |
152 | def __init__(self, apirequest):
153 | super(authenticateTestController, self).__init__(apirequest)
154 | return
155 |
156 | def validaterequest(self):
157 | anetLogger.debug('performing custom validation.')
158 | #validate required fields
159 | #if (self._request.xyz == "null"):
160 | # raise ValueError('xyz is required')
161 | return
162 |
163 | def getrequesttype(self):
164 | '''Returns request type'''
165 | return 'authenticateTestRequest'
166 |
167 | def getresponseclass(self):
168 | ''' Returns the response class '''
169 | return apicontractsv1.authenticateTestResponse()
170 | class createCustomerPaymentProfileController(apicontrollersbase.APIOperationBase):
171 |
172 | def __init__(self, apirequest):
173 | super(createCustomerPaymentProfileController, self).__init__(apirequest)
174 | return
175 |
176 | def validaterequest(self):
177 | anetLogger.debug('performing custom validation.')
178 | #validate required fields
179 | #if (self._request.xyz == "null"):
180 | # raise ValueError('xyz is required')
181 | return
182 |
183 | def getrequesttype(self):
184 | '''Returns request type'''
185 | return 'createCustomerPaymentProfileRequest'
186 |
187 | def getresponseclass(self):
188 | ''' Returns the response class '''
189 | return apicontractsv1.createCustomerPaymentProfileResponse()
190 | class createCustomerProfileController(apicontrollersbase.APIOperationBase):
191 |
192 | def __init__(self, apirequest):
193 | super(createCustomerProfileController, self).__init__(apirequest)
194 | return
195 |
196 | def validaterequest(self):
197 | anetLogger.debug('performing custom validation.')
198 | #validate required fields
199 | #if (self._request.xyz == "null"):
200 | # raise ValueError('xyz is required')
201 | return
202 |
203 | def getrequesttype(self):
204 | '''Returns request type'''
205 | return 'createCustomerProfileRequest'
206 |
207 | def getresponseclass(self):
208 | ''' Returns the response class '''
209 | return apicontractsv1.createCustomerProfileResponse()
210 | class createCustomerProfileFromTransactionController(apicontrollersbase.APIOperationBase):
211 |
212 | def __init__(self, apirequest):
213 | super(createCustomerProfileFromTransactionController, self).__init__(apirequest)
214 | return
215 |
216 | def validaterequest(self):
217 | anetLogger.debug('performing custom validation.')
218 | #validate required fields
219 | #if (self._request.xyz == "null"):
220 | # raise ValueError('xyz is required')
221 | return
222 |
223 | def getrequesttype(self):
224 | '''Returns request type'''
225 | return 'createCustomerProfileFromTransactionRequest'
226 |
227 | def getresponseclass(self):
228 | ''' Returns the response class '''
229 | return apicontractsv1.createCustomerProfileResponse()
230 | class createCustomerProfileTransactionController(apicontrollersbase.APIOperationBase):
231 |
232 | def __init__(self, apirequest):
233 | super(createCustomerProfileTransactionController, self).__init__(apirequest)
234 | return
235 |
236 | def validaterequest(self):
237 | anetLogger.debug('performing custom validation.')
238 | #validate required fields
239 | #if (self._request.xyz == "null"):
240 | # raise ValueError('xyz is required')
241 | return
242 |
243 | def getrequesttype(self):
244 | '''Returns request type'''
245 | return 'createCustomerProfileTransactionRequest'
246 |
247 | def getresponseclass(self):
248 | ''' Returns the response class '''
249 | return apicontractsv1.createCustomerProfileTransactionResponse()
250 | class createCustomerShippingAddressController(apicontrollersbase.APIOperationBase):
251 |
252 | def __init__(self, apirequest):
253 | super(createCustomerShippingAddressController, self).__init__(apirequest)
254 | return
255 |
256 | def validaterequest(self):
257 | anetLogger.debug('performing custom validation.')
258 | #validate required fields
259 | #if (self._request.xyz == "null"):
260 | # raise ValueError('xyz is required')
261 | return
262 |
263 | def getrequesttype(self):
264 | '''Returns request type'''
265 | return 'createCustomerShippingAddressRequest'
266 |
267 | def getresponseclass(self):
268 | ''' Returns the response class '''
269 | return apicontractsv1.createCustomerShippingAddressResponse()
270 | class createTransactionController(apicontrollersbase.APIOperationBase):
271 |
272 | def __init__(self, apirequest):
273 | super(createTransactionController, self).__init__(apirequest)
274 | return
275 |
276 | def validaterequest(self):
277 | anetLogger.debug('performing custom validation.')
278 | #validate required fields
279 | #if (self._request.xyz == "null"):
280 | # raise ValueError('xyz is required')
281 | return
282 |
283 | def getrequesttype(self):
284 | '''Returns request type'''
285 | return 'createTransactionRequest'
286 |
287 | def getresponseclass(self):
288 | ''' Returns the response class '''
289 | return apicontractsv1.createTransactionResponse()
290 | class decryptPaymentDataController(apicontrollersbase.APIOperationBase):
291 |
292 | def __init__(self, apirequest):
293 | super(decryptPaymentDataController, self).__init__(apirequest)
294 | return
295 |
296 | def validaterequest(self):
297 | anetLogger.debug('performing custom validation.')
298 | #validate required fields
299 | #if (self._request.xyz == "null"):
300 | # raise ValueError('xyz is required')
301 | return
302 |
303 | def getrequesttype(self):
304 | '''Returns request type'''
305 | return 'decryptPaymentDataRequest'
306 |
307 | def getresponseclass(self):
308 | ''' Returns the response class '''
309 | return apicontractsv1.decryptPaymentDataResponse()
310 | class deleteCustomerPaymentProfileController(apicontrollersbase.APIOperationBase):
311 |
312 | def __init__(self, apirequest):
313 | super(deleteCustomerPaymentProfileController, self).__init__(apirequest)
314 | return
315 |
316 | def validaterequest(self):
317 | anetLogger.debug('performing custom validation.')
318 | #validate required fields
319 | #if (self._request.xyz == "null"):
320 | # raise ValueError('xyz is required')
321 | return
322 |
323 | def getrequesttype(self):
324 | '''Returns request type'''
325 | return 'deleteCustomerPaymentProfileRequest'
326 |
327 | def getresponseclass(self):
328 | ''' Returns the response class '''
329 | return apicontractsv1.deleteCustomerPaymentProfileResponse()
330 | class deleteCustomerProfileController(apicontrollersbase.APIOperationBase):
331 |
332 | def __init__(self, apirequest):
333 | super(deleteCustomerProfileController, self).__init__(apirequest)
334 | return
335 |
336 | def validaterequest(self):
337 | anetLogger.debug('performing custom validation.')
338 | #validate required fields
339 | #if (self._request.xyz == "null"):
340 | # raise ValueError('xyz is required')
341 | return
342 |
343 | def getrequesttype(self):
344 | '''Returns request type'''
345 | return 'deleteCustomerProfileRequest'
346 |
347 | def getresponseclass(self):
348 | ''' Returns the response class '''
349 | return apicontractsv1.deleteCustomerProfileResponse()
350 | class deleteCustomerShippingAddressController(apicontrollersbase.APIOperationBase):
351 |
352 | def __init__(self, apirequest):
353 | super(deleteCustomerShippingAddressController, self).__init__(apirequest)
354 | return
355 |
356 | def validaterequest(self):
357 | anetLogger.debug('performing custom validation.')
358 | #validate required fields
359 | #if (self._request.xyz == "null"):
360 | # raise ValueError('xyz is required')
361 | return
362 |
363 | def getrequesttype(self):
364 | '''Returns request type'''
365 | return 'deleteCustomerShippingAddressRequest'
366 |
367 | def getresponseclass(self):
368 | ''' Returns the response class '''
369 | return apicontractsv1.deleteCustomerShippingAddressResponse()
370 | class ErrorController(apicontrollersbase.APIOperationBase):
371 |
372 | def __init__(self, apirequest):
373 | super(ErrorController, self).__init__(apirequest)
374 | return
375 |
376 | def validaterequest(self):
377 | anetLogger.debug('performing custom validation.')
378 | #validate required fields
379 | #if (self._request.xyz == "null"):
380 | # raise ValueError('xyz is required')
381 | return
382 |
383 | def getrequesttype(self):
384 | '''Returns request type'''
385 | return 'ErrorRequest'
386 |
387 | def getresponseclass(self):
388 | ''' Returns the response class '''
389 | return apicontractsv1.ErrorResponse()
390 | class getAUJobDetailsController(apicontrollersbase.APIOperationBase):
391 |
392 | def __init__(self, apirequest):
393 | super(getAUJobDetailsController, self).__init__(apirequest)
394 | return
395 |
396 | def validaterequest(self):
397 | anetLogger.debug('performing custom validation.')
398 | #validate required fields
399 | #if (self._request.xyz == "null"):
400 | # raise ValueError('xyz is required')
401 | return
402 |
403 | def getrequesttype(self):
404 | '''Returns request type'''
405 | return 'getAUJobDetailsRequest'
406 |
407 | def getresponseclass(self):
408 | ''' Returns the response class '''
409 | return apicontractsv1.getAUJobDetailsResponse()
410 | class getAUJobSummaryController(apicontrollersbase.APIOperationBase):
411 |
412 | def __init__(self, apirequest):
413 | super(getAUJobSummaryController, self).__init__(apirequest)
414 | return
415 |
416 | def validaterequest(self):
417 | anetLogger.debug('performing custom validation.')
418 | #validate required fields
419 | #if (self._request.xyz == "null"):
420 | # raise ValueError('xyz is required')
421 | return
422 |
423 | def getrequesttype(self):
424 | '''Returns request type'''
425 | return 'getAUJobSummaryRequest'
426 |
427 | def getresponseclass(self):
428 | ''' Returns the response class '''
429 | return apicontractsv1.getAUJobSummaryResponse()
430 | class getBatchStatisticsController(apicontrollersbase.APIOperationBase):
431 |
432 | def __init__(self, apirequest):
433 | super(getBatchStatisticsController, self).__init__(apirequest)
434 | return
435 |
436 | def validaterequest(self):
437 | anetLogger.debug('performing custom validation.')
438 | #validate required fields
439 | #if (self._request.xyz == "null"):
440 | # raise ValueError('xyz is required')
441 | return
442 |
443 | def getrequesttype(self):
444 | '''Returns request type'''
445 | return 'getBatchStatisticsRequest'
446 |
447 | def getresponseclass(self):
448 | ''' Returns the response class '''
449 | return apicontractsv1.getBatchStatisticsResponse()
450 | class getCustomerPaymentProfileController(apicontrollersbase.APIOperationBase):
451 |
452 | def __init__(self, apirequest):
453 | super(getCustomerPaymentProfileController, self).__init__(apirequest)
454 | return
455 |
456 | def validaterequest(self):
457 | anetLogger.debug('performing custom validation.')
458 | #validate required fields
459 | #if (self._request.xyz == "null"):
460 | # raise ValueError('xyz is required')
461 | return
462 |
463 | def getrequesttype(self):
464 | '''Returns request type'''
465 | return 'getCustomerPaymentProfileRequest'
466 |
467 | def getresponseclass(self):
468 | ''' Returns the response class '''
469 | return apicontractsv1.getCustomerPaymentProfileResponse()
470 | class getCustomerPaymentProfileListController(apicontrollersbase.APIOperationBase):
471 |
472 | def __init__(self, apirequest):
473 | super(getCustomerPaymentProfileListController, self).__init__(apirequest)
474 | return
475 |
476 | def validaterequest(self):
477 | anetLogger.debug('performing custom validation.')
478 | #validate required fields
479 | #if (self._request.xyz == "null"):
480 | # raise ValueError('xyz is required')
481 | return
482 |
483 | def getrequesttype(self):
484 | '''Returns request type'''
485 | return 'getCustomerPaymentProfileListRequest'
486 |
487 | def getresponseclass(self):
488 | ''' Returns the response class '''
489 | return apicontractsv1.getCustomerPaymentProfileListResponse()
490 | class getCustomerProfileController(apicontrollersbase.APIOperationBase):
491 |
492 | def __init__(self, apirequest):
493 | super(getCustomerProfileController, self).__init__(apirequest)
494 | return
495 |
496 | def validaterequest(self):
497 | anetLogger.debug('performing custom validation.')
498 | #validate required fields
499 | #if (self._request.xyz == "null"):
500 | # raise ValueError('xyz is required')
501 | return
502 |
503 | def getrequesttype(self):
504 | '''Returns request type'''
505 | return 'getCustomerProfileRequest'
506 |
507 | def getresponseclass(self):
508 | ''' Returns the response class '''
509 | return apicontractsv1.getCustomerProfileResponse()
510 | class getCustomerProfileIdsController(apicontrollersbase.APIOperationBase):
511 |
512 | def __init__(self, apirequest):
513 | super(getCustomerProfileIdsController, self).__init__(apirequest)
514 | return
515 |
516 | def validaterequest(self):
517 | anetLogger.debug('performing custom validation.')
518 | #validate required fields
519 | #if (self._request.xyz == "null"):
520 | # raise ValueError('xyz is required')
521 | return
522 |
523 | def getrequesttype(self):
524 | '''Returns request type'''
525 | return 'getCustomerProfileIdsRequest'
526 |
527 | def getresponseclass(self):
528 | ''' Returns the response class '''
529 | return apicontractsv1.getCustomerProfileIdsResponse()
530 | class getCustomerShippingAddressController(apicontrollersbase.APIOperationBase):
531 |
532 | def __init__(self, apirequest):
533 | super(getCustomerShippingAddressController, self).__init__(apirequest)
534 | return
535 |
536 | def validaterequest(self):
537 | anetLogger.debug('performing custom validation.')
538 | #validate required fields
539 | #if (self._request.xyz == "null"):
540 | # raise ValueError('xyz is required')
541 | return
542 |
543 | def getrequesttype(self):
544 | '''Returns request type'''
545 | return 'getCustomerShippingAddressRequest'
546 |
547 | def getresponseclass(self):
548 | ''' Returns the response class '''
549 | return apicontractsv1.getCustomerShippingAddressResponse()
550 | class getHostedPaymentPageController(apicontrollersbase.APIOperationBase):
551 |
552 | def __init__(self, apirequest):
553 | super(getHostedPaymentPageController, self).__init__(apirequest)
554 | return
555 |
556 | def validaterequest(self):
557 | anetLogger.debug('performing custom validation.')
558 | #validate required fields
559 | #if (self._request.xyz == "null"):
560 | # raise ValueError('xyz is required')
561 | return
562 |
563 | def getrequesttype(self):
564 | '''Returns request type'''
565 | return 'getHostedPaymentPageRequest'
566 |
567 | def getresponseclass(self):
568 | ''' Returns the response class '''
569 | return apicontractsv1.getHostedPaymentPageResponse()
570 | class getHostedProfilePageController(apicontrollersbase.APIOperationBase):
571 |
572 | def __init__(self, apirequest):
573 | super(getHostedProfilePageController, self).__init__(apirequest)
574 | return
575 |
576 | def validaterequest(self):
577 | anetLogger.debug('performing custom validation.')
578 | #validate required fields
579 | #if (self._request.xyz == "null"):
580 | # raise ValueError('xyz is required')
581 | return
582 |
583 | def getrequesttype(self):
584 | '''Returns request type'''
585 | return 'getHostedProfilePageRequest'
586 |
587 | def getresponseclass(self):
588 | ''' Returns the response class '''
589 | return apicontractsv1.getHostedProfilePageResponse()
590 | class getMerchantDetailsController(apicontrollersbase.APIOperationBase):
591 |
592 | def __init__(self, apirequest):
593 | super(getMerchantDetailsController, self).__init__(apirequest)
594 | return
595 |
596 | def validaterequest(self):
597 | anetLogger.debug('performing custom validation.')
598 | #validate required fields
599 | #if (self._request.xyz == "null"):
600 | # raise ValueError('xyz is required')
601 | return
602 |
603 | def getrequesttype(self):
604 | '''Returns request type'''
605 | return 'getMerchantDetailsRequest'
606 |
607 | def getresponseclass(self):
608 | ''' Returns the response class '''
609 | return apicontractsv1.getMerchantDetailsResponse()
610 | class getSettledBatchListController(apicontrollersbase.APIOperationBase):
611 |
612 | def __init__(self, apirequest):
613 | super(getSettledBatchListController, self).__init__(apirequest)
614 | return
615 |
616 | def validaterequest(self):
617 | anetLogger.debug('performing custom validation.')
618 | #validate required fields
619 | #if (self._request.xyz == "null"):
620 | # raise ValueError('xyz is required')
621 | return
622 |
623 | def getrequesttype(self):
624 | '''Returns request type'''
625 | return 'getSettledBatchListRequest'
626 |
627 | def getresponseclass(self):
628 | ''' Returns the response class '''
629 | return apicontractsv1.getSettledBatchListResponse()
630 | class getTransactionDetailsController(apicontrollersbase.APIOperationBase):
631 |
632 | def __init__(self, apirequest):
633 | super(getTransactionDetailsController, self).__init__(apirequest)
634 | return
635 |
636 | def validaterequest(self):
637 | anetLogger.debug('performing custom validation.')
638 | #validate required fields
639 | #if (self._request.xyz == "null"):
640 | # raise ValueError('xyz is required')
641 | return
642 |
643 | def getrequesttype(self):
644 | '''Returns request type'''
645 | return 'getTransactionDetailsRequest'
646 |
647 | def getresponseclass(self):
648 | ''' Returns the response class '''
649 | return apicontractsv1.getTransactionDetailsResponse()
650 | class getTransactionListController(apicontrollersbase.APIOperationBase):
651 |
652 | def __init__(self, apirequest):
653 | super(getTransactionListController, self).__init__(apirequest)
654 | return
655 |
656 | def validaterequest(self):
657 | anetLogger.debug('performing custom validation.')
658 | #validate required fields
659 | #if (self._request.xyz == "null"):
660 | # raise ValueError('xyz is required')
661 | return
662 |
663 | def getrequesttype(self):
664 | '''Returns request type'''
665 | return 'getTransactionListRequest'
666 |
667 | def getresponseclass(self):
668 | ''' Returns the response class '''
669 | return apicontractsv1.getTransactionListResponse()
670 | class getTransactionListForCustomerController(apicontrollersbase.APIOperationBase):
671 |
672 | def __init__(self, apirequest):
673 | super(getTransactionListForCustomerController, self).__init__(apirequest)
674 | return
675 |
676 | def validaterequest(self):
677 | anetLogger.debug('performing custom validation.')
678 | #validate required fields
679 | #if (self._request.xyz == "null"):
680 | # raise ValueError('xyz is required')
681 | return
682 |
683 | def getrequesttype(self):
684 | '''Returns request type'''
685 | return 'getTransactionListForCustomerRequest'
686 |
687 | def getresponseclass(self):
688 | ''' Returns the response class '''
689 | return apicontractsv1.getTransactionListResponse()
690 | class getUnsettledTransactionListController(apicontrollersbase.APIOperationBase):
691 |
692 | def __init__(self, apirequest):
693 | super(getUnsettledTransactionListController, self).__init__(apirequest)
694 | return
695 |
696 | def validaterequest(self):
697 | anetLogger.debug('performing custom validation.')
698 | #validate required fields
699 | #if (self._request.xyz == "null"):
700 | # raise ValueError('xyz is required')
701 | return
702 |
703 | def getrequesttype(self):
704 | '''Returns request type'''
705 | return 'getUnsettledTransactionListRequest'
706 |
707 | def getresponseclass(self):
708 | ''' Returns the response class '''
709 | return apicontractsv1.getUnsettledTransactionListResponse()
710 | class isAliveController(apicontrollersbase.APIOperationBase):
711 |
712 | def __init__(self, apirequest):
713 | super(isAliveController, self).__init__(apirequest)
714 | return
715 |
716 | def validaterequest(self):
717 | anetLogger.debug('performing custom validation.')
718 | #validate required fields
719 | #if (self._request.xyz == "null"):
720 | # raise ValueError('xyz is required')
721 | return
722 |
723 | def getrequesttype(self):
724 | '''Returns request type'''
725 | return 'isAliveRequest'
726 |
727 | def getresponseclass(self):
728 | ''' Returns the response class '''
729 | return apicontractsv1.isAliveResponse()
730 | class logoutController(apicontrollersbase.APIOperationBase):
731 |
732 | def __init__(self, apirequest):
733 | super(logoutController, self).__init__(apirequest)
734 | return
735 |
736 | def validaterequest(self):
737 | anetLogger.debug('performing custom validation.')
738 | #validate required fields
739 | #if (self._request.xyz == "null"):
740 | # raise ValueError('xyz is required')
741 | return
742 |
743 | def getrequesttype(self):
744 | '''Returns request type'''
745 | return 'logoutRequest'
746 |
747 | def getresponseclass(self):
748 | ''' Returns the response class '''
749 | return apicontractsv1.logoutResponse()
750 | class mobileDeviceLoginController(apicontrollersbase.APIOperationBase):
751 |
752 | def __init__(self, apirequest):
753 | super(mobileDeviceLoginController, self).__init__(apirequest)
754 | return
755 |
756 | def validaterequest(self):
757 | anetLogger.debug('performing custom validation.')
758 | #validate required fields
759 | #if (self._request.xyz == "null"):
760 | # raise ValueError('xyz is required')
761 | return
762 |
763 | def getrequesttype(self):
764 | '''Returns request type'''
765 | return 'mobileDeviceLoginRequest'
766 |
767 | def getresponseclass(self):
768 | ''' Returns the response class '''
769 | return apicontractsv1.mobileDeviceLoginResponse()
770 | class mobileDeviceRegistrationController(apicontrollersbase.APIOperationBase):
771 |
772 | def __init__(self, apirequest):
773 | super(mobileDeviceRegistrationController, self).__init__(apirequest)
774 | return
775 |
776 | def validaterequest(self):
777 | anetLogger.debug('performing custom validation.')
778 | #validate required fields
779 | #if (self._request.xyz == "null"):
780 | # raise ValueError('xyz is required')
781 | return
782 |
783 | def getrequesttype(self):
784 | '''Returns request type'''
785 | return 'mobileDeviceRegistrationRequest'
786 |
787 | def getresponseclass(self):
788 | ''' Returns the response class '''
789 | return apicontractsv1.mobileDeviceRegistrationResponse()
790 | class securePaymentContainerController(apicontrollersbase.APIOperationBase):
791 |
792 | def __init__(self, apirequest):
793 | super(securePaymentContainerController, self).__init__(apirequest)
794 | return
795 |
796 | def validaterequest(self):
797 | anetLogger.debug('performing custom validation.')
798 | #validate required fields
799 | #if (self._request.xyz == "null"):
800 | # raise ValueError('xyz is required')
801 | return
802 |
803 | def getrequesttype(self):
804 | '''Returns request type'''
805 | return 'securePaymentContainerRequest'
806 |
807 | def getresponseclass(self):
808 | ''' Returns the response class '''
809 | return apicontractsv1.securePaymentContainerResponse()
810 | class sendCustomerTransactionReceiptController(apicontrollersbase.APIOperationBase):
811 |
812 | def __init__(self, apirequest):
813 | super(sendCustomerTransactionReceiptController, self).__init__(apirequest)
814 | return
815 |
816 | def validaterequest(self):
817 | anetLogger.debug('performing custom validation.')
818 | #validate required fields
819 | #if (self._request.xyz == "null"):
820 | # raise ValueError('xyz is required')
821 | return
822 |
823 | def getrequesttype(self):
824 | '''Returns request type'''
825 | return 'sendCustomerTransactionReceiptRequest'
826 |
827 | def getresponseclass(self):
828 | ''' Returns the response class '''
829 | return apicontractsv1.sendCustomerTransactionReceiptResponse()
830 | class updateCustomerPaymentProfileController(apicontrollersbase.APIOperationBase):
831 |
832 | def __init__(self, apirequest):
833 | super(updateCustomerPaymentProfileController, self).__init__(apirequest)
834 | return
835 |
836 | def validaterequest(self):
837 | anetLogger.debug('performing custom validation.')
838 | #validate required fields
839 | #if (self._request.xyz == "null"):
840 | # raise ValueError('xyz is required')
841 | return
842 |
843 | def getrequesttype(self):
844 | '''Returns request type'''
845 | return 'updateCustomerPaymentProfileRequest'
846 |
847 | def getresponseclass(self):
848 | ''' Returns the response class '''
849 | return apicontractsv1.updateCustomerPaymentProfileResponse()
850 | class updateCustomerProfileController(apicontrollersbase.APIOperationBase):
851 |
852 | def __init__(self, apirequest):
853 | super(updateCustomerProfileController, self).__init__(apirequest)
854 | return
855 |
856 | def validaterequest(self):
857 | anetLogger.debug('performing custom validation.')
858 | #validate required fields
859 | #if (self._request.xyz == "null"):
860 | # raise ValueError('xyz is required')
861 | return
862 |
863 | def getrequesttype(self):
864 | '''Returns request type'''
865 | return 'updateCustomerProfileRequest'
866 |
867 | def getresponseclass(self):
868 | ''' Returns the response class '''
869 | return apicontractsv1.updateCustomerProfileResponse()
870 | class updateCustomerShippingAddressController(apicontrollersbase.APIOperationBase):
871 |
872 | def __init__(self, apirequest):
873 | super(updateCustomerShippingAddressController, self).__init__(apirequest)
874 | return
875 |
876 | def validaterequest(self):
877 | anetLogger.debug('performing custom validation.')
878 | #validate required fields
879 | #if (self._request.xyz == "null"):
880 | # raise ValueError('xyz is required')
881 | return
882 |
883 | def getrequesttype(self):
884 | '''Returns request type'''
885 | return 'updateCustomerShippingAddressRequest'
886 |
887 | def getresponseclass(self):
888 | ''' Returns the response class '''
889 | return apicontractsv1.updateCustomerShippingAddressResponse()
890 | class updateHeldTransactionController(apicontrollersbase.APIOperationBase):
891 |
892 | def __init__(self, apirequest):
893 | super(updateHeldTransactionController, self).__init__(apirequest)
894 | return
895 |
896 | def validaterequest(self):
897 | anetLogger.debug('performing custom validation.')
898 | #validate required fields
899 | #if (self._request.xyz == "null"):
900 | # raise ValueError('xyz is required')
901 | return
902 |
903 | def getrequesttype(self):
904 | '''Returns request type'''
905 | return 'updateHeldTransactionRequest'
906 |
907 | def getresponseclass(self):
908 | ''' Returns the response class '''
909 | return apicontractsv1.updateHeldTransactionResponse()
910 | class updateMerchantDetailsController(apicontrollersbase.APIOperationBase):
911 |
912 | def __init__(self, apirequest):
913 | super(updateMerchantDetailsController, self).__init__(apirequest)
914 | return
915 |
916 | def validaterequest(self):
917 | anetLogger.debug('performing custom validation.')
918 | #validate required fields
919 | #if (self._request.xyz == "null"):
920 | # raise ValueError('xyz is required')
921 | return
922 |
923 | def getrequesttype(self):
924 | '''Returns request type'''
925 | return 'updateMerchantDetailsRequest'
926 |
927 | def getresponseclass(self):
928 | ''' Returns the response class '''
929 | return apicontractsv1.updateMerchantDetailsResponse()
930 | class updateSplitTenderGroupController(apicontrollersbase.APIOperationBase):
931 |
932 | def __init__(self, apirequest):
933 | super(updateSplitTenderGroupController, self).__init__(apirequest)
934 | return
935 |
936 | def validaterequest(self):
937 | anetLogger.debug('performing custom validation.')
938 | #validate required fields
939 | #if (self._request.xyz == "null"):
940 | # raise ValueError('xyz is required')
941 | return
942 |
943 | def getrequesttype(self):
944 | '''Returns request type'''
945 | return 'updateSplitTenderGroupRequest'
946 |
947 | def getresponseclass(self):
948 | ''' Returns the response class '''
949 | return apicontractsv1.updateSplitTenderGroupResponse()
950 | class validateCustomerPaymentProfileController(apicontrollersbase.APIOperationBase):
951 |
952 | def __init__(self, apirequest):
953 | super(validateCustomerPaymentProfileController, self).__init__(apirequest)
954 | return
955 |
956 | def validaterequest(self):
957 | anetLogger.debug('performing custom validation.')
958 | #validate required fields
959 | #if (self._request.xyz == "null"):
960 | # raise ValueError('xyz is required')
961 | return
962 |
963 | def getrequesttype(self):
964 | '''Returns request type'''
965 | return 'validateCustomerPaymentProfileRequest'
966 |
967 | def getresponseclass(self):
968 | ''' Returns the response class '''
969 | return apicontractsv1.validateCustomerPaymentProfileResponse()
970 |
--------------------------------------------------------------------------------
/authorizenet/apicontrollersbase.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Nov 1, 2015
3 |
4 | @author: krgupta
5 | '''
6 | import abc
7 | import logging
8 | import pyxb
9 | import sys
10 | import xml.dom.minidom
11 | import requests
12 | from lxml import objectify
13 |
14 | from authorizenet.constants import constants
15 | from authorizenet import apicontractsv1
16 | from authorizenet import utility
17 | '''
18 | from authorizenet.apicontractsv1 import merchantAuthenticationType
19 | from authorizenet.apicontractsv1 import ANetApiRequest
20 | from authorizenet.apicontractsv1 import ANetApiResponse
21 | '''
22 |
23 | anetLogger = logging.getLogger(constants.defaultLoggerName)
24 | anetLogger.addHandler(logging.NullHandler())
25 | logging.getLogger('pyxb.binding.content').addHandler(logging.NullHandler())
26 |
27 | class APIOperationBaseInterface(object):
28 |
29 | __metaclass__ = abc.ABCMeta
30 |
31 | @abc.abstractmethod
32 | def execute(self):
33 | '''
34 | Makes a http-post call.
35 | Uses request xml and response class type to check that the response was of correct type
36 | '''
37 | pass
38 |
39 | @abc.abstractmethod
40 | def getresponseclass(self):
41 | ''' Returns the response class '''
42 | pass
43 |
44 | @abc.abstractmethod
45 | def getrequesttype(self):
46 | ''' Returns the request class '''
47 | pass
48 |
49 | @abc.abstractmethod
50 | def getresponse(self):
51 | ''' Returns the de-serialized response'''
52 | pass
53 |
54 | @abc.abstractmethod
55 | def getresultcode(self):
56 | ''' Returns the result code from the response '''
57 | pass
58 |
59 | @abc.abstractmethod
60 | def getmessagetype(self):
61 | ''' Returns the message type enum from the response '''
62 | pass
63 |
64 | @abc.abstractmethod
65 | def afterexecute(self):
66 | '''Returns the message received from binding after processing request'''
67 | pass
68 |
69 | @abc.abstractmethod
70 | def beforeexecute(self):
71 | '''TODO'''
72 | pass
73 |
74 | class APIOperationBase(APIOperationBaseInterface):
75 |
76 | __metaclass__ = abc.ABCMeta
77 | __initialized = False
78 | __merchantauthentication = "null"
79 | __environment = "null"
80 |
81 | @staticmethod
82 | def __classinitialized():
83 | return APIOperationBase.__initialized
84 |
85 | @abc.abstractmethod
86 | def validaterequest(self):
87 | return
88 |
89 | def validate(self):
90 | anetapirequest = self._getrequest()
91 | self.validateandsetmerchantauthentication()
92 | self.validaterequest()
93 |
94 | return
95 |
96 | def setClientId(self): #protected method
97 | self._request.clientId = constants.clientId
98 |
99 | def _getrequest(self): #protected method
100 | return self._request
101 |
102 | def buildrequest(self):
103 | anetLogger.debug('building request..')
104 |
105 | xmlRequest = self._request.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
106 | #remove namespaces that toxml() generates
107 | xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
108 | xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
109 |
110 | return xmlRequest
111 |
112 | def getprettyxmlrequest(self):
113 | xmlRequest = self.buildrequest()
114 | requestDom = xml.dom.minidom.parseString(xmlRequest)
115 | anetLogger.debug('Request is: %s' % requestDom.toprettyxml())
116 |
117 | return requestDom
118 |
119 | def execute(self):
120 |
121 | self.endpoint = APIOperationBase.__environment
122 |
123 | anetLogger.debug('Executing http post to url: %s', self.endpoint)
124 |
125 | self.beforeexecute()
126 |
127 | proxyDictionary = {'http' : utility.helper.getproperty("http_proxy"),
128 | 'https' : utility.helper.getproperty("https_proxy"),
129 | 'ftp' : utility.helper.getproperty("ftp")}
130 |
131 | #requests is http request
132 | try:
133 | self.setClientId()
134 | xmlRequest = self.buildrequest()
135 | self._httpResponse = requests.post(self.endpoint, data=xmlRequest, headers=constants.headers, proxies=proxyDictionary)
136 | except Exception as httpException:
137 | anetLogger.error( 'Error retrieving http response from: %s for request: %s', self.endpoint, self.getprettyxmlrequest())
138 | anetLogger.error( 'Exception: %s, %s', type(httpException), httpException.args )
139 |
140 |
141 | if self._httpResponse:
142 | self._httpResponse.encoding = constants.response_encoding
143 | self._httpResponse = self._httpResponse.text[3:] #strip BOM
144 | self.afterexecute()
145 | try:
146 | self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
147 | #objectify code
148 | xmlResponse= self._response.toxml(encoding=constants.xml_encoding, element_name=self.getrequesttype())
149 | xmlResponse = xmlResponse.replace(constants.nsNamespace1, b'')
150 | xmlResponse = xmlResponse.replace(constants.nsNamespace2, b'')
151 | self._mainObject = objectify.fromstring(xmlResponse)
152 |
153 | except Exception as objectifyexception:
154 | anetLogger.error( 'Create Document Exception: %s, %s', type(objectifyexception), objectifyexception.args )
155 | responseString = self._httpResponse
156 |
157 | # removing encoding attribute as objectify fails if it is present
158 | responseString = responseString.replace('encoding=\"utf-8\"', '')
159 | self._mainObject = objectify.fromstring(responseString)
160 | else:
161 | if type(self.getresponseclass()) != type(self._mainObject):
162 | if self._response.messages.resultCode == "Error":
163 | anetLogger.debug("Response error")
164 | domResponse = xml.dom.minidom.parseString(self._httpResponse.encode('utf-8'))
165 | anetLogger.debug('Received response: %s' % domResponse.toprettyxml(encoding='utf-8'))
166 | else:
167 | #Need to handle ErrorResponse
168 | anetLogger.debug('Error retrieving response for request: %s' % self._request)
169 | else:
170 | anetLogger.debug("Did not receive http response")
171 | return
172 |
173 | def getresponse(self):
174 | #return self._response #pyxb object
175 | return self._mainObject #objectify object
176 |
177 | def getresultcode(self):
178 | resultcode = 'null'
179 | if self._response:
180 | resultcode = self._response.resultCode
181 | return resultcode
182 |
183 | def getmessagetype(self):
184 | message = 'null'
185 | if self._response:
186 | message = self._response.message
187 | return message
188 |
189 | def afterexecute(self ):
190 | return
191 |
192 | def beforeexecute(self):
193 | return
194 |
195 | @staticmethod
196 | def getmerchantauthentication(self):
197 | return self.__merchantauthentication
198 |
199 | @staticmethod
200 | def setmerchantauthentication(merchantauthentication):
201 | APIOperationBase.__merchantauthentication = merchantauthentication
202 | return
203 |
204 | def validateandsetmerchantauthentication(self):
205 | anetapirequest = apicontractsv1.ANetApiRequest()
206 | if (anetapirequest.merchantAuthentication == "null"):
207 | if (self.getmerchantauthentication() != "null"):
208 | anetapirequest.merchantAuthentication = self.getmerchantauthentication()
209 | else:
210 | raise ValueError('Merchant Authentication can not be null')
211 | return
212 |
213 | @staticmethod
214 | def getenvironment(self):
215 | return APIOperationBase.__environment
216 |
217 |
218 | @staticmethod
219 | def setenvironment(userenvironment):
220 | APIOperationBase.__environment = userenvironment
221 | return
222 |
223 | def __init__(self, apiRequest):
224 | self._httpResponse = None
225 | self._request = None
226 | self._response = None
227 | #objectify variables
228 | self._responseXML = None
229 | self._reponseObject = None
230 | self._mainObject = None
231 |
232 | if None == apiRequest:
233 | raise ValueError('Input request cannot be null')
234 |
235 | self._request = apiRequest
236 | __merchantauthentication = apicontractsv1.merchantAuthenticationType()
237 | APIOperationBase.__environment = constants.SANDBOX
238 |
239 | APIOperationBase.setmerchantauthentication(__merchantauthentication)
240 | self.validate()
241 |
242 | return
243 |
--------------------------------------------------------------------------------
/authorizenet/constants.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Jun 8, 2015
3 |
4 | @author: egodolja
5 | '''
6 | import logging
7 |
8 | class constants(object):
9 | """All the constants are defined here
10 | Define all your constants instead of using magic numbers in the
11 | code.
12 | """
13 |
14 | '''Environments'''
15 | SANDBOX = 'https://apitest.authorize.net/xml/v1/request.api'
16 | PRODUCTION = 'https://api2.authorize.net/xml/v1/request.api'
17 |
18 | '''clientId'''
19 | version = '1.1.4'
20 | clientId = 'sdk-python-' + version
21 |
22 | '''xml encoding'''
23 | xml_encoding = 'utf-8'
24 |
25 | '''xml headers'''
26 | headers = {'Content-Type' : 'application/xml', 'version' : '1.0', 'encoding' : xml_encoding}
27 |
28 | """
29 | Following constants are defined and used in the ARBSubscriptionStatusController
30 | Used to remove the "Status" element, that has been deprecated
31 | However, since the server response still contains it, we have to remove it
32 | before de-serialization
33 | """
34 | '''ARBGetSubscriptionStatus tag'''
35 | StatusStart = ''
36 | StatusEnd = ''
37 |
38 | '''response encoding'''
39 | response_encoding = 'ISO-8859-1'
40 |
41 | '''note section of subscription status response'''
42 | note = ' note="Status with a capital \'S\' is obsolete."'
43 |
44 | '''ns namespace 1'''
45 | nsNamespace1 = b'ns1:'
46 |
47 | '''ns namespace 2'''
48 | nsNamespace2 = b':ns1'
49 |
50 | '''default log file name'''
51 | defaultLogFileName = "anetsdk.log"
52 |
53 | '''default logging level'''
54 | defaultLoggingLevel = logging.WARNING
55 | # defaultLoggingLevel = logging.DEBUG
56 |
57 | '''default log format'''
58 | defaultlogformat = '%(asctime)s %(message)s'
59 |
60 | propertiesloggingfilename = "loggingfilename"
61 |
62 | propertiesexecutionlogginglevel = "executionlogginglevel"
63 |
64 | defaultLoggerName = "authorizenet.sdk"
65 |
66 | '''eof'''
67 |
--------------------------------------------------------------------------------
/authorizenet/utility.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Nov 4, 2015
3 |
4 | @author: krgupta
5 | '''
6 |
7 | try:
8 | from ConfigParser import ConfigParser as SafeConfigParser
9 | from ConfigParser import NoSectionError
10 | except ImportError:
11 | from configparser import ConfigParser as SafeConfigParser
12 | from configparser import NoSectionError
13 |
14 | import os
15 | import sys
16 | import logging
17 | #from __future__ import print_function
18 |
19 | logger = logging.getLogger(__name__)
20 |
21 | class helper():
22 | __parser = "null"
23 | __propertyfilename = "null"
24 | __initialized = False
25 |
26 | @staticmethod
27 | def getparser():
28 | return helper.__parser
29 |
30 | @staticmethod
31 | def getpropertyfile():
32 | return helper.__propertyfilename
33 |
34 | @staticmethod
35 | def setpropertyfile(propertyfilename):
36 | if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False):
37 | helper.__propertyfilename = 'null'
38 | else:
39 | helper.__propertyfilename = propertyfilename
40 | return
41 |
42 | @staticmethod
43 | def __classinitialized():
44 | return helper.__initialized
45 |
46 | @staticmethod
47 | def getproperty(propertyname):
48 | stringvalue = "null"
49 |
50 | if ('null' != helper.getpropertyfile()):
51 | if (False == helper.__classinitialized()):
52 | if ('null' == helper.getparser()):
53 | try:
54 | helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
55 | except:
56 | logger.debug("Parser could not be initialized")
57 |
58 | if ('null' != helper.getparser()):
59 | try:
60 | helper.getparser().read(helper.__propertyfilename)
61 | helper.__initialized = True
62 | except:
63 | logger.debug("Unable to load the property file")
64 |
65 | if (True == helper.__classinitialized()):
66 | try:
67 | stringvalue = helper.getparser().get("properties", propertyname)
68 | except:
69 | logger.debug("'%s' not found\n" %propertyname )
70 |
71 | if ( "null" == stringvalue):
72 | stringvalue = os.getenv(propertyname)
73 | return stringvalue
--------------------------------------------------------------------------------
/generatingClasses.md:
--------------------------------------------------------------------------------
1 | Generating classes from xsd
2 | --------------------------------------
3 | - use the pyxbgen script from PyXB
4 | - run the following:
5 | python [path to pyxbgen] -u [link to xsd schema] -m [name of module to contain the classes]
6 | - refer to generateObjectsFromXSD.bat in the scripts folder to see how it's used
--------------------------------------------------------------------------------
/script/ControllerTemplate.pyt:
--------------------------------------------------------------------------------
1 |
2 | class APICONTROLLERNAMEController(apicontrollersbase.APIOperationBase):
3 |
4 | def __init__(self, apirequest):
5 | super(APICONTROLLERNAMEController, self).__init__(apirequest)
6 | return
7 |
8 | def validaterequest(self):
9 | anetLogger.debug('performing custom validation.')
10 | #validate required fields
11 | #if (self._request.xyz == "null"):
12 | # raise ValueError('xyz is required')
13 | return
14 |
15 | def getrequesttype(self):
16 | '''Returns request type'''
17 | return 'APICONTROLLERNAMERequest'
18 |
19 | def getresponseclass(self):
20 | ''' Returns the response class '''
21 | return apicontractsv1.APICONTROLLERNAMEResponse()
--------------------------------------------------------------------------------
/script/addany.pl:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/perl
2 |
3 | #author krgupta
4 |
5 | #Modifying XSD to add wildcard character
6 | #Adding paymentScheduleTypeInterval type to overcome pyxb's anonymous complex type issue
7 |
8 | $input_file = $ARGV[0];
9 | $intermediate_file = $ARGV[1];
10 | $output_file = $ARGV[2];
11 | $inp_cmd = "dos2unix $input_file\n";
12 |
13 | open(INP,"<$input_file") or die "Cannot open $input_file for reading:$!\n";
14 | open(OUP,">$intermediate_file") or die "Cannot open $intermediate_file for writing\n";
15 | $appd_line = "\\n";
16 | while(){
17 | $line=$_;
18 | if($line =~ /(\t+|\s+)(\<\/xs:sequence)(.*)/){
19 | $new_line = $1 . "\t" . $appd_line . $line;
20 | print OUP "$new_line";
21 | }
22 | else{
23 | print OUP "$line";
24 | }
25 | }
26 | close(OUP);
27 | close(INP);
28 | #print "$intermediate_file created from AnetApiSchema.xsd\n"; #uncomment for debugging
29 |
30 | # Using intermediate file as input
31 | open(INPUT,"<$intermediate_file") or die "Cannot open $intermediate_file for reading:$!\n";
32 | $inp_cmd = "dos2unix $intermediate_file\n";
33 |
34 | open(OUTPUT,">$output_file") or die "Cannot open $output_file for writing\n";
35 | $matchline = '';
36 |
37 | $i=0;$j=0;
38 | @lines1=();
39 | @lines2=();
40 | while(){
41 | $readline=$_;
42 | if($readline =~ /$matchline/){
43 | ($new_readline = $readline) =~ s/paymentScheduleType/paymentScheduleTypeInterval/g;
44 | $lines1[$i] = $new_readline;
45 | $i++;
46 | $lines2[$j] = $readline;
47 | $j++;
48 | $readline = ;
49 | while($readline !~ /;
52 | $j++;
53 | }
54 | $readline = ;
55 | while($readline !~ /<\/xs:complexType>/){
56 | ($lines1[$i] = $readline) =~ s/\t\t\t//;
57 | $i++;
58 | $readline = ;
59 | }
60 | ($lines1[$i] = $readline) =~ s/\t\t\t//;
61 | $lines1[$i+1] = "\t\n\n";
62 | $deleteline = ;
63 |
64 | $lines2[$j-1] =~ s/minOccurs=\"0\"/minOccurs=\"0\" type=\"anet:paymentScheduleTypeInterval\" \//g;
65 | print OUTPUT @lines1;
66 | print OUTPUT @lines2;
67 | }
68 | else{
69 | print OUTPUT "$readline";
70 | }
71 | }
72 | close(OUTPUT);
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/script/generateObjectsFromXSD.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | @REM Script to generate the python contract from XSD
4 | @REM Requires pyxb module to be installed and available in path
5 |
6 | @ECHO Running Pyxbgen on %DATE%-%TIME%
7 | where python > NUL
8 | IF "0"=="%ERRORLEVEL%" (
9 | @ECHO Found python
10 | ) ELSE (
11 | @ECHO Unable to find python. Make sure python is installed.
12 | EXIT /b 1
13 | )
14 | where pyxbgen > %TEMP%\pyxbgenpath.txt
15 | IF "0"=="%ERRORLEVEL%" (
16 | @ECHO Found pyxbgen
17 | ) ELSE (
18 | @ECHO Unable to find pyxbgen. Make sure pyxb package is installed.
19 | EXIT /b 1
20 | )
21 | SET XSDPATH=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
22 | SET CONTRACTSDIR=authorizenet
23 | SET CONTRACTSFILE=apicontractsv1
24 | SET /p PYXBGENPATH=< %TEMP%\pyxbgenpath.txt
25 | SET TEMPFILE=binding
26 |
27 | @ECHO Using pyxb from "%PYXBGENPATH%"
28 | IF EXIST "%TEMPFILE%.py" (
29 | DEL "%TEMPFILE%.py" > NUL
30 | )
31 |
32 | python "%PYXBGENPATH%" -u %XSDPATH% -m %TEMPFILE%
33 | IF "0"=="%ERRORLEVEL%" (
34 | IF EXIST "%CONTRACTSDIR%\%CONTRACTSFILE%.old" (
35 | DEL "%CONTRACTSDIR%\%CONTRACTSFILE%.old" > NUL
36 | )
37 | IF EXIST "%CONTRACTSDIR%\%CONTRACTSFILE%.py" (
38 | DEL "%CONTRACTSDIR%\%CONTRACTSFILE%.py" > NUL
39 | )
40 | MOVE "%TEMPFILE%.py" "%CONTRACTSDIR%\%CONTRACTSFILE%.py" > NUL
41 | @ECHO Bindings have been successfully generated from XSD in the file authorizenet\%CONTRACTSFILE%.py
42 | @ECHO Old contracts have been moved to .old
43 | ) ELSE (
44 | @ECHO Found python
45 | @ECHO Error generating bindings from XSD. Review the errors and rerun the script.
46 | EXIT /b 1
47 | )
48 |
49 | EXIT /b 0
50 |
--------------------------------------------------------------------------------
/script/generatecontrollersfromtemplate.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Script to generate controllers from the generated bindings file, and uses template
4 |
5 | currdir=`pwd`
6 |
7 | dt=`date '+%m/%d/%Y %H:%M:%S'`
8 | echo Starting ${dt}
9 |
10 | CDIR=`pwd`
11 | SRCDIR=${CDIR}
12 | GENFOLDER=authorizenet/apicontractsv1.py
13 | CONTROLLERFOLDER=controllerstemporary
14 |
15 | SRCLOG=${CDIR}/log/TestSources
16 | CNTLOG=${CDIR}/log/TestControllers
17 |
18 | if [ ! -e "${CDIR}/log" ]; then
19 | echo "Creating ${CDIR}/log"
20 | mkdir ${CDIR}/log
21 | else
22 | echo "Deleting existing ${CDIR}/log/*"
23 | rm -rf ${CDIR}/log/*.* > /dev/null
24 | fi
25 |
26 | echo Identifying Requests\/Responses to process from "${SRCDIR}/${GENFOLDER}"
27 | grep -i -e "request *=" -e "response *=" ${SRCDIR}/${GENFOLDER} | grep -v _AVS | cut -d= -f1 | egrep -v "^ |\." | sort -u > ${SRCLOG}0.log
28 |
29 | echo Getting Unique Request\/Responses
30 | grep -i -e "request *$" -e "response *$" ${SRCLOG}0.log > ${SRCLOG}1.log
31 |
32 | echo Identifying Object names
33 | perl -pi -w -e 's/Request *$|Response *$//g;' ${SRCLOG}1.log
34 | sort -u ${SRCLOG}1.log > ${SRCLOG}2.log
35 |
36 | # Create backup for later comparison
37 | cp ${SRCLOG}2.log ${SRCLOG}3.log
38 |
39 | echo Creating Final List of Request\/Response to generate code
40 | sort -u ${SRCLOG}2.log > ${SRCLOG}.log
41 |
42 | # make sure the temporary folder exists
43 | if [ ! -e "${CONTROLLERFOLDER}" ]; then
44 | mkdir ${CONTROLLERFOLDER}
45 | fi
46 | rm -rf ${CONTROLLERFOLDER}/*Controller.py
47 |
48 | echo Creating Controllers
49 | for cntrls in `cat ${SRCLOG}.log`
50 | do
51 | echo Generating Code for ${cntrls}Controller.py
52 | cp ${SRCDIR}/script/ControllerTemplate.pyt ${SRCDIR}/${CONTROLLERFOLDER}/${cntrls}Controller.py
53 | perl -pi -w -e "s/APICONTROLLERNAME/$cntrls/g;" ${SRCDIR}/${CONTROLLERFOLDER}/${cntrls}Controller.py
54 | done
55 |
56 | cat ${SRCDIR}/script/headertemplate.pyt ${SRCDIR}/${CONTROLLERFOLDER}/*.py > ${SRCDIR}/authorizenet/apicontrollers.new
57 |
58 | sed -i 's/getTransactionListForCustomerResponse/getTransactionListResponse/g' ${SRCDIR}/authorizenet/apicontrollers.new
59 |
60 | echo Controllers generated in module: ${SRCDIR}/authorizenet/apicontrollers.py
61 |
62 | echo Finished ${dt}
63 |
64 |
--------------------------------------------------------------------------------
/script/generateobjectsfromxsd.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Script to generate the python contract from XSD
4 | # Requires pyxb module to be installed and available in path
5 |
6 | dt=`date '+%m/%d/%Y %H:%M:%S'`
7 |
8 | AnetURL=https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd
9 | AnetURLPERL='https:\/\/apitest.authorize.net\/xml\/v1\/schema\/AnetApiSchema.xsd'
10 | LOCALXSDWITHANY=./script/AnetOut.xsd
11 | CONTRACTSDIR=authorizenet
12 | CONTRACTSFILE=apicontractsv1
13 | PYXBGENPATH=`which pyxbgen`
14 | TEMPFILE=binding
15 | TEMPDIRECTORY=./script/temp
16 |
17 | echo Starting pyxbgen on ${dt}
18 | which python > /dev/null
19 | if [ $? -eq 0 ]
20 | then
21 | echo Found python
22 | else
23 | echo Unable to find python. Make sure python is installed.
24 | exit 1
25 | fi
26 |
27 | which pyxbgen > /tmp/pyxbgenpath.txt
28 | if [ $? -eq 0 ]
29 | then
30 | echo Found pyxbgen
31 | else
32 | echo Unable to find pyxbgen. Make sure pyxb package is installed.
33 | exit 1
34 | fi
35 |
36 | which perl > /dev/null
37 | if [ $? -eq 0 ]
38 | then
39 | echo Found perl
40 | else
41 | echo Unable to find perl. Make sure perl is installed.
42 | exit 1
43 | fi
44 |
45 | # which wget > /dev/null
46 | # if [ $? -eq 0 ]
47 | # then
48 | # echo Found wget. Downloading AnetAPISchema file under Script directory.
49 | # wget -O ./script/AnetApiSchema.xsd ${AnetURL}
50 | # if [ $? -eq 0 ]
51 | # then
52 | # echo AnetAPISchema.xsd downloaded.
53 | # else
54 | # echo Unable to download AnetAPISchema.
55 | # exit 1
56 | # fi
57 | # else
58 | # echo Wget not found. Looking for Curl
59 | # which curl > /dev/null
60 | # if [ $? -eq 0 ]
61 | # then
62 | # echo Found curl. Downloading AnetAPISchema file under Script directory.
63 | # curl --noproxy '*' ${AnetURL} > ./script/AnetApiSchema.xsd
64 | # if [ $? -eq 0 ]
65 | # then
66 | # echo AnetAPISchema.xsd downloaded.
67 | # else
68 | # curl ${AnetURL} > ./script/AnetApiSchema.xsd
69 | # if [ $? -eq 0 ]
70 | # then
71 | # echo AnetAPISchema.xsd downloaded.
72 | # else
73 | # echo Unable to download AnetAPISchema.
74 | # exit 1
75 | # fi
76 | # fi
77 | # else
78 | # echo Unable to find wget and curl. Make sure either one is installed
79 | # exit 1
80 | # fi
81 | # fi
82 |
83 | echo Modifying XSD using perl to support backward compatibility
84 | echo Creating temporary directory
85 | mkdir -p "$TEMPDIRECTORY"
86 |
87 | # Added since UpdateCustomerProfile API was updated for SOAP APIs, thus requiring changes to the contract object UpdateCustomerProfileRequest.
88 | # Doesn't remove the type declaration for customerProfileInfoExType, but prevents it from being used anywhere else in the contract
89 | perl -pi.back -e 's/type=\"anet:customerProfileInfoExType\"/type=\"anet:customerProfileExType\"/g;' script/AnetApiSchema.xsd
90 |
91 | perl script/addany.pl script/AnetApiSchema.xsd ${TEMPDIRECTORY}/IntermediateAnetOut.xsd ${LOCALXSDWITHANY}
92 | if [ $? -eq 0 ]
93 | then
94 | : #echo AnetOut.xsd generated #Uncomment for debugging
95 | else
96 | echo Unable to generate AnetOut.xsd
97 | exit 1
98 | fi
99 |
100 | echo Deleting temporary directory
101 | rm -rf "$TEMPDIRECTORY"
102 |
103 | echo Using pyxb from "${PYXBGENPATH}"
104 | if [ -e "${TEMPFILE}.py" ]; then
105 | rm ${TEMPFILE}.py
106 | fi
107 |
108 | python "${PYXBGENPATH}" -u ${LOCALXSDWITHANY} -m ${TEMPFILE}
109 | if [ $? -eq 0 ]
110 | then
111 | if [ -e "${CONTRACTSDIR}/${CONTRACTSFILE}.old" ]
112 | then
113 | rm "${CONTRACTSDIR}/${CONTRACTSFILE}.old"
114 | fi
115 | if [ -e "${CONTRACTSDIR}/${CONTRACTSFILE}.py" ]
116 | then
117 | rm "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
118 | fi
119 | mv "${TEMPFILE}.py" "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
120 | echo Bindings have been successfully generated from XSD in the file "${CONTRACTSDIR}/${CONTRACTSFILE}.py"
121 | echo Old contracts have been moved to .old
122 | else
123 | echo Error generating bindings from XSD. Review the errors and rerun the script.
124 | exit 1
125 | fi
126 |
127 | perl -i -pe "s/.Location\(\'.*xsd\'/.Location\(\'$AnetURLPERL\'/g" ${CONTRACTSDIR}/${CONTRACTSFILE}.py
128 |
129 | exit 0
130 |
--------------------------------------------------------------------------------
/script/headertemplate.pyt:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Aug 28, 2024
3 |
4 | @author: gnongsie
5 | '''
6 | import logging
7 | from authorizenet.constants import constants
8 | from authorizenet import apicontractsv1
9 | from authorizenet import apicontrollersbase
10 |
11 | anetLogger = logging.getLogger(constants.defaultLoggerName)
12 |
--------------------------------------------------------------------------------
/script/masterupdate.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo Started at `date`
4 | echo This script will update the generated code
5 | echo
6 |
7 | currdir=`pwd`
8 | cmdlist="generateobjectsfromxsd.sh generatecontrollersfromtemplate.sh"
9 | for cmd in $cmdlist ; do
10 | echo Executing Script "$cmd"
11 | if [ ! -f $currdir/script/$cmd ];then
12 | echo "Script $currdir/script/$cmd not found"
13 | exit 1
14 | fi
15 | $currdir/script/$cmd
16 | ERRORCODE=$?
17 | if [ $ERRORCODE -ne 0 ];then
18 | echo "########################################################################"
19 | echo "Encountered error during execution of $cmd"
20 | echo "See logs or output above."
21 | echo "Exiting, Update ***NOT*** complete."
22 | exit $ERRORCODE
23 | fi
24 | done
25 | echo Exiting, Update completed successfully.
26 | echo Compile, run tests and commit to git-hub.
27 | echo Completed at `date`
28 |
29 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | """A setuptools based setup module.
2 | """
3 |
4 | # Always prefer setuptools over distutils
5 | from setuptools import setup
6 | from setuptools import find_packages
7 | # To use a consistent encoding
8 | from codecs import open
9 | from os import path
10 |
11 | here = path.abspath(path.dirname(__file__))
12 |
13 | with open(path.join(here, 'README.md'), encoding='utf-8') as f:
14 | long_description = f.read()
15 |
16 | setup(
17 | name='authorizenet',
18 |
19 | # Versions should comply with PEP440. For a discussion on single-sourcing
20 | # the version across setup.py and the project code, see
21 | # https://packaging.python.org/en/latest/single_source_version.html
22 | version='1.1.6',
23 |
24 | description='Authorize.Net Python SDK',
25 | long_description=long_description,
26 | long_description_content_type='text/markdown',
27 |
28 | # The project's main homepage.
29 | url='https://github.com/AuthorizeNet/sdk-python',
30 |
31 | # Author details
32 | author='Authorize.Net Developer',
33 | author_email='developer@authorize.net',
34 |
35 | # Choose your license
36 | license='proprietary',
37 |
38 | # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
39 | classifiers=[
40 | # How mature is this project? Common values are
41 | # 3 - Alpha
42 | # 4 - Beta
43 | # 5 - Production/Stable
44 | 'Development Status :: 4 - Beta',
45 |
46 | # Indicate who your project is intended for
47 | 'Intended Audience :: Developers',
48 | 'Topic :: Software Development :: Build Tools',
49 |
50 | # Pick your license as you wish (should match "license" above)
51 | 'License :: Other/Proprietary License',
52 |
53 | # Specify the Python versions you support here. In particular, ensure
54 | # that you indicate whether you support Python 2, Python 3 or both.
55 | 'Programming Language :: Python :: 3.6',
56 | 'Programming Language :: Python :: 3.7',
57 | 'Programming Language :: Python :: 3.8',
58 | 'Programming Language :: Python :: 3.9',
59 | 'Programming Language :: Python :: 3.10',
60 | 'Programming Language :: Python :: 3.11',
61 | 'Programming Language :: Python :: 3.12'
62 | ],
63 |
64 | # What does your project relate to?
65 | keywords='authorizenet, authorize.net, payment, ecommerce',
66 |
67 | # You can just specify the packages manually here if your project is
68 | # simple. Or you can use find_packages().
69 | packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
70 |
71 | # List run-time dependencies here. These will be installed by pip when
72 | # your project is installed. For an analysis of "install_requires" vs pip's
73 | # requirements files see:
74 | # https://packaging.python.org/en/latest/requirements.html
75 | install_requires=['PyXB-X', 'lxml==4.*', 'requests==2.*'],
76 | #install_requires=['nose'],
77 | #install_requires=['nosetests'],
78 | #install_requires=['mock'],
79 | #install_requires=['lxml'],
80 |
81 | tests_require = ['nose==1.*', 'mock==2.*'],
82 | # List additional groups of dependencies here (e.g. development
83 | # dependencies). You can install these using the following syntax,
84 | # for example:
85 | # $ pip install -e .[dev,test]
86 | extras_require={
87 | #'pip install mock'
88 | #'pip install lxml'
89 | #'dev': ['check-manifest'],
90 | #'test': ['coverage'],
91 | },
92 | environment_variables={
93 | #api.login.id : xyz
94 | #transaction.key : xyz
95 | #md5.hash.key : MD5_HASH_KEY
96 | },
97 |
98 | # If there are data files included in your packages that need to be
99 | # installed, specify them here. If using Python 2.6 or less, then these
100 | # have to be included in MANIFEST.in as well.
101 | #package_data={
102 | # 'sample': ['package_data.dat'],
103 | #},
104 |
105 | # Although 'package_data' is the preferred approach, in some case you may
106 | # need to place data files outside of your packages. See:
107 | # http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
108 | # In this case, 'data_file' will be installed into '/my_data'
109 | # data_files=[('my_data', ['data/data_file'])],
110 |
111 | # To provide executable scripts, use entry points in preference to the
112 | # "scripts" keyword. Entry points provide cross-platform support and allow
113 | # pip to create the appropriate form of executable for the target platform.
114 | #entry_points={
115 | # 'console_scripts': [
116 | # 'sample=sample:main',
117 | # ],
118 | #},
119 | )
120 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AuthorizeNet/sdk-python/2d7ee348c55216e2289662c8b45f134dc09ca816/tests/__init__.py
--------------------------------------------------------------------------------
/tests/apitestbase.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Jul 15, 2015
3 |
4 | @author: egodolja
5 | '''
6 |
7 | import unittest
8 | import datetime
9 | from decimal import *
10 | import random
11 | import test
12 |
13 | try:
14 | from ConfigParser import SafeConfigParser
15 | except ImportError:
16 | from configparser import SafeConfigParser
17 |
18 | from authorizenet import apicontractsv1, apicontrollersbase
19 | from authorizenet.utility import *
20 | #from authorizenet.apicontractsv1 import CTD_ANON
21 | from authorizenet import utility
22 |
23 | class ApiTestBase(unittest.TestCase):
24 |
25 | def setUp(self):
26 | utility.helper.setpropertyfile('anet_python_sdk_properties.ini')
27 |
28 | self.amount = str(round(random.random()*100, 2))
29 |
30 | self.merchantAuthentication = apicontractsv1.merchantAuthenticationType()
31 |
32 | self.merchantAuthentication.name = utility.helper.getproperty('api.login.id')
33 | if self.merchantAuthentication.name == None:
34 | self.merchantAuthentication.name = utility.helper.getproperty('api_login_id')
35 |
36 | self.merchantAuthentication.transactionKey = utility.helper.getproperty('transaction.key')
37 | if self.merchantAuthentication.transactionKey == None:
38 | self.merchantAuthentication.transactionKey = utility.helper.getproperty('transaction_key')
39 |
40 | self.ref_id = 'Sample'
41 |
42 | self.dateOne = datetime.date(2020, 8, 30)
43 | # self.interval = CTD_ANON()
44 | # self.interval.length = 1
45 | # self.interval.unit = 'months'
46 | self.paymentScheduleOne = apicontractsv1.paymentScheduleType()
47 | self.paymentScheduleOne.interval = apicontractsv1.paymentScheduleTypeInterval()
48 |
49 | self.paymentScheduleOne.interval.length = 1
50 | self.paymentScheduleOne.interval.unit = 'months'
51 |
52 | self.paymentScheduleOne.startDate = self.dateOne
53 | self.paymentScheduleOne.totalOccurrences = 12
54 | self.paymentScheduleOne.trialOccurrences = 1
55 |
56 | self.creditCardOne = apicontractsv1.creditCardType()
57 | self.creditCardOne.cardNumber = "4111111111111111"
58 | self.creditCardOne.expirationDate = "2020-12"
59 |
60 | self.payment = apicontractsv1.paymentType()
61 | self.payment.creditCard = self.creditCardOne
62 |
63 | self.customerOne = apicontractsv1.nameAndAddressType()
64 | self.customerOne.firstName = "John" + str(random.randint(0, 10000))
65 | self.customerOne.lastName = "Smith"
66 |
67 | self.customerData = apicontractsv1.customerDataType()
68 | self.customerData.id = "99999456654"
69 |
70 | self.subscriptionOne = apicontractsv1.ARBSubscriptionType()
71 | self.subscriptionOne.paymentSchedule = self.paymentScheduleOne
72 | self.subscriptionOne.amount = Decimal(str(round(random.random()*100, 2)))
73 | self.subscriptionOne.trialAmount = Decimal(str(round(random.random()*100, 2)))
74 | self.subscriptionOne.payment = self.payment
75 | self.subscriptionOne.billTo = self.customerOne
76 |
77 | self.order = apicontractsv1.orderType()
78 | self.order.invoiceNumber = "INV-21345"
79 | self.order.description = "Product description"
80 |
81 | self.billTo = apicontractsv1.customerAddressType()
82 | self.billTo.firstName = "Ellen"
83 | self.billTo.lastName = "Johnson"
84 | self.billTo.company = "Souveniropolis"
85 | self.billTo.address = "14 Main St"
86 | self.billTo.city = "Seattle"
87 | self.billTo.state = "WA"
88 | self.billTo.zip = "98122"
89 | self.billTo.country = "USA"
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/tests/testpyxb.py:
--------------------------------------------------------------------------------
1 | from authorizenet.constants import constants
2 | from decimal import *
3 | import logging
4 | import datetime
5 | import unittest
6 | from authorizenet import utility
7 | import xml.dom.minidom
8 | from authorizenet import apicontractsv1
9 |
10 | class test_CreateTransactionUnitTest(unittest.TestCase):
11 | def testPyxbDeserializationElementAtMid(self):
12 | self.__PyxbDeserialization(False)
13 |
14 | def testPyxbDeserializationElementAtLast(self):
15 | self.__PyxbDeserialization(True)
16 |
17 | def testPyxbDeserializationGoodXML(self):
18 | self.__PyxbDeserialization()
19 |
20 | def __PyxbDeserialization(self, lastElement = None):
21 | loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename)
22 | logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel)
23 |
24 | deserializedObject = None
25 | deserializedBadObject = None
26 |
27 | if (None == loggingfilename):
28 | loggingfilename = constants.defaultLogFileName
29 | if (None == logginglevel):
30 | logginglevel = constants.defaultLoggingLevel
31 |
32 | logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)
33 |
34 | merchantAuth = apicontractsv1.merchantAuthenticationType()
35 | merchantAuth.name = "unknown"
36 | merchantAuth.transactionKey = "anon"
37 |
38 | creditCard = apicontractsv1.creditCardType()
39 | creditCard.cardNumber = "4111111111111111"
40 | creditCard.expirationDate = "2020-12"
41 |
42 | payment = apicontractsv1.paymentType()
43 | payment.creditCard = creditCard
44 |
45 | transactionrequest = apicontractsv1.transactionRequestType()
46 | transactionrequest.transactionType = "authCaptureTransaction"
47 | transactionrequest.amount = Decimal( 6.99)
48 | transactionrequest.payment = payment
49 |
50 | createtransactionrequest = apicontractsv1.createTransactionRequest()
51 | createtransactionrequest.merchantAuthentication = merchantAuth
52 | createtransactionrequest.transactionRequest = transactionrequest
53 | createtransactionrequest.refId = "MerchantID-0001"
54 |
55 | logging.debug( "Request: %s " % datetime.datetime.now())
56 | logging.debug( " : %s " % createtransactionrequest )
57 |
58 | try:
59 | xmlRequest = createtransactionrequest.toxml(encoding=constants.xml_encoding, element_name='createTransactionRequest')
60 | xmlRequest = xmlRequest.replace(constants.nsNamespace1, '')
61 | xmlRequest = xmlRequest.replace(constants.nsNamespace2, '')
62 | ##print ("xmlRequest %s " %xmlRequest)
63 | logging.debug( "Xml Request: %s" % xmlRequest)
64 | except Exception as ex:
65 | logging.debug( "Xml Exception: %s" % ex)
66 |
67 | badXmlElement = None
68 |
69 | if (lastElement == None):
70 | try:
71 | deserializedObject = apicontractsv1.CreateFromDocument(xmlRequest)
72 | self.assertIsNotNone(deserializedObject, "Null deserializedObject ")
73 |
74 | if type(createtransactionrequest) == type(deserializedObject):
75 | ##print (" for good xml objects are equal")
76 | logging.debug( "createtransactionrequest object is equal to deserializedObject")
77 | else:
78 | ##print ("for good xml some error: objects are NOT equal" )
79 | logging.debug( "createtransactionrequest object is NOT equal to deserializedObject")
80 |
81 | deseriaziedObjectXmlRequest = deserializedObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
82 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace1, '')
83 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace2, '')
84 | logging.debug( "Good Dom Request: %s " % deseriaziedObjectXmlRequest )
85 | ##print ( "Good De-serialized XML: %s \n" % deseriaziedObjectXmlRequest )
86 | except Exception as ex:
87 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
88 | else:
89 | if (lastElement == False):
90 | try:
91 | splitString = ""
92 | lines = xmlRequest.split( splitString)
93 | badXmlElement = "BadElement"
94 | badXmlRequest = lines[0] + badXmlElement + splitString + lines[1]
95 | logging.debug( "Bad XmlRequest: %s" % badXmlRequest)
96 | ##print ("ElementInMidXML Request: %s \n" %badXmlRequest)
97 | except Exception as ex:
98 | ##print ("ElementInMidXML can not be inserted: %s, %s",type(ex), ex.args)
99 | logging.debug( "ElementInMidXML can not be inserted: %s, %s" ,type(ex), ex.args)
100 | if (lastElement == True):
101 | try:
102 | splitStringAtLast = ""
103 | lines = xmlRequest.split( splitStringAtLast)
104 | badXmlElementAtLast = "BadElementAtLast"
105 | badXmlRequest = lines[0] + badXmlElementAtLast + splitStringAtLast + lines[1]
106 | logging.debug( "Bad XmlRequest at Last: %s" % badXmlRequest)
107 | ##print ("ElementAtLastXML Request: %s \n" %badXmlRequest)
108 | except Exception as ex:
109 | ##print ("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args)
110 | logging.debug("ElementAtLastXML can not be inserted: %s, %s",type(ex), ex.args)
111 | try:
112 | deserializedBadObject = apicontractsv1.CreateFromDocument(badXmlRequest)
113 | self.assertIsNotNone(deserializedBadObject, "Null deserializedObject ")
114 | badDomXml = deserializedBadObject.toxml(encoding=constants.xml_encoding, element_name='deserializedBadObject')
115 | badDomXml = badDomXml.replace(constants.nsNamespace1, '')
116 | badDomXml = badDomXml.replace(constants.nsNamespace2, '')
117 | logging.debug( "Bad Dom Request: %s " % badDomXml )
118 | ##print ("Bad Dom De-serialized: %s \n" %badDomXml)
119 | except Exception as ex:
120 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
121 | ##print ("Exception while de-serializing bad dom: %s, %s",type(ex), ex.args)
122 |
123 | class test_CustomerProfile(unittest.TestCase):
124 | def testGetCustomerProfile(self):
125 | loggingfilename = utility.helper.getproperty(constants.propertiesloggingfilename)
126 | logginglevel = utility.helper.getproperty(constants.propertiesexecutionlogginglevel)
127 | logging.basicConfig(filename=loggingfilename, level=logginglevel, format=constants.defaultlogformat)
128 |
129 | merchantAuth = apicontractsv1.merchantAuthenticationType()
130 | merchantAuth.name = "unknown"
131 | merchantAuth.transactionKey = "anon"
132 |
133 | getCustomerProfileRequest = apicontractsv1.getCustomerProfileRequest()
134 | getCustomerProfileRequest.merchantAuthentication = merchantAuth
135 | getCustomerProfileRequest.customerProfileId = '36152115'
136 | getCustomerProfileRequest.abc = 'aaaaaaaa' #extra property not in getCustomerProfileRequest object
137 |
138 | logging.debug( "Request: %s " % datetime.datetime.now())
139 | logging.debug( " : %s " % getCustomerProfileRequest )
140 |
141 | try:
142 | '''serialzing object to XML '''
143 | xmlRequest = getCustomerProfileRequest.toxml(encoding=constants.xml_encoding, element_name='getCustomerProfileRequest')
144 | xmlRequest = xmlRequest.replace(constants.nsNamespace1, b'')
145 | xmlRequest = xmlRequest.replace(constants.nsNamespace2, b'')
146 | logging.debug( "Xml Request: %s" % xmlRequest)
147 | #print( "Xml Request: %s" % xmlRequest)
148 | except Exception as ex:
149 | logging.debug( "Xml Exception: %s" % ex)
150 |
151 | try:
152 | '''deserialize XML to object '''
153 | deserializedObject = None
154 | deserializedObject = apicontractsv1.CreateFromDocument(xmlRequest)
155 | self.assertIsNotNone(deserializedObject, "Null deserializedObject ")
156 |
157 | if type(getCustomerProfileRequest) == type(deserializedObject):
158 | #print ("objects are equal")
159 | logging.debug( "createtransactionrequest object is equal to deserializedObject")
160 | else:
161 | #print ("some error: objects are NOT equal" )
162 | logging.debug( "createtransactionrequest object is NOT equal to deserializedObject")
163 |
164 | deseriaziedObjectXmlRequest = deserializedObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
165 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace1, '')
166 | deseriaziedObjectXmlRequest = deseriaziedObjectXmlRequest.replace(constants.nsNamespace2, '')
167 | logging.debug( "Good Dom Request: %s " % deseriaziedObjectXmlRequest )
168 | #print( "Good Dom Request: %s " % deseriaziedObjectXmlRequest )
169 | #print("de-serialized successfully. GOOD CASE COMPLETE \n ")
170 | except Exception as ex:
171 |
172 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
173 |
174 | self.assertEqual(type(getCustomerProfileRequest), type(deserializedObject), "deseriaziedObject does not match original object")
175 |
176 | try:
177 | #print("starting with element in mid")
178 | newxml = 'unknownanon11Jan36152115'
179 |
180 | #print ("newxml: %s" %newxml)
181 | DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxml)
182 | self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ")
183 |
184 |
185 | DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
186 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '')
187 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '')
188 | logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest )
189 | #print( " DEseriaziedNEWObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest )
190 | #print("de-serialized successfully")
191 | #print("FINISHED element in mid \n ")
192 | except Exception as ex:
193 | #print("DEseriaziedNEWObjectXmlRequest is NOT DESerialized")
194 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
195 |
196 |
197 | try:
198 | #print("starting with element at last")
199 | newxmlATLAst = 'unknownanon3615211511Jan'
200 | #print ("newxmlATLAst: %s" %newxmlATLAst)
201 | DEserializedNEWObject = apicontractsv1.CreateFromDocument(newxmlATLAst)
202 | self.assertIsNotNone(DEserializedNEWObject, "Null deserializedObject ")
203 | DEseriaziedNEWObjectXmlRequest = DEserializedNEWObject.toxml(encoding=constants.xml_encoding, element_name='deserializedObject')
204 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace1, '')
205 | DEseriaziedNEWObjectXmlRequest = DEseriaziedNEWObjectXmlRequest.replace(constants.nsNamespace2, '')
206 | logging.debug( "Good Dom Request: %s " % DEseriaziedNEWObjectXmlRequest )
207 | #print( " DEseriaziedNEWATLASTObjectXmlRequest Request: %s " % DEseriaziedNEWObjectXmlRequest )
208 | #print("de-serialized successfully")
209 | #print("Finished element at last \n " )
210 | except Exception as ex:
211 | #print("DEseriaziedNEWATLASTObjectXmlRequest is NOT DESerialized")
212 | logging.error( 'Create Document Exception: %s, %s', type(ex), ex.args )
213 |
214 | if __name__ =='__main__':
215 | unittest.main()
216 |
--------------------------------------------------------------------------------
/tests/testsmock.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Jul 1, 2015
3 |
4 | @author: egodolja
5 |
6 | '''
7 | '''
8 | import unittest
9 |
10 | from mock import MagicMock
11 | from authorizenet import apicontractsv1
12 | #from controller.ARBCancelSubscriptionController import ARBCancelSubscriptionController
13 | from tests import apitestbase
14 | from authorizenet.apicontrollers import *
15 | import test
16 | '''
17 | '''
18 | class ARBCancelSubscriptionControllerTest(apitestbase.ApiTestBase):
19 |
20 | def test_ARBCancelSubscriptionController(self):
21 | cancelSubscriptionRequest = apicontractsv1.ARBCancelSubscriptionRequest()
22 | cancelSubscriptionRequest.merchantAuthentication = self.merchantAuthentication
23 | cancelSubscriptionRequest.refId = 'Sample'
24 | cancelSubscriptionRequest.subscriptionId = '2680891'
25 |
26 | ctrl = ARBCancelSubscriptionController()
27 |
28 | ctrl.execute = MagicMock(return_value=None)
29 |
30 | ctrl.execute(cancelSubscriptionRequest, apicontractsv1.ARBCancelSubscriptionResponse)
31 |
32 | ctrl.execute.assert_called_with(cancelSubscriptionRequest, apicontractsv1.ARBCancelSubscriptionResponse)
33 | ctrl.execute.assert_any_call(cancelSubscriptionRequest, apicontractsv1.ARBCancelSubscriptionResponse)
34 |
35 | '''
36 | '''
37 | class ARBCreateSubscriptionTest(apitestbase.ApiTestBase):
38 |
39 | def testCreateSubscriptionController(self):
40 | createSubscriptionRequest = apicontractsv1.ARBCreateSubscriptionRequest()
41 | createSubscriptionRequest.merchantAuthentication = self.merchantAuthentication
42 | createSubscriptionRequest.refId = 'Sample'
43 | createSubscriptionRequest.subscription = self.subscriptionOne
44 |
45 | ctrl = ARBCreateSubscriptionController()
46 |
47 | ctrl.execute = MagicMock(return_value=None)
48 |
49 | createRequest = ctrl.ARBCreateSubscriptionController(createSubscriptionRequest)
50 | ctrl.execute(createRequest, apicontractsv1.ARBCreateSubscriptionResponse)
51 |
52 | ctrl.execute.assert_called_with(createRequest, apicontractsv1.ARBCreateSubscriptionResponse )
53 | ctrl.execute.assert_any_call(createRequest, apicontractsv1.ARBCreateSubscriptionResponse)
54 |
55 | class ARBGetSubscriptionStatusTest(object):
56 |
57 |
58 | def testGetSubscriptionStatusController(self):
59 | getSubscriptionStatusRequest = apicontractsv1.ARBGetSubscriptionStatusRequest()
60 | getSubscriptionStatusRequest.merchantAuthentication = self.merchantAuthentication
61 | getSubscriptionStatusRequest.refId = 'Sample'
62 | getSubscriptionStatusRequest.subscriptionId = '2680891'
63 |
64 | ctrl = ARBGetSubscriptionStatusController()
65 |
66 | ctrl.execute = MagicMock(return_value=None)
67 |
68 | statusRequest = ctrl.ARBGetSubscriptionStatusController(getSubscriptionStatusRequest)
69 | ctrl.execute(statusRequest, apicontractsv1.ARBGetSubscriptionStatusResponse)
70 |
71 | ctrl.execute.assert_called_with(statusRequest, apicontractsv1.ARBGetSubscriptionStatusResponse)
72 | ctrl.execute.assert_any_call(statusRequest, apicontractsv1.ARBGetSubscriptionStatusResponse)
73 | '''
74 |
75 |
76 |
--------------------------------------------------------------------------------
/tests/testssample.py:
--------------------------------------------------------------------------------
1 | '''
2 | Created on Nov 16, 2015
3 |
4 | @author: krgupta
5 | '''
6 | from authorizenet import apicontractsv1
7 | from authorizenet.constants import constants
8 | from authorizenet.apicontractsv1 import CTD_ANON
9 | from authorizenet.apicontrollers import *
10 | from decimal import *
11 | import random
12 | import datetime
13 | import unittest
14 | import sys
15 | from tests import apitestbase
16 | from authorizenet import utility
17 |
18 | class test_ReadProperty(apitestbase.ApiTestBase):
19 | def testPropertyFromFile(self):
20 | login= utility.helper.getproperty("api.login.id")
21 | if (login) == None:
22 | login= utility.helper.getproperty("api_login_id")
23 | transactionkey = utility.helper.getproperty("transaction.key")
24 | if (transactionkey) == None:
25 | transactionkey= utility.helper.getproperty("transaction_key")
26 | self.assertIsNotNone(login)
27 | self.assertIsNotNone(transactionkey)
28 |
29 | class test_TransactionReportingUnitTest(apitestbase.ApiTestBase):
30 | def testchargeCreditCard(self):
31 | creditCard = apicontractsv1.creditCardType()
32 | creditCard.cardNumber = "4111111111111111"
33 | creditCard.expirationDate = "2020-12"
34 | payment = apicontractsv1.paymentType()
35 | payment.creditCard = creditCard
36 | transactionrequest = apicontractsv1.transactionRequestType()
37 | transactionrequest.transactionType = "authCaptureTransaction"
38 | transactionrequest.amount = Decimal(str(round(random.random()*100, 2)))
39 | transactionrequest.payment = payment
40 | createtransactionrequest = apicontractsv1.createTransactionRequest()
41 | createtransactionrequest.merchantAuthentication = self.merchantAuthentication
42 | createtransactionrequest.refId = "MerchantID-0001"
43 | createtransactionrequest.transactionRequest = transactionrequest
44 | createtransactioncontroller = createTransactionController(createtransactionrequest)
45 | createtransactioncontroller.execute()
46 | response = createtransactioncontroller.getresponse()
47 | if hasattr(response, 'messages') == True:
48 | if hasattr(response.messages, 'resultCode') == True:
49 | self.assertEquals('Ok', response.messages.resultCode)
50 | if hasattr(response, 'transactionResponse') == True:
51 | if hasattr(response.transactionResponse, 'transId') == True:
52 | createdTransactionId = response.transactionResponse.transId
53 | return str(createdTransactionId)
54 |
55 | def testgetTransactionDetails(self):
56 | gettransactiondetailsrequest = apicontractsv1.getTransactionDetailsRequest()
57 | gettransactiondetailsrequest.merchantAuthentication = self.merchantAuthentication
58 | transactionID = self.testchargeCreditCard()
59 | gettransactiondetailsrequest.transId = transactionID #update valid transaction id
60 | gettransactiondetailscontroller = getTransactionDetailsController(gettransactiondetailsrequest)
61 | gettransactiondetailscontroller.execute()
62 | response = gettransactiondetailscontroller.getresponse()
63 | if hasattr(response, 'messages') == True:
64 | if hasattr(response.messages, 'resultCode') == True:
65 | self.assertEquals('Ok', response.messages.resultCode)
66 |
67 | class test_RecurringBillingTest(apitestbase.ApiTestBase):
68 | def testCreateSubscription(self):
69 | createsubscriptionrequest = apicontractsv1.ARBCreateSubscriptionRequest()
70 | createsubscriptionrequest.merchantAuthentication = self.merchantAuthentication
71 | createsubscriptionrequest.refId = 'Sample'
72 | createsubscriptionrequest.subscription = self.subscriptionOne
73 | arbcreatesubscriptioncontroller = ARBCreateSubscriptionController(createsubscriptionrequest)
74 | arbcreatesubscriptioncontroller.execute()
75 | response = arbcreatesubscriptioncontroller.getresponse()
76 | if hasattr(response, 'messages') == True:
77 | if hasattr(response.messages, 'resultCode') == True:
78 | self.assertEquals('Ok', response.messages.resultCode)
79 | if hasattr(response, 'subscriptionId') == True:
80 | createdSubscriptionId = response.subscriptionId
81 | return str(createdSubscriptionId)
82 |
83 | def testGetSubscription(self):
84 | getSubscription = apicontractsv1.ARBGetSubscriptionRequest()
85 | getSubscription.merchantAuthentication = self.merchantAuthentication
86 | subscriptionID = self.testCreateSubscription()
87 | getSubscription.subscriptionId = subscriptionID #update valid subscription id
88 | getSubscriptionController = ARBGetSubscriptionController(getSubscription)
89 | getSubscriptionController.execute()
90 | response = getSubscriptionController.getresponse()
91 | if hasattr(response, 'messages') == True:
92 | if hasattr(response.messages, 'resultCode') == True:
93 | self.assertEquals('Ok', response.messages.resultCode)
94 |
95 | def testCancelSubscription(self):
96 | cancelsubscriptionrequest = apicontractsv1.ARBCancelSubscriptionRequest()
97 | cancelsubscriptionrequest.merchantAuthentication = self.merchantAuthentication
98 | cancelsubscriptionrequest.refId = 'Sample'
99 | subscriptionID = self.testCreateSubscription()
100 | cancelsubscriptionrequest.subscriptionId = subscriptionID #input valid subscriptionId
101 | cancelsubscriptioncontroller = ARBCancelSubscriptionController (cancelsubscriptionrequest)
102 | cancelsubscriptioncontroller.execute()
103 | response = cancelsubscriptioncontroller.getresponse()
104 | if hasattr(response, 'messages') == True:
105 | if hasattr(response.messages, 'resultCode') == True:
106 | self.assertEquals('Ok', response.messages.resultCode)
107 |
108 | class test_paymentTransactionUnitTest(apitestbase.ApiTestBase):
109 | def testAuthCaptureTransaction(self):
110 | transactionrequesttype = apicontractsv1.transactionRequestType()
111 | transactionrequesttype.transactionType = "authCaptureTransaction"
112 | transactionrequesttype.amount = self.amount
113 | transactionrequesttype.payment = self.payment
114 | transactionrequesttype.order = self.order
115 | transactionrequesttype.customer = self.customerData
116 | transactionrequesttype.billTo = self.billTo
117 | createtransactionrequest = apicontractsv1.createTransactionRequest()
118 | createtransactionrequest.merchantAuthentication = self.merchantAuthentication
119 | createtransactionrequest.refId = self.ref_id
120 | createtransactionrequest.transactionRequest = transactionrequesttype
121 | createtransactioncontroller = createTransactionController(createtransactionrequest)
122 | createtransactioncontroller.execute()
123 | response = createtransactioncontroller.getresponse()
124 | if hasattr(response, 'messages') == True:
125 | if hasattr(response.messages, 'resultCode') == True:
126 | self.assertEquals('Ok', response.messages.resultCode)
127 | if hasattr(response, 'transactionResponse') == True:
128 | self.assertIsNotNone(response.transactionResponse)
129 | if hasattr(response.transactionResponse, 'transId') == True:
130 | self.assertIsNotNone(response.transactionResponse.transId)
131 |
132 | def testAuthOnlyContinueTransaction(self):
133 | transactionrequesttype = apicontractsv1.transactionRequestType()
134 | transactionrequesttype.transactionType = "authCaptureTransaction"
135 | transactionrequesttype.amount = self.amount
136 | transactionrequesttype.payment = self.payment
137 | transactionrequesttype.order = self.order
138 | transactionrequesttype.customer = self.customerData
139 | transactionrequesttype.billTo = self.billTo
140 | createtransactionrequest = apicontractsv1.createTransactionRequest()
141 | createtransactionrequest.merchantAuthentication = self.merchantAuthentication
142 | createtransactionrequest.refId = self.ref_id
143 | createtransactionrequest.transactionRequest = transactionrequesttype
144 | createtransactioncontroller = createTransactionController(createtransactionrequest)
145 | createtransactioncontroller.execute()
146 | response = createtransactioncontroller.getresponse()
147 | if hasattr(response, 'messages') == True:
148 | if hasattr(response.messages, 'resultCode') == True:
149 | self.assertEquals('Ok', response.messages.resultCode)
150 | if hasattr(response, 'transactionResponse') == True:
151 | self.assertIsNotNone(response.transactionResponse)
152 | if hasattr(response.transactionResponse, 'transId') == True:
153 | self.assertIsNotNone(response.transactionResponse.transId)
154 |
155 | class test_CustomerProfile(apitestbase.ApiTestBase):
156 | def testCreateCustomerProfile(self):
157 | createdCustomerProfileID = None
158 | createCustomerProfile = apicontractsv1.createCustomerProfileRequest()
159 | createCustomerProfile.merchantAuthentication = self.merchantAuthentication
160 | randomInt = random.randint(0, 10000)
161 | createCustomerProfile.profile = apicontractsv1.customerProfileType()
162 | createCustomerProfile.profile.merchantCustomerId = 'jdoe%s' % randomInt
163 | createCustomerProfile.profile.description = 'John Doe%s' % randomInt
164 | createCustomerProfile.profile.email = 'jdoe%s@mail.com' % randomInt
165 | controller = createCustomerProfileController(createCustomerProfile)
166 | controller.execute()
167 | response = controller.getresponse()
168 | if hasattr(response, 'messages') == True:
169 | if hasattr(response.messages, 'resultCode') == True:
170 | self.assertEquals('Ok', response.messages.resultCode)
171 | if hasattr(response, 'customerProfileId') == True:
172 | createdCustomerProfileID = response.customerProfileId
173 | return str(createdCustomerProfileID)
174 |
175 | def testGetCustomerProfile(self):
176 | getCustomerProfile = apicontractsv1.getCustomerProfileRequest()
177 | getCustomerProfile.merchantAuthentication = self.merchantAuthentication
178 |
179 | CustomerProfileID = self.testCreateCustomerProfile()
180 | getCustomerProfile.customerProfileId = CustomerProfileID
181 | controller = getCustomerProfileController(getCustomerProfile)
182 | controller.execute()
183 | response = controller.getresponse()
184 | self.assertEquals('Ok', response.messages.resultCode)
185 | if hasattr(response, 'messages') == True:
186 | if hasattr(response.messages, 'resultCode') == True:
187 | self.assertEquals('Ok', response.messages.resultCode)
188 |
189 | def testCreateAndGetCustomerShippingAddress(self):
190 | officeAddress = apicontractsv1.customerAddressType();
191 | officeAddress.firstName = "John"
192 | officeAddress.lastName = "Doe"
193 | officeAddress.address = "123 Main St."
194 | officeAddress.city = "Bellevue"
195 | officeAddress.state = "WA"
196 | officeAddress.zip = "98004"
197 | officeAddress.country = "USA"
198 | officeAddress.phoneNumber = "000-000-0000"
199 | shippingAddressRequest = apicontractsv1.createCustomerShippingAddressRequest()
200 | shippingAddressRequest.address = officeAddress
201 | CustomerProfileID = self.testCreateCustomerProfile()
202 | shippingAddressRequest.customerProfileId = CustomerProfileID
203 | shippingAddressRequest.merchantAuthentication = self.merchantAuthentication
204 | controller = createCustomerShippingAddressController(shippingAddressRequest)
205 | controller.execute()
206 | response = controller.getresponse()
207 | if hasattr(response, 'messages') == True:
208 | if hasattr(response.messages, 'resultCode') == True:
209 | self.assertEquals('Ok', response.messages.resultCode)
210 | if hasattr(response, 'customerAddressId') == True:
211 | createdShippingAddressId = str(response.customerAddressId)
212 | #return str(createdShippingAddressId)
213 |
214 | #def testGetCustomerShippingAddress(self):
215 | getShippingAddress = apicontractsv1.getCustomerShippingAddressRequest()
216 | getShippingAddress.merchantAuthentication = self.merchantAuthentication
217 |
218 |
219 | getShippingAddress.customerProfileId = CustomerProfileID
220 | getShippingAddress.customerAddressId = createdShippingAddressId
221 |
222 | getShippingAddressController = getCustomerShippingAddressController(getShippingAddress)
223 | getShippingAddressController.execute()
224 | response = getShippingAddressController.getresponse()
225 | if hasattr(response, 'messages') == True:
226 | if hasattr(response.messages, 'resultCode') == True:
227 | self.assertEquals('Ok', response.messages.resultCode)
228 |
229 | '''
230 | class test_ProductionURL(apitestbase.ApiTestBase):
231 | #Tests will run only with production credentials
232 |
233 |
234 | def testGetSettledBatchList(self):
235 | settledBatchListRequest = apicontractsv1.getSettledBatchListRequest()
236 | settledBatchListRequest.merchantAuthentication = self.merchantAuthentication
237 | settledBatchListController = getSettledBatchListController(settledBatchListRequest)
238 | customEndpoint = constants.PRODUCTION
239 | apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
240 | settledBatchListController.execute()
241 | response = settledBatchListController.getresponse()
242 | self.assertEquals('Ok', response.messages.resultCode)
243 |
244 | def testGetListofSubscriptions(self):
245 | sorting = apicontractsv1.ARBGetSubscriptionListSorting()
246 | sorting.orderBy = apicontractsv1.ARBGetSubscriptionListOrderFieldEnum.id
247 | sorting.orderDescending = "false"
248 | paging = apicontractsv1.Paging()
249 | paging.limit = 1000
250 | paging.offset = 1
251 | GetListofSubscriptionRequest = apicontractsv1.ARBGetSubscriptionListRequest()
252 | GetListofSubscriptionRequest.merchantAuthentication = self.merchantAuthentication
253 | GetListofSubscriptionRequest.refId = "Sample"
254 | GetListofSubscriptionRequest.searchType = apicontractsv1.ARBGetSubscriptionListSearchTypeEnum.subscriptionInactive
255 | GetListofSubscriptionRequest.sorting = sorting
256 | GetListofSubscriptionRequest.paging = paging
257 | arbgetsubscriptionlistcontroller = ARBGetSubscriptionListController(GetListofSubscriptionRequest)
258 | customEndpoint = constants.PRODUCTION
259 | apicontrollersbase.APIOperationBase.setenvironment(customEndpoint)
260 | arbgetsubscriptionlistcontroller.execute()
261 | response = arbgetsubscriptionlistcontroller.getresponse()
262 | self.assertEquals('Ok', response.messages.resultCode)
263 | '''
264 | if __name__ =='__main__':
265 | unittest.main()
266 |
--------------------------------------------------------------------------------