Skip to content
abunsen edited this page Nov 12, 2011 · 4 revisions

Importing what you need

    from paython import CreditCard, AuthorizeNet

Setting up a credit card

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

Checking to see if it's valid

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

Setting 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='[email protected]', 
        ip='127.0.0.1')

Trying to 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)

Keep in mind, if you authorize, you need to settle

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

OR, you can capture instead

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

This is the standard paython response.

    gateway_response = {
        'response_text': 'This transaction has been approved.',
        'cvv_response': 'P',
        'response_code': '1',
        'trans_type': 'auth_only',
        'amount': '0.05',
        'avs_response': 'Y',
        'response_reason_code': '1',
        'trans_id': '2156729380',
        'alt_trans_id': '',
        'auth_code': 'IL2UW7',
        'approved': True,
        'response_time': '0.55'
    }
Clone this wiki locally