开发者

Python/Django: Which authorize.net library should I use?

I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .

There are quite a few libraries and code snippets around, I'm looking for recommendations as to which work best.

  • Satchmo seems more than I need, and it looks lik开发者_JS百科e it's complex.
  • Django-Bursar seems like what I need, but it's listed as alpha.
  • The adroll/authorize library also looks pretty good.
  • The CIM XML APIs don't look too bad, I could connect directly with them.

And there are quite a few other code snippets.

What's the best choice right now, given my fairly simple requirements?


Long story short, none of the existing solutions met my needs. They were either unmaintained, uncommented, untested, or lacked saved cards. So of course I built my own solution and open-sourced it:

AuthorizeSauce: https://github.com/jeffschenck/authorizesauce

It handles basic transactions (the AIM API), saved cards (the CIM API), and recurring payments (the ARB API). It is fully documented and has a full test suite.

I expect the original poster has long since moved on, but if it can help anyone else avoid some of the pain of payment processing, I'd be overjoyed.


Edit: https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py looks pretty nice, haven't tried it yet.

Edit: [For the next project I have that uses authorize.net, I'm going to take a close look at: http://github.com/zen4ever/django-authorizenet It looks pretty nice. I don't think that it has support for recurring payments though.]

In the past I have made little one-off implementations.

For simple post to the AIM payment gateway, you can use something like this:

URL = 'https://test.authorize.net/gateway/transact.dll'
API = {'x_login':'XXX',
'x_tran_key':'XXX', 'x_method':'CC', 'x_type':'AUTH_ONLY',
'x_delim_data':'TRUE', 'x_duplicate_window':'10', 'x_delim_char':'|',
'x_relay_response':'FALSE', 'x_version':'3.1'}

def call_auth(amount, card_num, exp_date, card_code, zip_code, request_ip=None):
    '''Call authorize.net and get a result dict back'''
    import urllib2, urllib
    payment_post = API
    payment_post['x_amount'] = amount
    payment_post['x_card_num'] = card_num
    payment_post['x_exp_date'] = exp_date
    payment_post['x_card_code'] = card_code
    payment_post['x_zip'] = zip_code
    payment_request = urllib2.Request(URL, urllib.urlencode(payment_post))
    r = urllib2.urlopen(payment_request).read()
    return r

def call_capture(trans_id): # r.split('|')[6] we get back from the first call, trans_id
    capture_post = API
    capture_post['x_type'] = 'PRIOR_AUTH_CAPTURE'
    capture_post['x_trans_id'] = trans_id
    capture_request = urllib2.Request(URL, urllib.urlencode(capture_post))
    r = urllib2.urlopen(capture_request).read()
    return r

To authorize, you do something like:

            r = authorize.call_auth(
                unicode(decimal_total),
                request.POST.get('card_num'),
                request.POST.get('exp_date'),
                request.POST.get('card_code'),
                request.POST.get('zip_code') if request.POST.get('zip_code') else address.zip_code,
            )
            if r.split('|')[0] == '1':
              # it's good, we have authorized the card...
            else:
              error = "%s Please try again." % (r.split('|')[3])

then, we can capture:

        r = authorize.call_capture(trans_id) # r.split('|')[6] in first response..
        if r.split('|')[0] == '1':
            # we captured it.
        else:
            error = r.split('|')[3]

There are more options, ways to request, nuances in the response to parse... I assume b/c A in AIM stands for advanced that all of the authorize.net options are available.

http://developer.authorize.net/guides/AIM/

I know that your question is what lib is best .. well, it might be easiest just to implement your own little bit of ad-hoc request and response for your specific requirements rather than trying to trove through an api on top of an api.


There is always Paython: https://github.com/abunsen/Paython

Currently supports 5+ payment gateways:

  1. Authorize.net
  2. First Data/Linkpoint
  3. Innovative Gateway (from intuit)
  4. PlugnPay
  5. Stripe

Here is an example:

from paython import CreditCard, AuthorizeNet

set up a card first:

credit_card = CreditCard(
      number = '4111111111111111',
      exp_mo = '02',
      exp_yr = '2012',
      first_name = 'John',
      last_name = 'Doe',
      cvv = '911',
      strict = False
  )

check if its valid:

if not credit_card.is_valid(): return 'houston, we have a problem' # checks card number + expiration date

Set up customer data to charge, not all fields are required:

customer_data = dict(
      address='123 Main St', 
      address2='Apt 1', 
      city='Pleasantville', 
      state='IA', 
      zipcode='54321', 
      country='US', 
      phone='654-369-9589', 
      email='john@localwoodshop.com', 
      ip='127.0.0.1')

authorize against gateway, options include debug output or test credentials:

  api = AuthorizeNet(username='test', password='testpassword', debug=True, test=True)
  gateway_response = api.auth(amount='0.05', credit_card=credit_card, billing_info=customer_data, shipping_info=None)

now you can settle:

  api = AuthorizeNet(username='test', password='testpassword', debug=True, test=True)
  gateway_response = api.settle(amount='0.05', trans_id='2156729380')


I recently wrote this API for Python and Authorize.net after failing to find one that supported all of Authorize.net's functionality.

https://github.com/vcatalano/py-authorize


For what it's worth we ended up using the adroll authorize library. Both Paython and django-authorizenet look interesting, will be checking those out.


I realize this is a bit late, but hopefully it helps others.

I recently came across Py-Authorize which has some great documentation, compared to the other packages available. You can install it via:

pip install Py-Authorize

It seems to install a dependency (colondar) which when installed via pip is outdated so you can get the latest (at the time of this writing) by doing the following:

pip install git+git://github.com/Pylons/colander.git@1.0b1

The docs are here: http://vcatalano.github.io/py-authorize/index.html

Works great in my experience, however for the project I am using it on I only needed AuthCapture and not ARB or anything...give it a try. Best package I've found so far.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