Skip to main content

Create a sale

Last updated: 06-Feb-2023
Rate this article:

Overview

Once you have passed the token to your server, you can use it along with your private key to charge the credit card and create a new sale using the authorization API call. The authorization will capture and deposit automatically within 48 hours of being placed.

Each of our community-supported libraries provides a method to perform authorization and create a new sale.

Attributes

The authorization API call must be passed a JSON string with the customer's billing information, an order identifier through the `merchantOrderId` parameter, your seller ID, private key, and either lineItem(s) data or just a sale total on all requests. The API will always return a JSON response body that includes a `response` sub-object on successful authorizations and an `exception` sub-object on failed authorizations that provide the result and transaction details.

API URL: https://www.2checkout.com/checkout/api/1/(seller_id)/rs/authService

Replace (seller_id) with your 2Checkout seller ID.

Content-Type: application/json

Returns: JSON response

HTTP Method: POST

Authorization Request Object

Base Attributes

Attribute Description
sellerId Your 2Checkout account number. Required
privateKey Your 2Checkout Private Key.  Required
merchantOrderId Your custom order identifier. Required.
token The credit card token. Required.
currency AFN, ALL, DZD, ARS, AUD, AZN, BSD, BDT, BBD, BZD, BMD, BOB, BWP, BRL, GBP, BND, BGN, CAD, CLP, CNY, COP, CRC, n n requCZK, DKK, DOP, XCD, EGP, EUR, FJD, GTQ, HKD, HNL, HUF, INR, IDR, ILS, JMD, JPY, KZT, KES, LAK, MMK, LBP, LRD, MOP, MYR, MVR, MRO, MUR, MXN, MAD, NPR, TWD, NZD, NIO, NOK, PKR, PGK, PEN, PHP, PLN, QAR, RON, RUB, WST, SAR, SCR, SGD, SBD, ZAR, KRW, LKR, SEK, CHF, SYP, THB, TOP, TTD, TRY, UAH, AED, USD, VUV, VND, XOF, YER. Use to specify the currency for the sale. Required.
total The Sale Total. Format: 0.00-99999999.99, defaults to 0 if a value isn’t passed in or if value is incorrectly formatted, no negatives (Only Use if you are not passing in lineItems.)
demo Test Order. Pass value as true to place a test order. Optional.

Lineitem Attributes

