" 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

Authorization Object.

Example Usage:

var tco = new Twocheckout({
    sellerId: "1817037",
    privateKey: "3508079E-5383-44D4-BF69-DC619C0D9811",
    sandbox: false
});

authorize = {
    "merchantOrderId": "123",
    "token": "MWQyYTI0ZmUtNjhiOS00NTIxLTgwY2MtODc3MWRlNmZjY2Jh",
    "currency": "USD",
    "total": "10.00",
    "billingAddr": {
        "name": "Testing Tester",
        "addrLine1": "123 Test St",
        "city": "Columbus",
        "state": "Ohio",
        "zipCode": "43123",
        "country": "USA",
        "email": "example@2co.com",
        "phoneNumber": "5555555555"
    }
};

tco.checkout.authorize(authorize, function (error, data) {
    if (error) {
        console.log(error);
    } else {
       console.log(data.response.responseCode);
    }
});

Example Response:

{
    "validationErrors": null,
    "response": {
        "type": "AuthResponse",
        "currencyCode": "USD",
        "lineItems": [
            {
                "description": "",
                "duration": null,
                "options": [],
                "price": "10.00",
                "quantity": "1",
                "recurrence": null,
                "startupFee": null,
                "productId": "",
                "tangible": "N",
                "name": "123",
                "type": "product"
            }
        ],
        "transactionId": "205208408440",
        "billingAddr": {
            "addrLine1": "123 Test St",
            "addrLine2": null,
            "city": "Columbus",
            "zipCode": "43123",
            "phoneNumber": "5555555555",
            "phoneExtension": null,
            "email": "example@2co.com",
            "name": "Testing Tester",
            "state": "Ohio",
            "country": "USA"
        },
        "shippingAddr": {
            "addrLine1": null,
            "addrLine2": null,
            "city": null,
            "zipCode": null,
            "phoneNumber": null,
            "phoneExtension": null,
            "email": null,
            "name": null,
            "state": null,
            "country": null
        },
        "merchantOrderId": "123",
        "orderNumber": "205208408431",
        "recurrentInstallmentId": null,
        "responseMsg": "Successfully authorized the provided credit card",
        "responseCode": "APPROVED",
        "total": "10.00",
        "errors": null
    },
    "exception": null
}