# Use stored credit

The Stored Credit payment method allows merchants to process payments without requiring payment details from the shopper. Instead, the shopper's credit balance is pre-stored and managed within your system (NOT stored by 2Checkout). When using this payment method via API, it is the merchant's responsibility to validate that the shopper has sufficient credits to complete the transaction. This method allows you to accept payments using pre-purchased credits systems such as proprietary gift vouchers.

## Availability

This payment method is exclusive to the API and is not available on any of 2Checkout's hosted shopping carts.

## Supported currencies

Stored Credit is at the moment available only in USD. Contact 2Checkout to ask about availability in other currencies.

## Workflow

1. Distribute the credits to your customers using your desired process, outside of the 2Checkout platform.
2. Validate that the customer who intends to initiate the order has enough credits available.
3. Create the order object. Use **STORED\_CREDIT** as the type in `PaymentDetails` object.

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>It is not recommended that you use the <code>PaymentMethod</code> object for Stored Credit — the only parameter supported is <code>RecurringEnabled</code> = false which is also the default value. true is not supported and will return an error.</p></div>
4. Place the order.

## Request parameters

<table><thead><tr><th width="126.5333251953125">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><code>sessionID</code></td><td><strong>Required (string)</strong><br>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 10 minutes.</td></tr><tr><td><a href="/pages/1Nzq8FH3DErKvpOktB0W"><code>Order</code></a></td><td><strong>Required (object)</strong><br>Object designed to collect all data necessary for an order, including billing, products/subscription plan and payment details. See code sample for more details.</td></tr></tbody></table>

### Request sample

```php
<?php
declare(strict_types=1);
class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'https://api.2checkout.com/rpc/6.0';
    public const ACTION = 'placeOrder';
    //array or JSON
    public const PAYLOAD = <<<JSON
{
    "Currency": "USD",
    "Language": "EN",
    "Country": "us",
    "CustomerIP": "91.220.121.21",
    "Source": "sourceAPI.net",
    "LocalTime": "2022-01-13 09:41:59",
    "CustomerReference": 421820775,
    "Items": [\
        {\
            "Code": "TA-TuneUp-M-RENEW"\
        }\
    ],
    "BillingDetails": {
        "Address1": "Test Address",
        "City": "LA",
        "State": "California",
        "CountryCode": "US",
        "Email": "testcustomer@2Checkout.com",
        "FirstName": "Customer",
        "LastName": "2Checkout",
        "Zip": "12345"
      },
    "PaymentDetails": {
        "Type": "STORED_CREDIT",
        "Currency": "USD",
        "CustomerIP": "91.220.121.21"
    }
}
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;
        $algo = 'sha256';
        $hash = hash_hmac($algo, $string, $key);
        return compact('merchantCode', 'date', 'hash', 'algo');
    }
    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, $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,
            ['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 parameters

<table><thead><tr><th width="180.933349609375">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><a href="/pages/296f77b2320970fcc8c6d6047e6ecabcaa996ffa"><code>Order information</code></a></td><td><strong>Object</strong><br>Object containing order information.</td></tr></tbody></table>


---

# 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/place-orders-with-catalog-products/use-stored-credit.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.
