> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/how-tos/placing-orders/payments/paypal/preparing-the-payment-for-execution.md).

# Preparing the payment for execution

How to make a payment ready to be executed on Paypal

## Problem

Your customer has approved the payment on Paypal – i.e. through [PayPal checkout](https://developer.paypal.com/docs/checkout/) — and has been redirected to your client. You need to make sure it's ready to be executed.

## Solution

To enable the payment execution with PayPal, you need to update the PayPal payment object. To do that, send a `PATCH` request to the `/api/paypal_payments/:id` endpoint, filling the `payment_payer_id` with the payer ID you just received from the client – see [PayPal documentation](https://developer.paypal.com/docs/integration/direct/payments/paypal-payments/#execute-payment) for any reference.

### Example

{% tabs %}
{% tab title="Request" %}
The following request updates the PayPal payment source identified by the "qaZPVIyoeg" ID with the payer ID received from the client:

<pre class="language-javascript"><code class="lang-javascript">curl -g -X PATCH \
  'http://yourdomain.commercelayer.io/api/paypal_payments/qaZPVIyoeg' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "paypal_payments",
    "id": "qaZPVIyoeg",
    "attributes": {
<strong>      "paypal_payer_id": "aaabbbccc123"
</strong>    }
  }
}
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the updated PayPal payment object:

<pre class="language-javascript"><code class="lang-javascript">{
  "data": {
    "id": "qaZPVIyoeg",
    "type": "paypal_payments",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/paypal_payments/qaZPVIyoeg"
    },
    "attributes": {
      "return_url": "https://checkout.yourdomain.com/jNbQLhMeqo/paypal",
      "cancel_url": "https://checkout.yourdomain.com/jNbQLhMeqo",
      "note_to_payer": null,
<strong>      "paypal_payer_id": "aaabbbccc123",
</strong>      "name": "aaabbbccc123",
      "paypal_id": "PAYID-xxxxyyyyzzzz",
      "status": "created",
      "approval_url": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&#x26;token=EC-123abc456",
      "payment_instrument":{...},
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": null,
      "reference_origin": null,
      "metadata": {}
    },
    "relationships": {
      "order": {
        "links": {
          "self": "https://commerce-layer.commercelayer.co/api/paypal_payments/qaZPVIyoeg/relationships/order",
          "related": "https://commerce-layer.commercelayer.co/api/paypal_payments/qaZPVIyoeg/order"
        }
      }
    },
    "meta": {
      "mode": "test",
      "organization_id": "Mn8oOpPqQr",
      "trace_id": "0b3c6d9e2f5a8b1c4d7e0f3a6b9c2d5e8f1a4b7c0d3e6f9a2b5c8d1e4f7a0b3c6"
    }
  },
  "meta": {
    "mode": "test",
    "organization_id": "Mn8oOpPqQr",
    "trace_id": "0b3c6d9e2f5a8b1c4d7e0f3a6b9c2d5e8f1a4b7c0d3e6f9a2b5c8d1e4f7a0b3c6"
  }
}
</code></pre>

{% endtab %}
{% endtabs %}

## More to read

See our documentation if you need more information on how to [update a PayPal payment](/core-api-reference/paypal_payments/update.md). See our Checkout guide for more details on how to place an order.

{% content-ref url="/pages/-LyDmx1SH-gJp8DstXnO" %}
[Placing the order](/how-tos/placing-orders/checkout/placing-the-order.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/how-tos/placing-orders/payments/paypal/preparing-the-payment-for-execution.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
