<p>编辑:<a href="https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py" rel="nofollow noreferrer">https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py</a>
看起来不错,还没试过呢。</p>
<p>编辑:[对于下一个使用authorize.net的项目,我将仔细查看:<a href="http://github.com/zen4ever/django-authorizenet" rel="nofollow noreferrer">http://github.com/zen4ever/django-authorizenet</a>它看起来非常漂亮。不过,我认为它不支持经常性付款。]</p>
<p>在过去,我做过一些一次性的实现。</p>
<p>对于发送到AIM支付网关的简单邮件,您可以使用以下内容:</p>
<pre><code>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
</code></pre>
<p>要授权,您可以执行以下操作:</p>
<pre><code> 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])
</code></pre>
<p>然后,我们可以捕获:</p>
<pre><code> 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]
</code></pre>
<p>有更多的选项,请求的方式,在解析的响应中的细微差别。。。我假设b/c<code>A</code>in<code>AIM</code>代表所有authorize.net选项都可用。</p>
<p><a href="http://developer.authorize.net/guides/AIM/" rel="nofollow noreferrer">http://developer.authorize.net/guides/AIM/</a></p>
<p>我知道你的问题是什么是最好的。。好吧,实现您自己的一点特殊请求和响应来满足您的特定需求可能是最简单的,而不是试图在api之上遍历api。</p>