PHP

This library provides developers with a simple set of bindings to the 2Checkout purchase routine, Instant Notification Service and Admin API.

Github URL - https://github.com/2Checkout/2checkout-php


Installation

To use, download or clone the repository.

git clone https://github.com/2Checkout/2checkout-php.git

Require in your PHP script.

require_once("/path/to/2checkout-php/lib/Twocheckout.php");

JSON is returned by default or you can add ‘array’ as an additional argument to each call to get an Array.


Example API Usage

Example Request:

Twocheckout::setCredentials("APIuser1817037", "APIpass1817037");

$args = array(
    'sale_id' => 4753371371,
    'category' => 1,
    'comment' => 'Order never sent.'
);

$result = Twocheckout_Sale::refund($args, 'array');
print_r($result);

Example Response:

Array
(
    [response_code] => OK
    [response_message] => refund added to invoice
)

Example Checkout Usage:

Example Request:

$args = array(
    'sid' => 532001,
    'cart_order_id' => 'Example Cart ID',
    'total' => '1.00'
);

Twocheckout_Charge::redirect($args);

Example Return Usage:

Example Request:

$params = array();
foreach ($_REQUEST as $k => $v) {
    $params[$k] = $v;
}

$passback = Twocheckout_Return::check($params, "tango", 'array');

Example Response:

Array
(
    [response_code] => Success
    [response_message] => Hash Matched
)

Example INS Usage:

Example Request:

$params = array();
foreach ($_POST as $k => $v) {
    $params[$k] = $v;
}

$passback = Twocheckout_Notification::check($params, "tango", 'array');

Example Response:

Array
(
    [response_code] => Success
    [response_message] => Hash Matched
)

Exceptions:

Twocheckout_Error exceptions are thrown if an error has returned. It is best to catch these exceptions so that they can be gracefully handled in your application.

Example Usage

Twocheckout::setCredentials("APIuser1817037", "APIpass1817037");

$params = array(
'sale_id' => 4774380224,
'category' => 1,
'comment' => 'Order never sent.'
);
try {
  $sale = Twocheckout_Sale::refund($params, 'array'); 
} catch (Twocheckout_Error $e) {
  $e->getMessage(); 
}