from __future__ import annotations import base64 import json import re from pathlib import Path from typing import Any import httpx from a2a_pack.deepagents import create_a2a_deep_agent from langchain_core.messages import BaseMessage from langchain_core.tools import StructuredTool from pydantic import BaseModel, Field from a2a_pack import ( A2AAgent, ConsumerSetup, ConsumerSetupField, ConsumerSetupMissing, EgressPolicy, LLMProvisioning, Pricing, Resources, RunContext, skill, ) DEFAULT_BASE_URL = "https://api-m.paypal.com" OPERATIONS = json.loads("{\n \"orders_authorize\": {\n \"base_url\": \"https://api-m.paypal.com\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Authorizes payment for an order. To successfully authorize payment for an order, the buyer must first approve the order or a valid payment_source must be provided in the request. A buyer can approve the order upon being redirected to the rel:approve URL that was returned in the HATEOAS links in the create order response.
Note: For error handling and troubleshooting, see Orders v2 errors.\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"orders_authorize\",\n \"parameters\": [\n {\n \"description\": \"The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. It is mandatory for all single-step create order calls (E.g. Create Order Request with payment source information like Card, PayPal.vault_id, PayPal.billing_agreement_id, etc).\",\n \"in\": \"header\",\n \"name\": \"PayPal-Request-Id\",\n \"required\": false,\n \"schema\": {\n \"maxLength\": 108,\n \"minLength\": 1,\n \"pattern\": \"^[\\\\S\\\\s]*$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"The preferred server response upon successful completion of the request. Value is:
return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.return=representation. The server returns a complete resource representation, including the current state of the resource.Note: For error handling and troubleshooting, see Orders v2 errors.\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"orders_capture\",\n \"parameters\": [\n {\n \"description\": \"The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. It is mandatory for all single-step create order calls (E.g. Create Order Request with payment source information like Card, PayPal.vault_id, PayPal.billing_agreement_id, etc).\",\n \"in\": \"header\",\n \"name\": \"PayPal-Request-Id\",\n \"required\": false,\n \"schema\": {\n \"maxLength\": 108,\n \"minLength\": 1,\n \"pattern\": \"^[\\\\S\\\\s]*$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"The preferred server response upon successful completion of the request. Value is:
return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.return=representation. The server returns a complete resource representation, including the current state of the resource.return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.return=representation. The server returns a complete resource representation, including the current state of the resource.Note: For error handling and troubleshooting, see Orders v2 errors.\",\n \"destructive\": true,\n \"method\": \"POST\",\n \"operation_id\": \"orders_create\",\n \"parameters\": [\n {\n \"description\": \"The server stores keys for 6 hours. The API callers can request the times to up to 72 hours by speaking to their Account Manager. It is mandatory for all single-step create order calls (E.g. Create Order Request with payment source information like Card, PayPal.vault_id, PayPal.billing_agreement_id, etc).\",\n \"in\": \"header\",\n \"name\": \"PayPal-Request-Id\",\n \"required\": false,\n \"schema\": {\n \"maxLength\": 108,\n \"minLength\": 1,\n \"pattern\": \"^[\\\\S\\\\s]*$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"PayPal Partner can send a PayPal-Partner-Attribution-Id request header with the value that they have been assigned by the PayPal Partner program. This value is known as a BN Code. In order to reward such partners (through partner programs), all the activities (including API calls) that they are doing on behalf of the merchants need to be tracked.\",\n \"in\": \"header\",\n \"name\": \"PayPal-Partner-Attribution-Id\",\n \"required\": false,\n \"schema\": {\n \"maxLength\": 36,\n \"minLength\": 1,\n \"pattern\": \"^[\\\\S\\\\s]*$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"A GUID value originating from Fraudnet and Dyson passed from external API clients via HTTP header. The value is used by Risk decisions to correlate calls which, in turn, might result in lower decline rates..\",\n \"in\": \"header\",\n \"name\": \"PayPal-Client-Metadata-Id\",\n \"required\": false,\n \"schema\": {\n \"$ref\": \"#/components/schemas/guid\"\n }\n },\n {\n \"description\": \"The preferred server response upon successful completion of the request. Value is:
return=minimal. The server returns a minimal response to optimize communication between the API caller and the server. A minimal response includes the id, status and HATEOAS links.return=representation. The server returns a complete resource representation, including the current state of the resource.Note: For error handling and troubleshooting, see Orders v2 errors.\",\n \"destructive\": false,\n \"method\": \"GET\",\n \"operation_id\": \"orders_get\",\n \"parameters\": [\n {\n \"description\": \"The ID of the order for which to show details.\",\n \"in\": \"path\",\n \"name\": \"id\",\n \"required\": true,\n \"schema\": {\n \"maxLength\": 36,\n \"minLength\": 1,\n \"pattern\": \"^[A-Z0-9]+$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"Holds authorization information for external API calls.\",\n \"in\": \"header\",\n \"name\": \"Authorization\",\n \"required\": false,\n \"schema\": {\n \"$ref\": \"#/components/schemas/standard_header_schema\"\n }\n },\n {\n \"description\": \"Header for an API client-provided JWT assertion that identifies the merchant. Establishing the consent to act-on-behalf of a merchant is a prerequisite for using this header.\",\n \"in\": \"header\",\n \"name\": \"PayPal-Auth-Assertion\",\n \"required\": false,\n \"schema\": {\n \"description\": \"Header for an API client-provided JWT assertion that identifies the merchant. Establishing the consent to act-on-behalf of a merchant is a prerequisite for using this header.\",\n \"maxLength\": 10000,\n \"minLength\": 1,\n \"pattern\": \"^.*$\",\n \"type\": \"string\"\n }\n },\n {\n \"description\": \"A comma-separated list of fields that should be returned for the order. Valid filter field is `payment_source`.\",\n \"in\": \"query\",\n \"name\": \"fields\",\n \"required\": false,\n \"schema\": {\n \"maxLength\": 2147483647,\n \"minLength\": 0,\n \"pattern\": \"^[a-z_]*$\",\n \"type\": \"string\"\n }\n }\n ],\n \"path\": \"/v2/checkout/orders/{id}\",\n \"request_body\": null,\n \"security\": [\n {\n \"Oauth2\": [\n \"https://uri.paypal.com/services/payments/payment\",\n \"https://uri.paypal.com/services/payments/orders/deprecating-jssdk-migration-for-limited-merchants\"\n ]\n }\n ],\n \"skill_name\": \"orders_get\",\n \"source_index\": 1,\n \"source_openapi_url\": \"https://raw.githubusercontent.com/paypal/paypal-rest-api-specifications/main/openapi/checkout_orders_v2.json\",\n \"source_title\": \"Orders\",\n \"summary\": \"Show order details\",\n \"tags\": [\n \"orders\"\n ]\n },\n \"orders_patch\": {\n \"base_url\": \"https://api-m.paypal.com\",\n \"base_url_field\": \"OPENAPI_BASE_URL\",\n \"description\": \"Updates an order with a `CREATED` or `APPROVED` status. You cannot update an order with the `COMPLETED` status.
\\\\\\\"/purchase_units/@reference_id=='default'/{attribute-or-object}\\\\\\\". Merchants and partners can add Level 2 and 3 data to payments to reduce risk and payment processing costs. For more information about processing payments, see checkout or multiparty checkout.Note: For error handling and troubleshooting, see Orders v2 errors.Patchable attributes or objects:
| Attribute | Op | Notes |
|---|---|---|
intent | replace | |
payer | replace, add | Using replace op for payer will replace the whole payer object with the value sent in request. |
purchase_units | replace, add | |
purchase_units[].custom_id | replace, add, remove | |
purchase_units[].description | replace, add, remove | |
purchase_units[].payee.email | replace | |
purchase_units[].shipping.name | replace, add | |
purchase_units[].shipping.email_address | replace, add | |
purchase_units[].shipping.phone_number | replace, add | |
purchase_units[].shipping.options | replace, add | |
purchase_units[].shipping.address | replace, add | |
purchase_units[].shipping.type | replace, add | |
purchase_units[].soft_descriptor | replace, remove | |
purchase_units[].amount | replace | |
purchase_units[].items | replace, add, remove | |
purchase_units[].invoice_id | replace, add, remove | |
purchase_units[].payment_instruction | replace | |
purchase_units[].payment_instruction.disbursement_mode | replace | By default, disbursement_mode is INSTANT. |
purchase_units[].payment_instruction.payee_receivable_fx_rate_id | replace, add, remove | |
purchase_units[].payment_instruction.platform_fees | replace, add, remove | |
purchase_units[].supplementary_data.airline | replace, add, remove | |
purchase_units[].supplementary_data.card | replace, add, remove | |
application_context.client_configuration | replace, add |
| Attribute | Op | Notes |
|---|---|---|
items | replace | Using replace op for items will replace the entire items object with the value sent in request. |
notify_payer | replace, add | |
status | replace | Only patching status to CANCELLED is currently supported. |