paypal-agent-toolkit 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. paypal_agent_toolkit-1.0.0/PKG-INFO +143 -0
  2. paypal_agent_toolkit-1.0.0/README.md +129 -0
  3. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/__init__.py +0 -0
  4. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/__init__.py +0 -0
  5. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/api.py +28 -0
  6. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/configuration.py +32 -0
  7. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/constants.py +4 -0
  8. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/logger_util.py +30 -0
  9. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/parameters.py +246 -0
  10. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/payload_util.py +133 -0
  11. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/paypal_client.py +63 -0
  12. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/prompts.py +100 -0
  13. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/tool_handlers.py +139 -0
  14. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/common/tools.py +144 -0
  15. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/openai/__init__.py +0 -0
  16. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/openai/tool.py +35 -0
  17. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit/openai/toolkit.py +54 -0
  18. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit.egg-info/PKG-INFO +143 -0
  19. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit.egg-info/SOURCES.txt +22 -0
  20. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit.egg-info/dependency_links.txt +1 -0
  21. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit.egg-info/requires.txt +3 -0
  22. paypal_agent_toolkit-1.0.0/paypal_agent_toolkit.egg-info/top_level.txt +1 -0
  23. paypal_agent_toolkit-1.0.0/pyproject.toml +37 -0
  24. paypal_agent_toolkit-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,143 @@
