Skip to content

Commit 3768086

Browse files
committed
Phase 12: Complete Documentation Implementation
✅ User Documentation (8 comprehensive guides): - docs/index.md - Main documentation with API reference - docs/installation.md - Complete installation and setup guide - docs/authentication.md - OAuth 2.0 and credential management - docs/store_management.md - Store creation and management - docs/order_management.md - Order creation and tracking - docs/location_services.md - Location hierarchy and search - docs/price_calculation.md - Delivery cost calculation - docs/error_handling.md - Exception handling patterns ✅ Practical Examples (3 comprehensive examples): - examples/basic_usage.py - SDK initialization and basic operations - examples/create_order.py - Complete order creation workflow - examples/error_handling.py - Error handling patterns and retry logic ✅ Documentation Features: - Comprehensive API reference with all classes and methods - Quick start guide for immediate productivity - Best practices and troubleshooting guidance - Environment configuration (sandbox vs production) - Working code examples for all major features - User-friendly error messages and solutions All documentation includes practical examples, proper error handling, and follows best practices for SDK usage.
1 parent b1ba76e commit 3768086

18 files changed

Lines changed: 2363 additions & 188 deletions

docs/authentication.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Authentication Guide
2+
3+
## Overview
4+
5+
The Pathao Python SDK uses OAuth 2.0 authentication with automatic token management. You need merchant credentials from Pathao to use the API.
6+
7+
## Getting Credentials
8+
9+
1. Contact Pathao to get merchant API access
10+
2. You'll receive:
11+
- Client ID
12+
- Client Secret
13+
- Username (email)
14+
- Password
15+
16+
## Authentication Methods
17+
18+
### Method 1: Direct Parameters
19+
20+
```python
21+
from pathao import PathaoClient
22+
23+
client = PathaoClient(
24+
client_id="your_client_id",
25+
client_secret="your_client_secret",
26+
username="your_email@example.com",
27+
password="your_password",
28+
environment="sandbox" # or "production"
29+
)
30+
```
31+
32+
### Method 2: Environment Variables
33+
34+
```python
35+
import os
36+
from pathao import PathaoClient
37+
38+
# Set environment variables first
39+
os.environ["PATHAO_CLIENT_ID"] = "your_client_id"
40+
os.environ["PATHAO_CLIENT_SECRET"] = "your_client_secret"
41+
os.environ["PATHAO_USERNAME"] = "your_email@example.com"
42+
os.environ["PATHAO_PASSWORD"] = "your_password"
43+
44+
# Create client (will auto-load from environment)
45+
client = PathaoClient(environment="sandbox")
46+
```
47+
48+
### Method 3: .env File
49+
50+
Create `.env` file:
51+
```env
52+
PATHAO_CLIENT_ID=your_client_id
53+
PATHAO_CLIENT_SECRET=your_client_secret
54+
PATHAO_USERNAME=your_email@example.com
55+
PATHAO_PASSWORD=your_password
56+
```
57+
58+
```python
59+
from pathao import PathaoClient
60+
61+
# Will automatically load from .env file
62+
client = PathaoClient(environment="sandbox")
63+
```
64+
65+
## Token Management
66+
67+
The SDK automatically handles token lifecycle:
68+
69+
```python
70+
# Get current access token
71+
token = client.get_access_token()
72+
73+
# Check if token is valid
74+
is_valid = client.is_token_valid()
75+
76+
# Manually refresh token (usually not needed)
77+
client.refresh_token()
78+
```
79+
80+
## Environments
81+
82+
### Sandbox Environment
83+
- For testing and development
84+
- Use `environment="sandbox"`
85+
- API Base URL: `https://courier-api-sandbox.pathao.com`
86+
87+
### Production Environment
88+
- For live operations
89+
- Use `environment="production"`
90+
- API Base URL: `https://api.pathao.com`
91+
92+
## Error Handling
93+
94+
```python
95+
from pathao import PathaoClient, AuthenticationError
96+
97+
try:
98+
client = PathaoClient(
99+
client_id="invalid_id",
100+
client_secret="invalid_secret",
101+
username="invalid@email.com",
102+
password="invalid_password",
103+
environment="sandbox"
104+
)
105+
106+
# This will trigger authentication
107+
token = client.get_access_token()
108+
109+
except AuthenticationError as e:
110+
print(f"Authentication failed: {e}")
111+
```
112+
113+
## Best Practices
114+
115+
1. **Use Environment Variables**: Don't hardcode credentials in your code
116+
2. **Use Sandbox First**: Test with sandbox before production
117+
3. **Handle Auth Errors**: Always wrap API calls in try-catch blocks
118+
4. **Token Caching**: The SDK automatically caches and refreshes tokens
119+
5. **Secure Storage**: Store credentials securely in production
120+
121+
## Example: Complete Setup
122+
123+
```python
124+
import os
125+
from pathao import PathaoClient, AuthenticationError
126+
127+
def create_pathao_client():
128+
"""Create and authenticate Pathao client."""
129+
try:
130+
client = PathaoClient(
131+
client_id=os.getenv("PATHAO_CLIENT_ID"),
132+
client_secret=os.getenv("PATHAO_CLIENT_SECRET"),
133+
username=os.getenv("PATHAO_USERNAME"),
134+
password=os.getenv("PATHAO_PASSWORD"),
135+
environment=os.getenv("PATHAO_ENV", "sandbox")
136+
)
137+
138+
# Test authentication
139+
token = client.get_access_token()
140+
print("✅ Authentication successful")
141+
142+
return client
143+
144+
except AuthenticationError as e:
145+
print(f"❌ Authentication failed: {e}")
146+
return None
147+
148+
# Usage
149+
client = create_pathao_client()
150+
if client:
151+
# Use client for API calls
152+
cities = client.locations.get_cities()
153+
print(f"Found {len(cities.data)} cities")
154+
```

0 commit comments

Comments
 (0)