# Update subscription payment information

Use the updateSubscriptionPaymentInformation method to update the credit card information related to the payment to be made for a subscription. To be able to do this, you need to generate a payment token using the credit card information via the 2Pay.js library, and then use this token in the request of the method as indicated below.

## Request Parameters

<table><thead><tr><th width="214">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><code>sessionID</code></td><td><p><strong>Required (string)</strong></p><p>The session identifier, the output of the <strong>Login</strong> method. Include <code>sessionID</code> into all your requests. 2Checkout throws an exception if the values are incorrect. The <code>sessionID</code> expires in <strong>10 minutes</strong>.</p></td></tr><tr><td><code>subscriptionReference</code></td><td><strong>Required (string)</strong><br>The reference of the subscription for which you want to retrieve the payment information.</td></tr><tr><td><code>paymentInformation</code></td><td><strong>Required (object)</strong><br>The payment information object, details below:</td></tr><tr><td><code>PaymentDetails</code></td><td><strong>Required (object)</strong><br>The payment details object, details below:</td></tr><tr><td><code>Type</code></td><td><strong>Required (string)</strong><br>The payment details type. Restricted to EES_TOKEN_PAYMENT for now.</td></tr><tr><td><code>PaymentMethod</code></td><td><strong>Required (object)</strong><br>The payment method object, details below:</td></tr><tr><td><code>EesToken</code></td><td><strong>Required (string)</strong><br>The 2Pay token obtained by integrating the 2Pay.js library.</td></tr><tr><td><code>Vendor3DSReturnURL</code></td><td><strong>Required (string)</strong><br>URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.</td></tr><tr><td><code>Vendor3DSCancelURL</code></td><td><strong>Required (string)</strong><br>URL address to which customers are redirected after the 3DS details get validated by the bank and the order is successfully authorized.</td></tr></tbody></table>

### Request sample

```php
<?php

declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = '';
    public const MERCHANT_KEY = '';
    public const URL = 'http://api.2checkout.com/rpc/6.0';
    public const ACTION = 'updateSubscriptionPaymentInformation';
    public const ADDITIONAL_OPTIONS = null;
    public const SUBSCRIPTION_REF = 'YC9XXMGOYO';
    //array or JSON
    public const PAYLOAD = <<<JSON
{
  "PaymentDetails": {
    "Type": "EES_TOKEN_PAYMENT",
    "PaymentMethod": {
      "EesToken": "b8de22d1-1378-4a9a-be21-aa2145a6eb54",
      "Vendor3DSReturnURL": "www.3dsReturnURL.com",
      "Vendor3DSCancelURL": "www.3dsCancelURL.com"
    }
  }
}
JSON;
}

class Client
{
    private const LOGIN_METHOD = 'login';
    private $calls = 1;
    private $sessionId;
    private function generateAuth(): array
    {
        $merchantCode = Configuration::MERCHANT_CODE;
        $key = Configuration::MERCHANT_KEY;
        $date = gmdate('Y-m-d H:i:s');
        $string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
        $hash = hash_hmac('md5', $string, $key);
        return compact('merchantCode', 'date', 'hash');
    }
    public function login(string $url)
    {
        $payload = $this->generateAuth();
        $response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
        $this->sessionId = $response['result'];
    }
    public function call(
        string $url = Configuration::URL,
        $payload = Configuration::PAYLOAD,
        string $action = Configuration::ACTION
    ): ?array {
        if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
            $this->login($url);
        }

        if(is_string($payload)) {
            $payload = json_decode($payload, true);
        }
        if (!empty($this->sessionId)) {
            $payload = [$this->sessionId, Configuration::SUBSCRIPTION_REF, $payload];
        }
        $payload = array_filter($payload);

        $request = json_encode([\
            'jsonrpc' => '2.0',\
            'method' => $action,\
            'params' => $payload,\
            'id' => $this->calls++,\
        ]);

        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_SSLVERSION, 0);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
        $response = curl_exec($curl);
        if(empty($response)) {
            die('Server unavailable');
        }
        echo $response . '</br>';
        return json_decode($response, true);;
    }
}
$client = new Client();
$result = $client->call();
var_dump($result);
```

## Response

The method responds with **Boolean** **true** when the payment information update was successfully performed.

Otherwise, in case of validation or access rights failures, it returns the usual error response with specific messages indicating the cause of the failure.

```json
{
    "jsonrpc": "2.0",
    "id": 2,
    "result": {
        "FirstDigits": "4012",
        "LastDigits": "9936",
        "Authorize3DSUrl": "https://...",
        "CardType": "visa"
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/subscription/update-subscription-payment-information.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