1
+ Metadata-Version: 2.4
2
+ Name: paypal-agent-toolkit
3
+ Version: 1.0.0
4
+ Summary: A toolkit for agent interactions with PayPal API.
5
+ Author-email: PayPal <support@paypal.com>
6
+ Project-URL: Bug Tracker, https://github.com/paypal/agent-toolkit/issues
7
+ Project-URL: Source Code, https://github.com/paypal/agent-toolkit
8
+ Keywords: paypal,payments,checkout,api
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: httpx>=0.26.0
12
+ Requires-Dist: requests>=2.31.0
13
+ Requires-Dist: pydantic>=2.10
14
+
15
+ # PayPal Agentic Toolkit
16
+
17
+ The PayPal Agentic Toolkit integrates PayPal's REST APIs seamlessly with OpenAI Agents, allowing AI-driven management of PayPal transactions.
18
+
19
+ ## Available tools
20
+
21
+ The PayPal Agent toolkit provides the following tools:
22
+
23
+ **Orders**
24
+
25
+ - `create_order`: Create an order in PayPal system based on provided details
26
+ - `get_order`: Retrieve the details of an order
27
+ - `capture_order`: Capture payment for an authorized order
28
+
29
+ **Products**
30
+
31
+ - `create_product`: Create a new product in the PayPal catalog
32
+ - `list_products`: List products with optional pagination and filtering
33
+ - `show_product_details`: Retrieve details of a specific product
34
+ - `update_product`: Update an existing product
35
+
36
+ **Subscription Plans**
37
+
38
+ - `create_subscription_plan`: Create a new subscription plan
39
+ - `list_subscription_plans`: List subscription plans
40
+ - `show_subscription_plan_details`: Retrieve details of a specific subscription plan
41
+
42
+ **Subscriptions**
43
+
44
+ - `create_subscription`: Create a new subscription
45
+ - `show_subscription_details`: Retrieve details of a specific subscription
46
+ - `cancel_subscription`: Cancel an active subscription
47
+
48
+
49
+ ## Prerequisites
50
+
51
+ Before setting up the workspace, ensure you have the following installed:
52
+ - Python 3.11 or higher
53
+ - `pip` (Python package manager)
54
+ - A PayPal developer account for API credentials
55
+
56
+ ## Installation
57
+
58
+ You don't need this source code unless you want to modify the package. If you just
59
+ want to use the package, just run:
60
+
61
+ ```sh
62
+ pip install paypal-agent-toolkit
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ The library needs to be configured with your PayPal developer account's API credentials which is
68
+ available in your [PayPal Developer Dashboard][app-keys].
69
+
70
+ ```python
71
+ from paypal_agent_toolkit.openai.toolkit import PayPalToolkit
72
+ from paypal_agent_toolkit.common.configuration import Configuration, Context
73
+
74
+ configuration = Configuration(
75
+ actions={
76
+ "orders": {
77
+ "create": True,
78
+ "get": True,
79
+ "capture": True,
80
+ }
81
+ },
82
+ context=Context(
83
+ sandbox=True
84
+ )
85
+ )
86
+
87
+ # Initialize toolkit
88
+ toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)
89
+
90
+ ```
91
+
92
+ This toolkit is designed to work with OpenAI's Agent SDK and Assistant API. It provides pre-built tools for managing PayPal transactions like creating, capturing, and checking orders details etc.
93
+
94
+
95
+ ### Using with OpenAI Agent SDK
96
+ ```python
97
+ from agents import Agent
98
+
99
+ tools = toolkit.get_tools()
100
+
101
+ agent = Agent(
102
+ name="PayPal Assistant",
103
+ instructions="""
104
+ You're a helpful assistant specialized in managing PayPal transactions:
105
+ - To create orders, invoke create_order.
106
+ - After approval by user, invoke capture_order.
107
+ - To check an order status, invoke get_order_status.
108
+ """,
109
+ tools=tools
110
+ )
111
+ ```
112
+
113
+
114
+ ### Using with OpenAI Assistants API
115
+ ```python
116
+
117
+ tools = toolkit.get_openai_chat_tools()
118
+ paypal_api = toolkit.get_paypal_api()
119
+
120
+ # Create assistant
121
+ assistant = client.beta.assistants.create(
122
+ name="PayPal Checkout Assistant",
123
+ instructions=f"""
124
+ You help users create and capture PayPal orders. When the user wants to make a purchase,
125
+ use the create_order tool and share the approval link. After approval, use capture_order.
126
+ """,
127
+ model="gpt-4-1106-preview",
128
+ tools=tools
129
+ )
130
+
131
+ # Create thread
132
+ thread = client.beta.threads.create()
133
+
134
+ # Start or retrieve a run
135
+ run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
136
+ ```
137
+
138
+ Examples for OpenAI's Agent SDK are included in [/examples](/examples).
139
+
140
+ [app-keys]: https://developer.paypal.com/dashboard/applications/sandbox
141
+
142
+ ## Disclaimer
143
+ AI-generated content may be inaccurate or incomplete. Users are responsible for independently verifying any information before relying on it. PayPal makes no guarantees regarding output accuracy and is not liable for any decisions, actions, or consequences resulting from its use.
@@ -0,0 +1,129 @@
1
+ # PayPal Agentic Toolkit
2
+
3
+ The PayPal Agentic Toolkit integrates PayPal's REST APIs seamlessly with OpenAI Agents, allowing AI-driven management of PayPal transactions.
4
+
5
+ ## Available tools
6
+
7
+ The PayPal Agent toolkit provides the following tools:
8
+
9
+ **Orders**
10
+
11
+ - `create_order`: Create an order in PayPal system based on provided details
12
+ - `get_order`: Retrieve the details of an order
13
+ - `capture_order`: Capture payment for an authorized order
14
+
15
+ **Products**
16
+
17
+ - `create_product`: Create a new product in the PayPal catalog
18
+ - `list_products`: List products with optional pagination and filtering
19
+ - `show_product_details`: Retrieve details of a specific product
20
+ - `update_product`: Update an existing product
21
+
22
+ **Subscription Plans**
23
+
24
+ - `create_subscription_plan`: Create a new subscription plan
25
+ - `list_subscription_plans`: List subscription plans
26
+ - `show_subscription_plan_details`: Retrieve details of a specific subscription plan
27
+
28
+ **Subscriptions**
29
+
30
+ - `create_subscription`: Create a new subscription
31
+ - `show_subscription_details`: Retrieve details of a specific subscription
32
+ - `cancel_subscription`: Cancel an active subscription
33
+
34
+
35
+ ## Prerequisites
36
+
37
+ Before setting up the workspace, ensure you have the following installed:
38
+ - Python 3.11 or higher
39
+ - `pip` (Python package manager)
40
+ - A PayPal developer account for API credentials
41
+
42
+ ## Installation
43
+
44
+ You don't need this source code unless you want to modify the package. If you just
45
+ want to use the package, just run:
46
+
47
+ ```sh
48
+ pip install paypal-agent-toolkit
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ The library needs to be configured with your PayPal developer account's API credentials which is
54
+ available in your [PayPal Developer Dashboard][app-keys].
55
+
56
+ ```python
57
+ from paypal_agent_toolkit.openai.toolkit import PayPalToolkit
58
+ from paypal_agent_toolkit.common.configuration import Configuration, Context
59
+
60
+ configuration = Configuration(
61
+ actions={
62
+ "orders": {
63
+ "create": True,
64
+ "get": True,
65
+ "capture": True,
66
+ }
67
+ },
68
+ context=Context(
69
+ sandbox=True
70
+ )
71
+ )
72
+
73
+ # Initialize toolkit
74
+ toolkit = PayPalToolkit(client_id=PAYPAL_CLIENT_ID, secret=PAYPAL_SECRET, configuration = configuration)
75
+
76
+ ```
77
+
78
+ This toolkit is designed to work with OpenAI's Agent SDK and Assistant API. It provides pre-built tools for managing PayPal transactions like creating, capturing, and checking orders details etc.
79
+
80
+
81
+ ### Using with OpenAI Agent SDK
82
+ ```python
83
+ from agents import Agent
84
+
85
+ tools = toolkit.get_tools()
86
+
87
+ agent = Agent(
88
+ name="PayPal Assistant",
89
+ instructions="""
90
+ You're a helpful assistant specialized in managing PayPal transactions:
91
+ - To create orders, invoke create_order.
92
+ - After approval by user, invoke capture_order.
93
+ - To check an order status, invoke get_order_status.
94
+ """,
95
+ tools=tools
96
+ )
97
+ ```
98
+
99
+
100
+ ### Using with OpenAI Assistants API
101
+ ```python
102
+
103
+ tools = toolkit.get_openai_chat_tools()
104
+ paypal_api = toolkit.get_paypal_api()
105
+
106
+ # Create assistant
107
+ assistant = client.beta.assistants.create(
108
+ name="PayPal Checkout Assistant",
109
+ instructions=f"""
110
+ You help users create and capture PayPal orders. When the user wants to make a purchase,
111
+ use the create_order tool and share the approval link. After approval, use capture_order.
112
+ """,
113
+ model="gpt-4-1106-preview",
114
+ tools=tools
115
+ )
116
+
117
+ # Create thread
118
+ thread = client.beta.threads.create()
119
+
120
+ # Start or retrieve a run
121
+ run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
122
+ ```
123
+
124
+ Examples for OpenAI's Agent SDK are included in [/examples](/examples).
125
+
126
+ [app-keys]: https://developer.paypal.com/dashboard/applications/sandbox
127
+
128
+ ## Disclaimer
129
+ AI-generated content may be inaccurate or incomplete. Users are responsible for independently verifying any information before relying on it. PayPal makes no guarantees regarding output accuracy and is not liable for any decisions, actions, or consequences resulting from its use.
@@ -0,0 +1,28 @@
1
+
2
+
3
+ from typing import Optional
4
+ from pydantic import BaseModel
5
+ from .configuration import Context
6
+ from .paypal_client import PayPalClient
7
+ from .tools import tools
8
+
9
+ class PayPalAPI(BaseModel):
10
+
11
+ _context: Context
12
+ _paypal_client: PayPalClient
13
+
14
+ def __init__(self, client_id: str, secret: str, context: Optional[Context]):
15
+ super().__init__()
16
+
17
+ self._context = context if context is not None else Context()
18
+ self._paypal_client = PayPalClient(client_id=client_id, secret=secret, context=context)
19
+
20
+
21
+ def run(self, method: str, kwargs) -> str:
22
+ for tool in tools:
23
+ if tool.get("method") == method:
24
+ execute_fn = tool.get("execute")
25
+ if execute_fn:
26
+ return execute_fn(self._paypal_client, kwargs)
27
+ raise ValueError("create_order method not found in tools list")
28
+
@@ -0,0 +1,32 @@
1
+ from typing import Optional, Dict, Any
2
+
3
+ class Context:
4
+ def __init__(
5
+ self,
6
+ merchant_id: Optional[str] = None,
7
+ sandbox: Optional[bool] = None,
8
+ access_token: Optional[str] = None,
9
+ request_id: Optional[str] = None,
10
+ tenant_context: Optional[Any] = None,
11
+ debug: Optional[bool] = None,
12
+ **kwargs: Any
13
+ ):
14
+ self.merchant_id = merchant_id
15
+ self.sandbox = sandbox or False
16
+ self.access_token = access_token
17
+ self.request_id = request_id
18
+ self.tenant_context = tenant_context
19
+ self.debug = debug or False
20
+ self.extra = kwargs
21
+
22
+ class Configuration:
23
+ def __init__(self, actions: Dict[str, Dict[str, bool]], context: Optional[Context] = None):
24
+ self.actions = actions
25
+ self.context = context
26
+
27
+ def is_tool_allowed(tool: Dict[str, Dict[str, Dict[str, bool]]], configuration: Configuration) -> bool:
28
+ for product, product_actions in tool.get("actions", {}).items():
29
+ for action, allowed in product_actions.items():
30
+ if configuration.actions.get(product, {}).get(action, False):
31
+ return True
32
+ return False
@@ -0,0 +1,4 @@
1
+ SANDBOX_BASE_URL = "https://api-m.sandbox.paypal.com"
2
+ LIVE_BASE_URL = "https://api-m.paypal.com"
3
+ ENV_SANDBOX = "sandbox"
4
+ ENV_LIVE = "live"
@@ -0,0 +1,30 @@
1
+
2
+ import logging
3
+ import json
4
+
5
+ def mask_bearer_token(token: str) -> str:
6
+ if not token.startswith("Bearer "):
7
+ return token
8
+ raw = token[7:] # remove "Bearer "
9
+ if len(raw) <= 8:
10
+ return "Bearer ****"
11
+ return f"Bearer {raw[:4]}****{raw[-4:]}"
12
+
13
+
14
+ def logRequestPayload(debug, payload, url, headers):
15
+ logging.debug("POST %s", url)
16
+ if debug:
17
+ # Mask sensitive header before logging
18
+ masked_headers = {
19
+ **headers,
20
+ "Authorization": mask_bearer_token(headers["Authorization"])
21
+ }
22
+ logging.debug("Request Headers:\n%s", json.dumps(masked_headers, indent=2))
23
+ logging.debug("Request Payload:\n%s", json.dumps(payload, indent=2))
24
+
25
+
26
+ def configure_logging(debug: bool):
27
+ logging.basicConfig(
28
+ level=logging.DEBUG if debug else logging.ERROR,
29
+ format="%(asctime)s - %(levelname)s - %(message)s"
30
+ )
@@ -0,0 +1,246 @@
1
+ from pydantic import BaseModel, Field, HttpUrl, validator, field_validator, ConfigDict, constr
2
+ from typing import List, Literal, Optional
3
+
4
+
5
+
6
+ class ItemDetails(BaseModel):
7
+ item_cost: float = Field(..., description="The cost of each item – up to 2 decimal points.")
8
+ tax_percent: float = Field(0, description="The tax percent for the specific item.")
9
+ item_total: float = Field(..., description="The total cost of this line item.")
10
+
11
+
12
+ class LineItem(ItemDetails):
13
+ name: str = Field(..., description="The name of the item.")
14
+ quantity: int = Field(
15
+ 1,
16
+ description="The item quantity. Must be a whole number.",
17
+ ge=1
18
+ )
19
+ description: Optional[str] = Field(
20
+ None,
21
+ description="The detailed item description."
22
+ )
23
+
24
+
25
+ class ShippingAddress(BaseModel):
26
+ address_line_1: Optional[str] = Field(
27
+ None,
28
+ description=(
29
+ "The first line of the address, such as number and street, "
30
+ "for example, `173 Drury Lane`. This field needs to pass the full address."
31
+ )
32
+ )
33
+ address_line_2: Optional[str] = Field(
34
+ None,
35
+ description="The second line of the address, for example, a suite or apartment number."
36
+ )
37
+ admin_area_2: Optional[str] = Field(
38
+ None,
39
+ description="A city, town, or village. Smaller than `admin_area_level_1`."
40
+ )
41
+ admin_area_1: Optional[str] = Field(
42
+ None,
43
+ description=(
44
+ "The highest-level sub-division in a country, which is usually a province, "
45
+ "state, or ISO-3166-2 subdivision."
46
+ )
47
+ )
48
+ postal_code: Optional[str] = Field(
49
+ None,
50
+ description=(
51
+ "The postal code, which is the ZIP code or equivalent. Typically required "
52
+ "for countries with a postal code or an equivalent."
53
+ )
54
+ )
55
+ country_code: Optional[constr(min_length=2, max_length=2)] = Field(
56
+ None,
57
+ description=(
58
+ "The 2-character ISO 3166-1 code that identifies the country or region. "
59
+ "Note: The country code for Great Britain is `GB`."
60
+ )
61
+ )
62
+
63
+
64
+ class CreateOrderParameters(BaseModel):
65
+ model_config = ConfigDict(validate_default=True)
66
+ currency_code: Literal["USD"] = Field(
67
+ ...,
68
+ description="Currency code of the amount."
69
+ )
70
+ items: List[LineItem] = Field(
71
+ ...,
72
+ description="List of individual items in the order (max 50)."
73
+ )
74
+ discount: float = Field(
75
+ 0,
76
+ description="The discount amount for the order."
77
+ )
78
+ shipping_cost: float = Field(
79
+ 0,
80
+ description="The cost of shipping for the order."
81
+ )
82
+ shipping_address: Optional[ShippingAddress] = Field(
83
+ None,
84
+ description="The shipping address for the order."
85
+ )
86
+ notes: Optional[str] = Field(
87
+ None,
88
+ description="Optional customer notes or instructions."
89
+ )
90
+ return_url: Optional[HttpUrl] = Field(
91
+ "https://example.com/returnUrl",
92
+ description="URL to redirect the buyer after approval."
93
+ )
94
+ cancel_url: Optional[HttpUrl] = Field(
95
+ "https://example.com/cancelUrl",
96
+ description="URL to redirect the buyer if they cancel."
97
+ )
98
+
99
+
100
+ class OrderIdParameters(BaseModel):
101
+ order_id: str
102
+
103
+ class CaptureOrderParameters(BaseModel):
104
+ order_id: str
105
+
106
+
107
+ class CreateProductParameters(BaseModel):
108
+ name: str
109
+ type: Literal['PHYSICAL', 'DIGITAL', 'SERVICE'] # Enum-like behavior for product type
110
+ description: Optional[str] = None
111
+ category: Optional[str] = None
112
+ image_url: Optional[HttpUrl] = None # Ensures valid URL
113
+ home_url: Optional[HttpUrl] = None # Ensures valid URL
114
+
115
+ class ListProductsParameters(BaseModel):
116
+ page: Optional[int] = None
117
+ page_size: Optional[int] = None
118
+ total_required: Optional[bool] = None
119
+
120
+ class ShowProductDetailsParameters(BaseModel):
121
+ product_id: str
122
+
123
+ # Frequency Schema
124
+ class FrequencySchema(BaseModel):
125
+ interval_unit: Literal['DAY', 'WEEK', 'MONTH', 'YEAR'] = Field(..., description="The unit of time for the billing cycle.")
126
+ interval_count: int = Field(..., description="The number of units for the billing cycle.")
127
+
128
+ # Pricing Scheme Schema
129
+ class FixedPriceSchema(BaseModel):
130
+ currency_code: Literal['USD'] = Field(..., description="The currency code for the fixed price.")
131
+ value: str = Field(..., description="The value of the fixed price.")
132
+
133
+ class PricingSchemeSchema(BaseModel):
134
+ fixed_price: Optional[FixedPriceSchema] = Field(None, description="The fixed price for the subscription plan.")
135
+ version: Optional[str] = Field(None, description="The version of the pricing scheme.")
136
+
137
+ # Billing Cycle Schema
138
+ class BillingCycleSchema(BaseModel):
139
+ frequency: FrequencySchema = Field(..., description="The frequency of the billing cycle.")
140
+ tenure_type: Literal['REGULAR', 'TRIAL'] = Field(..., description="The type of billing cycle tenure.")
141
+ sequence: int = Field(..., description="The sequence of the billing cycle.")
142
+ total_cycles: Optional[int] = Field(None, description="The total number of cycles in the billing plan.")
143
+ pricing_scheme: PricingSchemeSchema = Field(..., description="The pricing scheme for the billing cycle.")
144
+
145
+ # Setup Fee Schema
146
+ class SetupFeeSchema(BaseModel):
147
+ currency_code: Optional[Literal['USD']] = Field(None, description="The currency code for the setup fee.")
148
+ value: Optional[str] = Field(None, description="The value of the setup fee.")
149
+
150
+ # Payment Preferences Schema
151
+ class PaymentPreferencesSchema(BaseModel):
152
+ auto_bill_outstanding: Optional[bool] = Field(None, description="Indicates whether to automatically bill outstanding amounts.")
153
+ setup_fee: Optional[SetupFeeSchema] = Field(None, description="The setup fee for the subscription plan.")
154
+ setup_fee_failure_action: Optional[Literal['CONTINUE', 'CANCEL']] = Field(None, description="The action to take if the setup fee payment fails.")
155
+ payment_failure_threshold: Optional[int] = Field(None, description="The number of failed payments before the subscription is canceled.")
156
+
157
+ # Taxes Schema
158
+ class TaxesSchema(BaseModel):
159
+ percentage: Optional[str] = Field(None, description="The tax percentage.")
160
+ inclusive: Optional[bool] = Field(None, description="Indicates whether the tax is inclusive.")
161
+
162
+ # Create Subscription Plan Parameters
163
+ class CreateSubscriptionPlanParameters(BaseModel):
164
+ product_id: str = Field(..., description="The ID of the product for which to create the plan.")
165
+ name: str = Field(..., description="The subscription plan name.")
166
+ description: Optional[str] = Field(None, description="The subscription plan description.")
167
+ billing_cycles: List[BillingCycleSchema] = Field(..., description="The billing cycles of the plan.")
168
+ payment_preferences: PaymentPreferencesSchema = Field(..., description="The payment preferences for the subscription plan.")
169
+ taxes: Optional[TaxesSchema] = Field(None, description="The tax details.")
170
+
171
+ # List Subscription Plans Parameters
172
+ class ListSubscriptionPlansParameters(BaseModel):
173
+ product_id: Optional[str] = Field(None, description="The ID of the product for which to get subscription plans.")
174
+ page: Optional[int] = Field(None, description="The page number of the result set to fetch.")
175
+ page_size: Optional[int] = Field(None, description="The number of records to return per page (maximum 100).")
176
+ total_required: Optional[bool] = Field(None, description="Indicates whether the response should include the total count of plans.")
177
+
178
+ # Show Subscription Plan Details Parameters
179
+ class ShowSubscriptionPlanDetailsParameters(BaseModel):
180
+ plan_id: str = Field(..., description="The ID of the subscription plan to show.")
181
+
182
+ # Name Schema
183
+ class NameSchema(BaseModel):
184
+ given_name: Optional[str] = Field(None, description="The subscriber given name.")
185
+ surname: Optional[str] = Field(None, description="The subscriber last name.")
186
+
187
+ # Address Schema
188
+ class AddressSchema(BaseModel):
189
+ address_line_1: str = Field(..., description="The first line of the address.")
190
+ address_line_2: Optional[str] = Field(None, description="The second line of the address.")
191
+ admin_area_1: str = Field(..., description="The city or locality.")
192
+ admin_area_2: str = Field(..., description="The state or province.")
193
+ postal_code: str = Field(..., description="The postal code.")
194
+ country_code: Literal['US'] = Field(..., description="The country code.")
195
+
196
+ # Shipping Address Schema
197
+ class ShippingAddressSchema(BaseModel):
198
+ name: Optional[NameSchema] = Field(None, description="The subscriber shipping address name.")
199
+ address: Optional[AddressSchema] = Field(None, description="The subscriber shipping address.")
200
+
201
+ # Payment Method Schema
202
+ class PaymentMethodSchema(BaseModel):
203
+ payer_selected: Literal['PAYPAL', 'CREDIT_CARD'] = Field(..., description="The payment method selected by the payer.")
204
+ payee_preferred: Optional[Literal['IMMEDIATE_PAYMENT_REQUIRED', 'INSTANT_FUNDING_SOURCE']] = Field(None, description="The preferred payment method for the payee.")
205
+
206
+ # Shipping Amount Schema
207
+ class ShippingAmountSchema(BaseModel):
208
+ currency_code: Literal['USD'] = Field(..., description="The currency code for the shipping amount.")
209
+ value: str = Field(..., description="The value of the shipping amount.")
210
+
211
+ # Subscriber Schema
212
+ class SubscriberSchema(BaseModel):
213
+ name: Optional[NameSchema] = Field(None, description="The subscriber name.")
214
+ email_address: Optional[str] = Field(None, description="The subscriber email address.")
215
+ shipping_address: Optional[ShippingAddressSchema] = Field(None, description="The subscriber shipping address.")
216
+
217
+ # Application Context Schema
218
+ class ApplicationContextSchema(BaseModel):
219
+ brand_name: str = Field(..., description="The brand name.")
220
+ locale: Optional[str] = Field(None, description="The locale for the subscription.")
221
+ shipping_preference: Optional[Literal['SET_PROVIDED_ADDRESS', 'GET_FROM_FILE']] = Field(None, description="The shipping preference.")
222
+ user_action: Optional[Literal['SUBSCRIBE_NOW', 'CONTINUE']] = Field(None, description="The user action.")
223
+ return_url: str = Field(..., description="The return URL after the subscription is created.")
224
+ cancel_url: str = Field(..., description="The cancel URL if the user cancels the subscription.")
225
+ payment_method: Optional[PaymentMethodSchema] = Field(None, description="The payment method details.")
226
+
227
+ # Create Subscription Parameters
228
+ class CreateSubscriptionParameters(BaseModel):
229
+ plan_id: str = Field(..., description="The ID of the subscription plan to create.")
230
+ quantity: Optional[int] = Field(None, description="The quantity of the product in the subscription.")
231
+ shipping_amount: Optional[ShippingAmountSchema] = Field(None, description="The shipping amount for the subscription.")
232
+ subscriber: Optional[SubscriberSchema] = Field(None, description="The subscriber details.")
233
+ application_context: Optional[ApplicationContextSchema] = Field(None, description="The application context for the subscription.")
234
+
235
+ # Show Subscription Details Parameters
236
+ class ShowSubscriptionDetailsParameters(BaseModel):
237
+ subscription_id: str = Field(..., description="The ID of the subscription to show details.")
238
+
239
+ class Reason(BaseModel):
240
+ reason: str = Field(..., description="Reason for Cancellation.")
241
+
242
+ # Cancel Subscription Parameters
243
+ class CancelSubscriptionParameters(BaseModel):
244
+ subscription_id: str = Field(..., description="The ID of the subscription to cancel.")
245
+ payload: Reason = Field(..., description="Reason for cancellation.")
246
+