Python/Django:应该使用哪个authorize.net库?

2024-05-23 14:27:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要授权.net集成订阅付款,可能使用CIM。要求很简单-每月定期付款,有几个不同的价格点。客户信用卡信息将存储在authorize.net中。

有相当多的库和代码片段,我正在寻找关于哪些工作最好的建议。

  • 萨奇莫似乎比我需要的要多,而且看起来很复杂。
  • Django-Bursar似乎是我需要的,但它被列为alpha。
  • adroll/authorize library看起来也不错。
  • CIM XML API看起来不太糟糕,我可以直接与它们连接。

还有很多其他的代码片段。

考虑到我的简单要求,现在最好的选择是什么?


Tags: django代码alpha信息net客户library价格
3条回答

总有付款方式:https://github.com/abunsen/Paython

目前支持5+支付网关:

  1. 授权.net
  2. 第一个数据/链接点
  3. 创新网关(来自intuit)
  4. 插头式
  5. 条纹

下面是一个例子:

from paython import CreditCard, AuthorizeNet

先办一张卡:

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

检查其是否有效:

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

设置要收费的客户数据,并非所有字段都是必需的:

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')

针对网关授权,选项包括调试输出或测试凭据:

  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)

现在你可以解决:

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

编辑:https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py 看起来不错,还没试过呢。

编辑:[对于下一个使用authorize.net的项目,我将仔细查看:http://github.com/zen4ever/django-authorizenet它看起来非常漂亮。不过,我认为它不支持经常性付款。]

在过去,我做过一些一次性的实现。

对于发送到AIM支付网关的简单邮件,您可以使用以下内容:

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

要授权,您可以执行以下操作:

            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])

然后,我们可以捕获:

        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]

有更多的选项,请求的方式,在解析的响应中的细微差别。。。我假设b/cAinAIM代表所有authorize.net选项都可用。

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

我知道你的问题是什么是最好的。。好吧,实现您自己的一点特殊请求和响应来满足您的特定需求可能是最简单的,而不是试图在api之上遍历api。

长话短说,现有的解决方案都不能满足我的需要。它们要么未维护、未注释、未测试,要么缺少保存的卡。因此,我当然构建了自己的解决方案并将其开源:

授权酱:https://github.com/jeffschenck/authorizesauce

它处理基本事务(AIM API)、保存的卡(CIM API)和重复付款(ARB API)。它有完整的文档和完整的测试套件。

我想原来的海报早就开始了,但如果它能帮助其他人避免一些支付过程中的痛苦,我会欣喜若狂。

相关问题 更多 >