# Use PayPal

Place an order with dynamic product information, and collect the payment using PayPal.

## Workflow

1. Create the order object. Use PAYPAL as the type of the `PaymentDetails` object and send the shopper email and a return URL as part of the `PaymentMethod` object. Place the order.
2. Once you place the order, 2Checkout logs it into the system. At this point in time, the status of the order is PENDING. 2Checkout responds with the Order information object.
3. Redirect shoppers to the `RedirectURL` from the Order information object you receive as response from 2Checkout.
4. Once shoppers log into their PayPal account and complete the transaction, they're redirected to the `ReturnURL` you set in the order object. 2Checkout also authorizes the order and updates the status to AUTHRECEIVED.&#x20;

## Request parameters

<table><thead><tr><th width="119.0667724609375">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 <strong>10 minutes</strong>.</td></tr><tr><td><a href="/pages/PiGMut3YIzAbHaH9WUTM"><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.<br>To place an order with PayPal rather than PayPal Express, use PAYPAL as the type of the <code>PaymentDetails</code> object and send the shopper email and a return URL as part of the <code>PaymentMethod</code> object. See code sample.</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/soap/6.0';
    public const ACTION = 'placeOrder';
    public const ADDITIONAL_OPTIONS = null;
    //array or JSON
    public const PAYLOAD = <<<JSON
{
  "Country": "us",
  "Currency": "USD",
  "CustomerIP": "91.220.121.21",
  "ExternalReference": "SOAP_API_AVANGTE",
  "Language": "en",
  "Source": "testAPI.com",
  "BillingDetails": {
    "Address1": "Test Address",
    "City": "LA",
    "State": "California",
    "CountryCode": "US",
    "Email": "testcustomer@2Checkout.com",
    "FirstName": "Customer",
    "LastName": "2Checkout",
    "Zip": "12345"
  },
  "Items": [\
    {\
      "Name": "Dynamic product",\
      "Description": "Test description",\
      "Quantity": 1,\
      "IsDynamic": true,\
      "Tangible": false,\
      "PurchaseType": "PRODUCT",\
      "Price": {\
        "Amount": 100,\
        "Type": "CUSTOM"\
      },\
      "ProductTaxCategoryUUID": "2ad5ecfe-508d-4852-bd24-d400c297523b",\
      "PriceType": "NET",\
      "PriceOptions": [\
        {\
          "Name": "OPT1",\
          "Options": [\
            {\
              "Name": "Name LR",\
              "Value": "Value LR",\
              "Surcharge": 7\
            }\
          ]\
        }\
      ],\
      "RecurringOptions": {\
        "CycleLength": 2,\
        "CycleUnit": "DAY",\
        "CycleAmount": 12.2,\
        "ContractLength": 3,\
        "ContractUnit": "DAY"\
      }\
    }\
  ],
  "PaymentDetails": {
    "Currency": "USD",
    "CustomerIP": "91.220.121.21",
    "PaymentMethod": {
      "RecurringEnabled": false,
      "ReturnURL": "http://secure.avangate.local/test/index.php",
      "CancelURL": "http://secure.avangate.local/test/create_order.php"
    },
    "Type": "PAYPAL"
  }
}
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) {
    var_dump($ex);
}
```

## Response parameters

<table><thead><tr><th width="190.5333251953125">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/9733888381672847c4e7be464828138038155e63"><code>Order Information</code></a></td><td>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/soap-api-reference/soap-api-6.0/api-requests/place-orders-with-dynamic-product-information/use-paypal.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.
