views:

920

answers:

1

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 like 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?

+2  A: 

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.

skyl
Oh, if any finds flaw, has suggestion, comment, I would love to hear. Maybe we can build a nice flexible and featureful but still lightweight way to do more.
skyl
Agreed. A light-weight implementation would be great. I just found zc authorizedotnet in PyPi. Have you any experience with this?
Noah Watkins
I actually have an upcoming project for which I'm going to have a go with:http://github.com/zen4ever/django-authorizenet
skyl