Attribute Description
lineItems Array of lineitem objects using the attributes specified below.
Will be returned in the order that they are passed in.
(Passed as a sub object to the Authorization Object.)
(Only Use if you are not passing in total.)
type The type of line item that is being passed in. (Always Lower Case, ‘product’, ‘shipping’, ‘tax’ or ‘coupon’, defaults to ‘product’) Required
name Name of the item passed in. (128 characters max, cannot use ‘<' or '>’, defaults to capitalized version of ‘type’.) Required
quantity Quantity of the item passed in. (0-999, defaults to 1 if not passed in or incorrectly formatted.) Optional
price Price of the line item. Format: 0.00-99999999.99, defaults to 0 if a value isn’t passed in or if value is incorrectly formatted, no negatives (use positive values for coupons). Required
tangible Y or N. Will default to Y if the type is shipping. Optional
productId Your custom product identifier. Optional
recurrence Sets billing frequency. Ex. ‘1 Week’ to bill order once a week. (Can use # Week, # Month or # Year) Required for recurring lineitems.
duration Sets how long to continue billing. Ex. ‘1 Year’. (Forever or # Week, # Month, # Year) Required for recurring lineitems.
startupFee Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price. Optional

Lineitem Option Attributes

Attribute Description
options Array of option objects using the attributes specified below. Optional
Will be returned in the order that they are passed in.
(Passed as a sub object of a lineItem object.)
optName Name of product option. Ex. Size (64 characters max – cannot include ‘<' or '>’) Required
optValue Option selected. Ex. Small (64 characters max, cannot include ‘<' or '>’) Required
optSurcharge Option price in seller currency. (0.00 for no cost options) Required

Billing Address Attributes

Attribute Description
billingAddr Object that defines the billing address using the attributes specified below. Required
(Passed as a sub object to the Authorization Object.)
name Card holder’s name. (128 characters max) Required
addrLine1 Card holder’s street address. (64 characters max) Required
addrLine2 Card holder’s street address line 2. (64 characters max) Required if “country” value is: CHN, JPN, RUS - Optional for all other “country” values.
city Card holder’s city. (64 characters max) Required
state Card holder’s state. (64 characters max) Required if “country” value is ARG, AUS, BGR, CAN, CHN, CYP, EGY, FRA, IND, IDN, ITA, JPN, MYS, MEX, NLD, PAN, PHL, POL, ROU, RUS, SRB, SGP, ZAF, ESP, SWE, THA, TUR, GBR, USA - Optional for all other “country” values.
zipCode Card holder’s zip. (16 characters max) Required if “country” value is ARG, AUS, BGR, CAN, CHN, CYP, EGY, FRA, IND, IDN, ITA, JPN, MYS, MEX, NLD, PAN, PHL, POL, ROU, RUS, SRB, SGP, ZAF, ESP, SWE, THA, TUR, GBR, USA - Optional for all other “country” values.
country Card holder’s country. (64 characters max) Required
email Card holder’s email. (64 characters max) Required
phoneNumber Card holder’s phone. (16 characters max) Required
phoneExt Card holder’s phone extension. (9 characters max) Optional

Shipping Address Attributes

Attribute Description
shippingAddr Object that defines the shipping address using the attributes specified below. Optional
Only required if a shipping lineitem is passed.
(Passed as a sub object to the Authorization Object.)
name Card holder’s name. (128 characters max) Required
addrLine1 Card holder’s street address. (64 characters max) Required
addrLine2 Card holder’s street address line 2. (64 characters max) Required if “country” value is: CHN, JPN, RUS - Optional for all other “country” values.
city Card holder’s city. (64 characters max) Required
state Card holder’s state. (64 characters max) Required if “country” value is ARG, AUS, BGR, CAN, CHN, CYP, EGY, FRA, IND, IDN, ITA, JPN, MYS, MEX, NLD, PAN, PHL, POL, ROU, RUS, SRB, SGP, ZAF, ESP, SWE, THA, TUR, GBR, USA - Optional for all other “country” values.
zipCode Card holder’s zip. (16 characters max) Required if “country” value is ARG, AUS, BGR, CAN, CHN, CYP, EGY, FRA, IND, IDN, ITA, JPN, MYS, MEX, NLD, PAN, PHL, POL, ROU, RUS, SRB, SGP, ZAF, ESP, SWE, THA, TUR, GBR, USA - Optional for all other “country” values.
country Card holder’s country. (64 characters max) Optional

Example Authorization Request

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

var params = {
    "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(params, function (error, data) {
    if (error) {
        console.log(error.message);
    } else {
        console.log(JSON.stringify(data));
    }
});

Authorization Response Object

The ‘response’ sub object is returned on successful authorizations to provide the result and transaction details.

Base Attributes

Attribute Description
type Response Object Type “AuthResponse”
merchantOrderId Your custom order identifier registered to the sale.
orderNumber 2Checkout Order Number
transactionId 2Checkout Invoice ID
responseMsg Message indicating the result of the authorization attempt.
responseCode Code indicating the result of the authorization attempt.
total The Sale Total. Format: 0.00-99999999.99.
currencyCode The sale currency code.

Lineitem Attributes

Attribute Description
lineitems Array of lineitem objects associated with the sale returned in the order that they are passed in.
(Returned as a sub object to the Response Object.)
type The type of line item that is being passed in.
name Name of the item passed in.
quantity Quantity of the item passed in.
price Price of the line item.
productId Your custom product identifier.
tangible Y or N.
recurrence Sets billing frequency.
duration Sets how long to continue billing.
startupFee Any start up fees for the product or service.

Lineitem Option Attributes

Attribute Description
options Array of option objects returned in the order that they are passed in.
(Returned as a sub object of a lineItem object.)
optName Name of product option.
optValue Option selected.
optSurcharge Option price in seller currency.

Billing Address Attributes

Attribute Description
billingAddr Object that defines the billing address.
(Returned as a sub object to the Response Object.)
name Card holder’s name.
addrLine1 Card holder’s street address.
addrLine2 Card holder’s street address line 2.
city Card holder’s city.
state Card holder’s state.
zipCode Card holder’s zip.
country Card holder’s country.
email Card holder’s email.
phone Card holder’s phone.
phoneExt Card holder’s phone extension.

Shipping Address Attributes

Attribute Description
shippingAddr Object that defines the shipping address.
(Returned as a sub object to the Response Object.)
name Recipient name.
addrLine1 Recipient’s street address.
addrLine2 Recipient’s street address line 2.
city Recipient’s city.
state Recipient’s state.
zipCode Recipient’s zip.
country Recipient’s country.

Example Response JSON Object

{
    "validationErrors": null,
    "exception": null,
    "response": {
        "type": "AuthResponse",
        "lineItems": [
            {
                "options": [],
                "price": "6.99",
                "quantity": "2",
                "recurrence": "1 Month",
                "startupFee": null,
                "productId": "123",
                "tangible": "N",
                "name": "Demo Item 1",
                "type": "product",
                "description": "",
                "duration": "1 Year"
            },
            {
                "options": [
                    {
                        "optName": "Size",
                        "optValue": "Large",
                        "optSurcharge": "1.00"
                    }
                ],
                "price": "1.99",
                "quantity": "1",
                "recurrence": null,
                "startupFee": null,
                "productId": "",
                "tangible": "N",
                "name": "Demo Item 2",
                "type": "product",
                "description": "",
                "duration": null
            },
            {
                "options": [],
                "price": "3.00",
                "quantity": "1",
                "recurrence": null,
                "startupFee": null,
                "productId": "",
                "tangible": "Y",
                "name": "Shipping Fee",
                "type": "shipping",
                "description": "",
                "duration": null
            }
        ],
        "transactionId": "205182114564",
        "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": "123 Test St",
            "addrLine2": "",
            "city": "Columbus",
            "zipCode": "43123",
            "phoneNumber": null,
            "phoneExtension": null,
            "email": null,
            "name": "Testing Tester",
            "state": "OH",
            "country": "USA"
        },
        "merchantOrderId": "123",
        "orderNumber": "205182114555",
        "recurrentInstallmentId": null,
        "responseMsg": "Successfully authorized the provided credit card",
        "responseCode": "APPROVED",
        "total": "19.97",
        "currencyCode": "USD",
        "errors": null
    }
}

