" 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 a Checkout object.

Example Usage:

Twocheckout.privatekey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3";

try {
    HashMap<String, String> billing = new HashMap<String, String>();
    billing.put("name", "Testing Tester");
    billing.put("addrLine1", "xvxcvxcvxcvcx");
    billing.put("city", "Columbus");
    billing.put("state", "Ohio");
    billing.put("country", "USA");
    billing.put("zipCode", "43230");
    billing.put("email", "tester@2co.com");
    billing.put("phoneNumber", "555-555-5555");

    HashMap<String, Object> request = new HashMap<String, Object>();
    request.put("sellerId", "1817037");
    request.put("merchantOrderId", "test123");
    request.put("token", "MGI4OTU0OTQtMDIxNi00YThlLTliOTctZjg1YmJiMzg0MjA3");
    request.put("currency", "USD");
    request.put("total", "1.00");
    request.put("billingAddr", billing);

    Authorization response = TwocheckoutCharge.authorize(request);
    String message = response.getResponseMsg();
} catch (Exception e) {
    String message = e.toString();
}

Example Response:

{
    "type": "AuthResponse",
    "responseCode": "APPROVED",
    "currencyCode": "USD",
    "orderNumber": "205181062452",
    "transactionId": "205181062461",
    "responseMsg": "Successfully authorized the provided credit card",
    "merchantOrderId": "test123",
    "total": 1,
    "lineItems": [
        {
            "type": "product",
            "name": "test123",
            "description": "",
            "price": 1,
            "quantity": 1,
            "tangible": "N",
            "productId": "",
            "options": []
        }
    ]
}

To test using the sandbox, set `Twocheckout.mode` to `sandbox`.