" 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

ChargeService().Authorize

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

Arguments

  • ChargeAuthorizeServiceOptions - Object composed of authorization attributes. Takes Sub-Objects `List`, `AuthBillingAddress` and `AuthShippingAddress`.
  • Attributes -> Authorization Attributes

Returns

Returns an Authorization object.

Example Usage:

TwoCheckoutConfig.SellerID = "1817037";
TwoCheckoutConfig.PrivateKey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3";
//TwoCheckoutConfig.Sandbox = true;   <-- Set Mode to use your 2Checkout sandbox account

try
{
    var Billing = new AuthBillingAddress();
    Billing.addrLine1 = "123 test st";
    Billing.city = "Columbus";
    Billing.zipCode = "43123";
    Billing.state = "OH";
    Billing.country = "USA";
    Billing.name = "Testing Tester";
    Billing.email = "example@2co.com";
    Billing.phone = "5555555555";

    var Customer = new ChargeAuthorizeServiceOptions();
    Customer.total = (decimal)1.00;
    Customer.currency = "USD";
    Customer.merchantOrderId = "123";
    Customer.billingAddr = Billing;
    Customer.token = "MzIwNzI3ZWQtMjdiNy00NTVhLWFhZTEtZGUyZGQ3MTk1ZDMw";

    var Charge = new ChargeService();
    
    var result = Charge.Authorize(Customer);
    Console.Write(result);
}
catch (TwoCheckoutException e)
{
    Console.Write(e);
}

Example Usage (Using Lineitems and Shipping):

TwoCheckoutConfig.SellerID = "1817037";
TwoCheckoutConfig.PrivateKey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3";

try
{
var Option1 = new AuthLineitemOption();
Option1.optName = "Test Option 1";
Option1.optValue = "Large";
Option1.optSurcharge = (decimal)1.00;

var Options = new List();
Options.Add(Option1);

var LineItem1 = new AuthLineitem();
LineItem1.name = "test item";
LineItem1.price = (decimal)10.00;
LineItem1.quantity = 1;
LineItem1.recurrence = "1 Month";
LineItem1.duration = "Forever";
LineItem1.options = Options;

var Lineitems = new List();
Lineitems.Add(LineItem1);

var Billing = new AuthBillingAddress();
Billing.addrLine1 = "123 test st";
Billing.city = "Columbus";
Billing.zipCode = "43123";
Billing.state = "OH";
Billing.country = "USA";
Billing.name = "Testing Tester";
Billing.email = "example@2co.com";
Billing.phoneNumber = "5555555555";

var Shipping = new AuthShippingAddress();
Shipping.addrLine1 = "123 test st";
Shipping.city = "Columbus";
Shipping.state = "OH";
Shipping.country = "USA";
Shipping.zipCode = "43123";
Shipping.name = "Testing Tester";


var Customer = new ChargeAuthorizeServiceOptions();
Customer.lineItems = Lineitems;
Customer.currency = "USD";
Customer.merchantOrderId = "123";
Customer.billingAddr = Billing;
Customer.shippingAddr = Shipping;
Customer.token = "ZDkzNGFlNjAtMzYyNi00ZjZmLTg1ZDAtODdlYWZkNmQ1Y2Vk";

var Charge = new ChargeService();

var result = Charge.Authorize(Customer);
    Console.Write(result);
}
catch (TwoCheckoutException e)
{
    Console.Write(e);
}

Example Response:

{TwoCheckout.Authorization}
    responseMsg: "Successfully authorized the provided credit card"
    responseCode: "APPROVED"
    type: "AuthResponse"
    orderNumber: 205205956108
    merchantOrderId: "123"
    transactionId: 205205956117
    currencyCode: "USD"
    total: 1.00
    lineItems: ...
      {TwoCheckout.AuthLineitem}
        type: "product"
        name: "123"
        quantity: 1
        price: 1.0
        tangible: "N"
        productId: ""
        recurrence: null
        duration: null
        startupFee: null
        options: ...
        billingAddr: { }
      {TwoCheckout.AuthBillingAddress}
        name: "Testing Tester"
        addrLine1: "123 test st"
        addrLine2: null
        city: "Columbus"
        state: "OH"
        zipCode: "43123"
        country: "USA"
        email: "example@2co.com"
        phone: null
        phoneExt: null
To test using the sandbox, set `TwoCheckoutConfig.Sandbox` to `true`.