Skip to main content
knowledgecenter.2checkout.com

Delete customer credit card

Overview

Use the removeCCFromCustomer method via SOAP API 6.0 to delete/unlink a customer's credit card information from the myAccount platform.

Request parameters

Parameter Type Required/Optional Description
CustomerReference String Required Internal 2Checkout customer reference or your customer identifier.
TransientToken String Required Transient Token for the card can be found in getCustomerInfoBySSOToken.

Response

# all good and was deleted
{
    "Deleted": true
}
# no and the delete failed with reasons
{
    "Deleted": false,
    "Subscriptions" [
        {
            "SubscriptionReference": "ABCF122132",
            "Error": {
                "error_code": "MY_ERROR_CODE_1",
                "message": ".... credit card was not deleted due to ..."
            }
        },
        {
            "SubscriptionReference": "DKHGTR12312",
            "Error": {
                "error_code": "MY_ERROR_CODE_2",
                "message": ".... credit card was not deleted due to ..."
            }
        },
        {
            "SubscriptionReference": "KHSTT1213",
            "Error": {
                "error_code": "MY_ERROR_CODE_3",
                "message": ".... credit card was not deleted due to ..."
            }
        }
    ]
}

Request sample

<?php
declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/soap/6.0';
    public const ACTION = 'unlinkCustomerCreditCard';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD =
        <<<json
    {
        "CustomerReference" : "someref",
        "TransientToken" : "sometoken"
    }
json;
}

class Client
{
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?object {
        if (is_array($payload)) {
            $payload = json_encode($payload);
        }
        if (!empty($payload)) {
            // SoapClient works with objects(StdClass)
            $payload = json_decode($payload);
        }
        $soapClient = $this->getClient($url);
        $sessionId = $this->getSession($soapClient);
        $args = array_filter([$sessionId, $payload]);

        return $soapClient->$action(...$args);
    }

    public function getClient(string $url): SoapClient
    {
        return new SoapClient(
            $url.'?wsdl',
            [
                'location' => $url,
                'cache_wsdl' => WSDL_CACHE_NONE,
            ]
        );
    }

    public function getSession(SoapClient $client)
    {
        $date = gmdate('Y-m-d H:i:s');
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $string = strlen($merchantCode).$merchantCode.strlen($date).$date;
        $hash = hash_hmac('md5', $string, $key);
        $client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');

        return $client->login($merchantCode, $date, $hash);
    }
}

try {
    $client = new Client();
    var_dump($client->call());
} catch (Exception $ex) {
    echo $ex->xdebug_message;
    var_dump($ex);
}
  • Was this article helpful?