# Place order with existing payment methods

2Checkout supports 1-click purchases for returning customers who paid for their previous orders with:

* Credit/Debit cards

<details>

<summary>How does this work?</summary>

1. Identify returning customers.
2. Retrieve the payment method token.
3. Collect the CVV from the customer.
4. Place a new order using a valid payment method token and CVV.
5. 2Checkout charges returning customers using their payment-on-file information.

</details>

## Requirements <a href="#requirements" id="requirements"></a>

* **TransientToken** required for the **placeOrder** method. Can be retrieved from **getCustomerInformation**.
* This method only woks with **Credit/Debit** **cards**.

## Request parameters <a href="#parameters" id="parameters"></a>

<table><thead><tr><th width="121.2000732421875">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, product/subscription plan and payment details.</td></tr></tbody></table>

### Request sample

#### Retrieve customer existent payment methods <a href="#retrieve-customer-existent-payment-methods" id="retrieve-customer-existent-payment-methods"></a>

```php
<?php

declare(strict_types=1);

class Configuration
{
    public const MERCHANT_CODE = 'MERCHANT_CODE';
    public const MERCHANT_KEY = 'SECRET_KEY';
    public const URL = 'https://api.2checkout.com/rpc/6.0';
    public const ACTION = 'getCustomerInformation';
    public const CUSTOMER_REF = '1111';
    public const INCLUDE_PAYMENT_DATA = true;
    //array or JSON
    public const PAYLOAD = null;
}

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::CUSTOMER_REF, Configuration::CUSTOMER_REF, Configuration::INCLUDE_PAYMENT_DATA, $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 <a href="#place-an-order-using-previous-order-reference" id="place-an-order-using-previous-order-reference"></a>

| Parameters                                                              | Type/Description |
| ----------------------------------------------------------------------- | ---------------- |
| [`Customer`](/json-rpc-api-reference/json-rpc-api-6.0/api-responses.md) | **Object**       |

#### Place an order using existing payment data <a href="#place-an-order-using-existing-payment-data" id="place-an-order-using-existing-payment-data"></a>

```php
<?php
require('PATH_TO_AUTH');
$oldOrderExistent = callRPC((Object)$jsonRpcRequest, $host, true);
$Order = new stdClass();
$Order->RefNo = NULL;
$Order->Currency = 'usd';
$Order->Country = 'US';
$Order->Language = 'en';
$Order->CustomerIP = '91.220.121.21';
$Order->ExternalReference = NULL;
$Order->Source = NULL;
$Order->Affiliate = new stdClass();
$Order->Affiliate->AffiliateCode = 'Partner123'
$Order->Affiliate->AffiliateSource = 'MobilePlatform'
$Order->CustomerReference = NULL;
$Order->Items = array();
$Order->Items[0] = new stdClass();
$Order->Items[0]->Code = 'my_subscription_1';
$Order->Items[0]->Quantity = 1;
$Order->Items[0]->PriceOptions = NULL;
$Order->Items[0]->SKU = NULL;
$Order->Items[0]->Price = NULL;
$Order->Items[0]->CrossSell = NULL;
$Order->Items[0]->Trial = false;
$Order->BillingDetails = new stdClass();
$Order->BillingDetails->Email = $oldOrderExistent->BillingDetails->Email;;
$Order->DeliveryDetails = NULL;
$Order->PaymentDetails = new stdClass ();
$Order->PaymentDetails->Type = 'EXISTING_PAYMENT_DATA';
$Order->PaymentDetails->Currency = 'usd';
$Order->PaymentDetails->PaymentMethod = new stdClass ();
$Order->PaymentDetails->CustomerIP = '10.10.10.10';
$Order->PaymentDetails->PaymentMethod->TransientToken= 'oj5iyozmtkvuirzybvmwyhl3bl3nuxa44rkg5r1h';
$Order->PaymentDetails->PaymentMethod->CCID = '123';
$Order->PaymentDetails->PaymentMethod->Vendor3DSReturnURL = "http://www.success.ro";
$Order->PaymentDetails->PaymentMethod->Vendor3DSCancelURL = "http://www.error.ro"; 
$Order->Promotions = NULL;
$Order->AdditionalFields = NULL;
$Order->LocalTime = NULL;
$Order->GiftDetails = NULL;
$jsonRpcRequest = array (
'method' => 'placeOrder',
'params' => array($sessionID, $Order),
'id' => $i++,
'jsonrpc' => '2.0'
);
var_dump (callRPC((Object)$jsonRpcRequest, $host, true)); 
```

## Response parameters <a href="#response" id="response"></a>

<table><thead><tr><th width="184.13330078125">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-order-with-existing-payment-methods.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.
