Create customer

Use the createCustomer method to add the details of a customer entity into the 2Checkout system. By default, customer status is Inactive until you assign a specific subscription to the customer. Following that action, customer status reflects the status of the attached subscription(s).

Request parameters

Parameter
Type / Description

sessionID

Required (string)

Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes.

Object

Request sample

<?php
$host   = "https://api.2checkout.com";
$client = new SoapClient($host . "/soap/4.0/?wsdl", array(
    'location' => $host . "/soap/4.0/",
    "stream_context" => stream_context_create(array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false
        )
    ))
));

function hmac($key, $data)
{
    $b = 64; // byte length for md5
    if (strlen($key) > $b) {
        $key = pack("H*", md5($key));
    }
    
    $key    = str_pad($key, $b, chr(0x00));
    $ipad   = str_pad('', $b, chr(0x36));
    $opad   = str_pad('', $b, chr(0x5c));
    $k_ipad = $key ^ $ipad;
    $k_opad = $key ^ $opad;
    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
}

$merchantCode = "YOUR_MERCHANT_CODE";
$key = "YOUR_SECRET_KEY";
$now = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($now) . $now;
$hash   = hmac($key, $string);

try {
    $sessionID = $client->login($merchantCode, $now, $hash);
} catch (SoapFault $e) {
    echo "Authentication: " . $e->getMessage();
    exit;
}

$newCustomer = new stdClass();
$newCustomer->TwoCheckoutCustomerReference = null;
$newCustomer->ExternalCustomerReference = 'ThisIsATestReference123456';
$newCustomer->FirstName = 'NewCustomer';
$newCustomer->LastName = 'NewCustomerLastName';
$newCustomer->Company = null;
$newCustomer->FiscalCode = null;
$newCustomer->Address1 = 'Address';
$newCustomer->Address2 = null;
$newCustomer->City = 'LA';
$newCustomer->Zip = '90210';
$newCustomer->CountryCode = 'us';
$newCustomer->Phone = null;
$newCustomer->Fax = null;
$newCustomer->Email = '[email protected]';
$newCustomer->ExistingCards = null;
$newCustomer->Enabled = null;
$newCustomer->Trial = null;

// New Credit object (optional)
$newCustomer->Credit = new stdClass();
$newCustomer->Credit->Limit = 51.0;       // float
$newCustomer->Credit->Remaining = 21.0;   // float
$newCustomer->Credit->Currency = 'EUR';   // string

try {
    $newCustomerInfo = $client->createCustomer($sessionID, $newCustomer);
} catch (SoapFault $e) {
    echo "newCustomerInfo: " . $e->getMessage();
    exit;
}

var_dump("newCustomerInfo", $newCustomerInfo);

Response parameters

Parameter
Type / Description

2CheckoutCustomerReference

Int

System-generated customer reference.

Last updated

Was this helpful?