PHPackages                             ducha/2checkout-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. ducha/2checkout-php-sdk

ActiveLibrary[Payment Processing](/categories/payments)

ducha/2checkout-php-sdk
=======================

2Checkout PHP SDK by Verifone

v1.1.2(1y ago)0148PHPPHP &gt;=5.6

Since Jul 12Pushed 1y agoCompare

[ Source](https://github.com/markomilivojevic/2checkout-php-sdk)[ Packagist](https://packagist.org/packages/ducha/2checkout-php-sdk)[ Docs](https://github.com/2Checkout/2checkout-php-sdk)[ RSS](/packages/ducha-2checkout-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

2Checkout PHP SDK
=================

[](#2checkout-php-sdk)

This is the current 2Checkout PHP SDK providing developers with a simple set of bindings to the 2Checkout 6.0 REST API, IPN and Convert Plus Signature API.

To use, clone and require with composer or require the included autoloader.

```
require_once('/path/to/2checkout-php-library/autoloader.php');
use Tco\TwocheckoutFacade;
```

All the features present in this library are used through TwocheckoutFacade instance which can be initialized with a configuration array.

```
$config    = array(
            'sellerId'      => YOUR_MERCHANT_CODE, // REQUIRED
            'secretKey'     => YOUR_SECRET_KEY, // REQUIRED
            'buyLinkSecretWord'    => YOUR_SECRET_WORD,
            'jwtExpireTime' => 30,
            'curlVerifySsl' => 1
);

$tco = new TwocheckoutFacade($config);
```

##### - &gt; All the required params in the $config can be found in [CPanel](https://secure.2checkout.com/cpanel/login.php) in Integrations -&gt; Webhooks &amp; API section

[](#---all-the-required-params-in-the-config-can-be-found-in-cpanel-in-integrations---webhooks--api-section)

Using the Api Core directly
---------------------------

[](#using-the-api-core-directly)

Call any 2Checkout REST 6.0 endpoint like below:

```
$result = $tco->apiCore()->call( '/orders/', $params, 'POST' );
```

Place order helper
------------------

[](#place-order-helper)

You can also use the provided Order helper object.

###### Dynamic Product:

[](#dynamic-product)

```
$dynamicOrderParams = array(
            'Country'           => 'US',
            'Currency'          => 'USD',
            'CustomerIP'        => '91.220.121.21',
            'ExternalReference' => 'CustOrd101',
            'Language'          => 'en',
            'Source'            => 'tcolib.local',
            'BillingDetails'    =>
                array(
                    'Address1'    => 'Street 1',
                    'City'        => 'Cleveland',
                    'State'       => 'Ohio',
                    'CountryCode' => 'US',
                    'Email'       => 'testcustomer@2Checkout.com',
                    'FirstName'   => 'John',
                    'LastName'    => 'Doe',
                    'Zip'         => '20034',
                ),
            'Items'             =>
                array(
                    0 =>
                        array(
                            'Name'         => 'Dynamic product2',
                            'Description'  => 'Product 2',
                            'Quantity'     => 3, //units
                            'IsDynamic'    => true,
                            'Tangible'     => false,
                            'PurchaseType' => 'PRODUCT',
                            'Price'        =>
                                array(
                                    'Amount' => 6, //value
                                    'Type'   => 'CUSTOM',
                                ),
                        ),
                    1 =>
                        array(
                            'Name'         => 'Dynamic product',
                            'Description'  => 'Test description',
                            'Quantity'     => 4,
                            'IsDynamic'    => true,
                            'Tangible'     => false,
                            'PurchaseType' => 'PRODUCT',
                            'Price'        =>
                                array(
                                    'Amount' => 1,
                                    'Type'   => 'CUSTOM',
                                )
                        ),
                ),
            'PaymentDetails'    =>
                array(
                    'Type'          => 'TEST', //'TEST' or 'EES_TOKEN_PAYMENT'
                    'Currency'      => 'USD',
                    'CustomerIP'    => '91.220.121.21',
                    'PaymentMethod' =>
                        array(
                            'RecurringEnabled' => false,
                            'HolderNameTime'   => 1,
                            'CardNumberTime'   => 1,
                        ),
                ),
        );
```

- We can get [Order](src/Tco/Source/Api/Rest/V6/Order.php) object by calling TwocheckoutFacade "order()" method:

```
$order = $tco->order();
```

- Order object has a method called "place" that generates a call to Api Core and returns a response:

```
$response = $order->place( $dynamicOrderParams );
```

- To validate the response you first need to check for "refno" key in response and then do a validation API call for that "refno". Example:

```
$orderData = $tco->order()->getOrder( array( 'RefNo' => $response['refNo'] ) );
```

Then validate "$orderData\['Status'\]". For successfully placed payments this value is "AUTHRECEIVED" or "COMPLETE".

\####2. Catalog Product

```
$orderCatalogProductParams = array(
    'Country'           => 'br',
    'Currency'          => 'brl',
    'CustomerIP'        => '91.220.121.21',
    'ExternalReference' => 'CustOrderCatProd100',
    'Language'          => 'en',
    'BillingDetails'    =>
        array(
            'Address1'    => 'Test Address',
            'City'        => 'LA',
            'CountryCode' => 'BR',
            'Email'       => 'customer@2Checkout.com',
            'FirstName'   => 'Customer',
            'FiscalCode'  => '056.027.963-98',
            'LastName'    => '2Checkout',
            'Phone'       => '556133127400',
            'State'       => 'DF',
            'Zip'         => '70403-900',
        ),
    'Items'             =>
        array(
            0 =>
                array(
                    'Code'     => 'E377076E6A_COPY1', //Get the code from CPANEL at Setup->Products->Code
                    column
                    'Quantity' => '1',
                ),
        ),
    'PaymentDetails'    =>
        array(
            'Type'          => 'TEST',
            'Currency'      => 'USD',
            'CustomerIP'    => '91.220.121.21',
            'PaymentMethod' =>
                array(
                    'CCID'               => '123',
                    'CardNumber'         => '4111111111111111',
                    'CardNumberTime'     => '12',
                    'CardType'           => 'VISA',
                    'ExpirationMonth'    => '12',
                    'ExpirationYear'     => '2023',
                    'HolderName'         => 'John Doe',
                    'HolderNameTime'     => '12',
                    'RecurringEnabled'   => true,
                    'Vendor3DSReturnURL' => 'www.test.com',
                    'Vendor3DSCancelURL' => 'www.test.com',
                ),
        ),
);
```

The rest of the flow is identical as for placing orders with dynamic products.

Subscriptions helper
--------------------

[](#subscriptions-helper)

- For a payment to be recurring (generate a subscription) one needs to add to "item" (product) array structure the "RecurringOptions" field set.

###### An example of how this option can be configured:

[](#an-example-of-how-this-option-can-be-configured)

```
'RecurringOptions' =>
    array(
        'CycleLength'    => 1,
        'CycleUnit'      => 'MONTH',
        'CycleAmount'    => 3,
        'ContractLength' => 3,
        'ContractUnit'   => 'Year',
    ),
```

###### An example of an item having recurring option:

[](#an-example-of-an-item-having-recurring-option)

```
'Items' =>
        array(
            0 =>
                array(
                    'Name'         => 'Dynamic product',
                    'Description'  => 'Product Description test',
                    'Quantity'     => 3, //units
                    'IsDynamic'    => true,
                    'Tangible'     => false,
                    'PurchaseType' => 'PRODUCT',
                    'Price'        =>
                        array(
                            'Amount' => 6, //amount in currency units
                            'Type'   => 'CUSTOM',
                        ),
                    //Dynamic product subscription.
                    'RecurringOptions' =>
                        array(
                            'CycleLength'    => 1,          //The length of the recurring billing cycle.
                            'CycleUnit'      => 'MONTH',    //Unit of measuring billing cycles (years, months).
                            'CycleAmount'    => 3,          //The amount to be billed on each renewal.
                            'ContractLength' => 3,          //The contact length for which the recurring option will apply.
                            'ContractUnit'   => 'Year',     //Unit of measuring contact length (years, months).
                        )
                )
        )
```

#### **Retrieving the subscriptions of a payment order** using an order number.

[](#retrieving-the-subscriptions-of-a-payment-order-using-an-order-number)

- In the following example we will get an array of all the subscriptions on an item:

```
/**
 * This will return the following array data:
 * return an array having this structure:
 * array(
 *   'item_code' => array(
 *        0 => 'subscription1_code',
 *        1=> 'Subscription2_code'
 *    )
 * )
**/

$productsRefWithSubscriptionRefArray = $tco->subscription()->getSubscriptionsByOrderRefNo( $orderData['RefNo'] );
```

- We can pick a subscription reference using the index it has in the retrieved array and then retrieve subscription details as in the following example:

```
$subscriptionSearch['SubscriptionReference'] = reset($productsRefWithSubscriptionRefArray)[0];
$subscriptionData = $tco->subscription()->searchSubscriptions($subscriptionSearch);
```

For more parameters by which subscriptions can be searched, check the API documentation [Here](https://app.swaggerhub.com/apis-docs/2Checkout-API/api-rest_documentation/6.0#/), and also check the Subscription class [Subscription](src/Tco/Source/Api/Rest/V6/Subscription.php)

Buy link signature generation
-----------------------------

[](#buy-link-signature-generation)

- To generate a buy link signature, create an array with the following structure (Details [Here](https://knowledgecenter.2checkout.com/Documentation/07Commerce/2Checkout-ConvertPlus/ConvertPlus_URL_parameters))

```
$buyLinkParameters = ‌array (
                       'address' => 'Street 1',
                       'city' => 'Cleveland',
                       'country' => 'US',
                       'name' => 'John Doe',
                       'phone' => '0018143519403',
                       'zip' => '20034',
                       'email' => 'testcustomer@2Checkout.com',
                       'company-name' => 'Verifone',
                       'state' => 'Ohio',
                       'ship-name' => 'John Doe',
                       'ship-address' => 'Street 1',
                       'ship-city' => 'Cleveland',
                       'ship-country' => 'US',
                       'ship-email' => 'testcustomer@2Checkout.com',
                       'ship-state' => 'Ohio',
                       'prod' => 'Colored Pencil',
                       'price' => 2,
                       'qty' => 1,
                       'type' => 'PRODUCT',
                       'tangible' => 0, // int 0 or 1
                       'src' => 'phpLibrary',
                       'return-url' => 'http://tcolib.local/Examples/Controllers/BuyLink/paymentCallback.php',
                       'return-type' => 'redirect',
                       'expiration' => 1617117946, // this is a dynamic unixtimestamp value
                       'order-ext-ref' => 'CustOrd101',
                       'item-ext-ref' => '20210330102546',
                       'customer-ext-ref' => 'testcustomer@2Checkout.com',
                       'currency' => 'usd',
                       'language' => 'en',
                       'test' => 1, //int (0 or 1)
                       'merchant' => '', //one needs a valid merchant id
                       'dynamic' => 1, //always int (0 or 1)
                       'recurrence' => '1:MONTH',
                       'duration' => '12:MONTH',
                       'renewal-price' => 2,
                     );

$buyLinkSignature = $tco->getBuyLinkSignature($buyLinkParameters);
$buyLinkParameters['signature'] = $buyLinkSignature;
$redirectTo = 'https://secure.2checkout.com/checkout/buy/?' . ( http_build_query( $buyLinkParameters ) );
//Now one can just redirect to the generated url.
```

\##Refunds Full refunds can be initiated using the library. Details about 2Checkout refunds [Here](https://knowledgecenter.2checkout.com/Documentation/27Refunds_and_chargebacks/Refunds)

```
$orderData = $tco->order()->getOrder( array( 'RefNo' => $this->lastRefNo ) );
//validate if requested order is valid

// Constructing FULL Refund Details
$refundData = array(
    'RefNo'        => $orderData['RefNo'], //Required
    'refundParams' => array(
        "amount"  => $orderData["GrossPrice"], //Required
        "comment" => 'REFUND Example',
        "reason"  => 'Other' //Required, default reason is "Other"
    )
);

$response = $tco->order()->issueRefund( $refundData );
```

Processing IPNs (Instant Payment Notification)
----------------------------------------------

[](#processing-ipns-instant-payment-notification)

IPNs are webhooks from 2Checkout which can be used to update payment statuses asynchronously. Instant Payment Notification (IPN) works as a message service generating automatic order/transaction notifications for your 2Checkout account. Use the notifications to process order data into your own management systems by synchronizing it with 2Checkout account events.

More details [Here](https://verifone.cloud/docs/2checkout/API-Integration/Webhooks/06Instant_Payment_Notification_IPN)

\####1. Validate Ipn Hash:

```
$params = $_POST;
    if ( ! isset( $params['REFNOEXT'] ) && ( ! isset( $params['REFNO'] ) && empty( $params['REFNO'] ) ) ) {
        throw new TcoException( 'Cannot identify order in Ipn request.' );
    }
$validIpn = $tco->validateIpnResponse($params);
```

\####2. Generate Ipn response:

```
$responseToken = $tco->generateIpnResponse($params);
echo $responseToken;
```

Exceptions
----------

[](#exceptions)

The library will throw a `TcoException` if an error response is returned. Here are some of the most known &amp; encountered exceptions:

\#####When one has a curl exception

- 'Exception ApiCore response: ' + MESSAGE #####When BuyLink signature generator does not return the signature.
- 'Api response is missing Signature parameter: ' + MESSAGE #####The reason above + some reasons regarding configuration or JwtSignature generation
- 'Exception generating buy link signature: ' + MESSAGE #####When retrieving a subscription by order reference number
- 'Exception getting subscriptions by order RefNo.' #####When one or more subscription search parameter
- 'Exception! Some subscription search parameters are not accepted: ' + MESSAGE #####When some search parameters for order search are not accepted
- Exception! Some order search parameters are not accepted: ' + MESSAGE #####If refunds fail this exception is raised
- 'Error when placing refund request: ' + MESSAGE #####Missing Secret word value for Buy Link signature generation
- 'Buy link Secret Word is not set in Tco Config! First set it and then use it.' #####When TcoConfig receives not accepted parameters or sellerId &amp;&amp; secretKey values are missing
- 'Some configuration keys are not accepted or not set!' #####Something went wrong when generating buy link signature in facade
- 'Exception getting buy link signature! Details: ' + MESSAGE #####When validating IPN request fails
- 'Cannot validate Ipn Request. Details:' + MESSAGE #####When generating IPN response fails
- 'Cannot generate Ipn Response. Details:' + MESSAGE

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance46

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~311 days

Total

3

Last Release

417d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85a10574447f265de286a7ee172e60f644d7433adce2a01bf24d60856a2741fa?d=identicon)[ducha](/maintainers/ducha)

---

Top Contributors

[![craigchristenson](https://avatars.githubusercontent.com/u/251493?v=4)](https://github.com/craigchristenson "craigchristenson (3 commits)")[![markomilivojevic](https://avatars.githubusercontent.com/u/22796935?v=4)](https://github.com/markomilivojevic "markomilivojevic (1 commits)")[![Tantacula](https://avatars.githubusercontent.com/u/1346989?v=4)](https://github.com/Tantacula "Tantacula (1 commits)")

---

Tags

paymentgateway2checkout2coverifone

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ducha-2checkout-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/ducha-2checkout-php-sdk/health.svg)](https://phpackages.com/packages/ducha-2checkout-php-sdk)
```

###  Alternatives

[2checkout/2checkout-php

2Checkout PHP Library

83740.3k2](/packages/2checkout-2checkout-php)[sudiptpa/omnipay-nabtransact

National Australia Bank (NAB) Transact driver for the Omnipay payment processing library.

1017.2k](/packages/sudiptpa-omnipay-nabtransact)[baklysystems/laravel-paymob

Laravel PayMob online payment gateway package

282.4k](/packages/baklysystems-laravel-paymob)[lucassmacedo/omnipay-mercadopago

MercadoPago gateway for OmniPay

154.6k](/packages/lucassmacedo-omnipay-mercadopago)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
