IntroductionThere are a handful of Python implementations of the Authorize.net AIM
API out there already, but we wrote our own. Why? Well honestly when
we
wrote it we didn't find any of the ones that already exist. Maybe we're
just really bad at using Google, but it's the truth. Regardless, we like
it because it's under 300 lines of code and extremely easy to use and
modify.
InstallingYou have a couple options for getting the code:
Usage:Initializing the processorimport pyauthorize Transaction Typesauth_and_captureUse this method to do a standard capture of funds.
Required fields: card_num, exp_date, amount
Optional fields: is_avs_required (True/False), is_ccv_required (True/False), invoice_number, first_name, last_name, customer_id, description
If is_avs_required is True: address and zip are also required.
If is_ccv_required is True: card_code is also required.
pp.card_num = '4111111111111111' auth_onlyUse this method to get an authorization but not actually capture funds.
Required fields: card_num, exp_date, amount
Optional fields: is_avs_required (True/False), is_ccv_required (True/False), invoice_number, first_name, last_name, customer_id, description
If is_avs_required is True: address and zip are also required.
If is_ccv_required is True: card_code is also required.
pp.card_num = '4111111111111111' prior_auth_captureUse this method to capture funds that were authorized in a previous auth_only transaction.
Required fields: transaction
Optional fields: amount (only if you wish to capture less than the original auth was for.)
pp.transaction = '123123123' voidUse this method to void a capture that hasn't settled yet.
Required fields: transaction
pp.transaction = '123123123' creditUse this method to process a credit (refund) on a previously settled transaction. The total amount of all refunds against a single transaction number cannot exceed the amount originally charged.
Required fields: transaction, card_num (full or last four digits), amount.
pp.transaction = '123123123' process_void_or_creditAttempts to process a void first, if the void fails it will process a credit. This is useful when you don't know if a transaction is settled yet but you wish to refund the full amount.
Required fields: transaction, card_num (full or last four digits), amount.
Returns: A two part tuple. The first value is a boolean indicating if the transaction was successful or not. The second field will be either 'Credit' or 'Void'.
pp.transaction = '123123123' Adding extra fieldsThe client includes what we encountered as the most common fields as well as field validation for those values based on the Authorize.net AIM integration guide. You are free, however, to include any of the fields specified in the manual even if the field is not included in PyAuthorize. Just add those additional values to the PaymentProcessor.transaction_data dictionary. If you are using these other fields often, please log a feature request with us and we will add the validation, or you are free to add it yourself and contribute your diff to the project.
pp.card_num = '4111111111111111' TestingA note on running the tests that are included: In order to run all the tests, you will have to edit lines 44 and 45 of pyauthorize_test.py and add your Authorize.net login details. Without setting these values, some tests will fail. ContributingWe welcome your contributions to the project, in whatever capacity you are able to help. Whether it is through feature requests, bug reports, code contributions, or simply some constructive feedback, we are glad to hear from you. See below for information on how to contact us.
Contacting UsThe best way to contact us is by sending us an email at open-source@analytemedia.com. We promise to get back to you in a jiffy! You can also email your patches to us there.
|
