Language

2Checkout Documentation

Payment API Testing

Testing the Payment API in the sandbox area is as easy as creating a sandbox account, generating your keys and following our integration documentation using the sandbox test credit card information.

Give it a try right now in your browser using JS Bin and Postman.


Setup

To enable the Payment API in your sandbox account, simply click on the API tab, then review and accept the API agreement.

API Agree

This takes you into the API settings page where you can find your sandbox API keys and sample credit card data to use while following our Payment API integration documentation.

API Settings
(You can regenerate your sandbox keys by clicking on the green Generate link.)

If you run into any issues while integrating, you can always access the logs for the Payment API calls you make under API Call Log subtab.

API Logs


Integration

Our Payment API documentation will walk you through the integration process. You will need to pass ‘sandbox’ as the first argument to the TCO.loadPubKey function and use the sandbox subdomain in the authorization URL.

Sandbox Public Key JavaScript Snippet

TCO.loadPubKey('sandbox', function() {
    // Sandbox Public Key is loaded
});‚Äč

Sandbox Authorization URL

https://sandbox.2checkout.com/checkout/api/1/[seller_id]/rs/authService

If you are using one of our community code libraries, an option already exists to designate the call as a sandbox call.

 

 

 

Server Code Snippet

curl -X POST https://sandbox.2checkout.com/checkout/api/1/901248156/rs/authService \
    -d '{"sellerId": "901248156", "privateKey": "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3", "merchantOrderId": "123", "token": "ODAxZjUzMDEtOWU0MC00NzA3LWFmMDctYmY1NTQ3MDhmZDFh", "currency": "USD", "lineItems": [{"name": "Demo Item", "price": "4.99", "type": "product", "quantity": "1", "recurrence": "4 Year", "startupFee": "9.99"}  ], "billingAddr": {"name": "testing tester", "addrLine1": "123 test blvd", "city": "columbus", "state": "Ohio", "zipCode": "43123", "country": "USA", "email": "example@2co.com", "phoneNumber": "123456789"} }' \
    -H 'Accept: application/json' -H 'Content-Type: application/json'
Twocheckout.privatekey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3";
Twocheckout.mode = "sandbox";

try {
    HashMap billing = new HashMap();
    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("phone", "555-555-5555");

    HashMap request = new HashMap();
    request.put("sellerId", "901248156");
    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();
}
TwoCheckoutConfig.SellerID = "901248156";
TwoCheckoutConfig.PrivateKey = "8CE03B2D-FE41-4C53-9156-52A8ED5A0FA3";
TwoCheckoutConfig.Sandbox = true;

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);
}
Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996');
Twocheckout::sellerId('901248204');
Twocheckout::sandbox(true);

try {
    $charge = Twocheckout_Charge::auth(array(
        "sellerId" => "901248204",
        "merchantOrderId" => "123",
        "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni',
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'testingtester@2co.com',
            "phoneNumber" => '555-555-5555'
        ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => 'testingtester@2co.com',
            "phoneNumber" => '555-555-5555'
        )
    ), 'array');
    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
    }
} catch (Twocheckout_Error $e) {
    $e->getMessage();
}
twocheckout.Api.auth_credentials({
    'private_key': 'BE632CB0-BB29-11E3-AFB6-D99C28100996',
    'seller_id': '901248204',
    'mode': 'sandbox'
})

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': 'example@2co.com',
        'phoneNumber': '555-555-5555'
    }
}

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

Twocheckout::API.credentials = {
    :seller_id => '901248204',
    :private_key => 'BE632CB0-BB29-11E3-AFB6-D99C28100996'
    :sandbox => 1
}

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

begin
  result = Twocheckout::Checkout.authorize(params)
rescue Twocheckout::TwocheckoutError => e
  puts e.message
end

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

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));
    }
});



Sandbox Sale Tools

Sale Tool

The sandbox sale tools provide the ability to test the life of a sale from end to end.

Testing Recurring

When a new recurring sale is placed in the sandbox, the following Recurring Installment options will be available on the sale detail page.

  • Bill Installment - Success: Creates a new invoice on the sale and sends the Recurring Installment Success notification.
  • Bill Installment - Credit Card Decline: Changes the sale recurring status to declined and sends the Recurring Installment Failed notification.
  • Bill Final Installment: Creates the final invoice on the sale and sends the Recurring Complete notification.

Testing Fraud Review

Place a new sale using the fraud buyer data, the fraud status will be set to wait and the Initiate Fraud Response options will be provided on the sale detail page.

  • Pass: Passes the sale and sends the Fraud Status Changed notification with a “fraud_status=pass”.
  • Fail: Fails and refunds the sale and sends the Fraud Status Changed notification with a “fraud_status=fail”.
  • Bill Final Installment: Creates the final invoice on the sale and sends the Recurring Complete notification.