" dynamic="no"} Language Libraries | Developer Documentation | 2Checkout
Language

2Checkout Documentation

Authorize

This method provides a binding to the authorization call available through our Payment API.

Method

authorize

Use to charge a buyer and create a new 2Checkout sale using a secure token provided by 2co.js.

Arguments

Returns

Returns an Authorization object.

Example Usage:

twocheckout.Api.auth_credentials({
    'private_key': '8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3',
    'seller_id': '1817037',
    'mode': 'production'
})

params = {
    'merchantOrderId': '123',
    'token': 'ODAxZjUzMDEtOWU0MC00NzA3LWFmMDctYmY1NTQ3MDhmZDFh',
    'currency': 'USD',
    'total': '1.00',
    'billingAddr': {
        'name': 'Testing Tester',
        'addrLine1': '123 Test St',
        'city': 'Columbus',
        'state': 'OH',
        'zipCode': '43123',
        'country': 'USA',
        'email': 'cchristenson@2co.com',
        'phoneNumber': '555-555-5555'
    }
}

try:
    result = twocheckout.Charge.authorize(params)
    print result.responseCode
except TwocheckoutError as error:
    print error.msg

Example Response:

{
    'lineItems': [
        {
            'tangible': 'N',
            'name': '123',
            'price': '1.00',
            'description': '',
            'recurrence': None,
            'duration': None,
            'startupFee': None,
            'productId': '',
            'type': 'product',
            'options': [
                
            ],
            'quantity': '1'
        }
    ],
    'responseMsg': 'Successfully authorized the provided creditcard',
    'recurrentInstallmentId': None,
    'shippingAddr': {
        'city': None,
        'phoneExtension': None,
        'country': None,
        'addrLine2': None,
        'zipCode': None,
        'addrLine1': None,
        'state': None,
        'phoneNumber': None,
        'email': None,
        'name': None
    },
    'orderNumber': '205180784763',
    'currencyCode': 'USD',
    'merchantOrderId': '123',
    'errors': None,
    'responseCode': 'APPROVED',
    'transactionId': '205180784772',
    'total': '1.00',
    'type': 'AuthResponse',
    'billingAddr': {
        'city': 'Columbus',
        'phoneExtension': None,
        'country': 'USA',
        'addrLine2': None,
        'zipCode': '43123',
        'addrLine1': '123 Test St',
        'state': 'OH',
        'phoneNumber': '555-555-5555',
        'email': 'cchristenson@2co.com',
        'name': 'Testing Tester'
    }
}

To test using the sandbox, pass the `mode` option with a value of `sandbox` to the `twocheckout.Charge.authorize` method along with your credentials.