Errors

If an error occurs when attempting to authorize the sale, such as a processing error or an error in the JSON request, the errorCode and errorMsg will be returned in the exception sub object in the response body.

Base Attributes

Error Code Error Message Cause
300 Unauthorized Seller unauthorized to use the API or incorrect private key.
Invalid Token
200 Unable to process the request Incorrect attributes or malformed JSON object.
400 Bad request - parameter error Missing required attributes or invalid token.
600 Authorization Failed Credit Card failed to authorize.
601 Payment Authorization Failed:  Please update your cards expiration date and try again, or try another payment method. Invalid Expiration Date.
602 Payment Authorization Failed:  Please verify your Credit Card details are entered correctly and try again, or try another payment method. Credit Card failed to authorize.
603 Your credit card has been declined because of the currency you are attempting to pay in.  Please change the currency of the transaction or use a different card and try again. Invalid Currency for card type.
604 Payment Authorization Failed: Credit is not enabled on this type of card, please contact your bank for more information or try another payment method. Credit Card failed to authorize.
605 Payment Authorization Failed: Invalid transaction type for this credit card, please use a different card and try submitting the payment again, or contact your bank for more information. Invalid transaction type for credit card.
606 Payment Authorization Failed: Please use a different credit card or payment method and try again, or contact your bank for more information. Credit Card failed to authorize.
607 Payment Authorization Failed: Please verify your information and try again, or try another payment method. Credit Card failed to authorize.

Example Exception JSON Object

{
    "validationErrors": null,
    "exception": {
        "errorMsg": "Payment Authorization Failed:  Please verify your Credit Card details are entered correctly and try again, or try another payment method.",
        "httpStatus": "400",
        "exception": false,
        "errorCode": "602"
    },
    "response": null
}

 

Rate this article:

Need help?

Do you have a question? If you didn’t find the answer you are looking for in our documentation, you can contact our Support teams for more information. If you have a technical issue or question, please contact us. We are happy to help.

Not yet a Verifone customer?

We’ll help you choose the right payment solution for your business, wherever you want to sell, in-person or online. Our team of experts will happily discuss your needs.

Verifone logo