-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_paddle_integration.py
More file actions
151 lines (122 loc) · 4.87 KB
/
test_paddle_integration.py
File metadata and controls
151 lines (122 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python3
"""
Test script for Paddle payment integration
Run this to verify that the payment endpoints are working correctly
"""
import os
import sys
import requests
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Add the app directory to Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'app'))
def test_paddle_config():
"""Test that Paddle configuration is loaded correctly"""
try:
from app.config import settings
print("Testing Paddle Configuration:")
print(f"PADDLE_API_KEY: {'✓ Set' if settings.PADDLE_API_KEY else '✗ Not set'}")
print(f"PADDLE_ENVIRONMENT: {settings.PADDLE_ENVIRONMENT}")
print(f"PADDLE_WEBHOOK_SECRET: {'✓ Set' if settings.PADDLE_WEBHOOK_SECRET else '✗ Not set'}")
print(f"PADDLE_PRODUCT_ID: {'✓ Set' if settings.PADDLE_PRODUCT_ID else '✗ Not set'}")
print(f"PADDLE_PRICE_ID: {'✓ Set' if settings.PADDLE_PRICE_ID else '✗ Not set'}")
print(f"Paddle API Base URL: {settings.paddle_api_base_url}")
print(f"Paddle Checkout URL: {settings.paddle_checkout_url}")
return True
except Exception as e:
print(f"✗ Configuration error: {str(e)}")
return False
def test_paddle_sdk():
"""Test that Paddle SDK is installed and importable"""
try:
import paddle_billing # type: ignore
print("✓ Paddle SDK imported successfully")
print(f"Paddle SDK version: {getattr(paddle_billing, '__version__', 'Unknown')}")
return True
except ImportError:
print("⚠ Paddle SDK not available - using requests fallback")
print(" This is OK for basic functionality")
return True # Not a failure, just a warning
def test_payment_routes():
"""Test that payment routes file exists and contains expected endpoints"""
try:
import os
payments_file = os.path.join(os.path.dirname(__file__), 'app', 'routes', 'payments.py')
if not os.path.exists(payments_file):
print("✗ payments.py file not found")
return False
# Read the file and check for expected route definitions
with open(payments_file, 'r') as f:
content = f.read()
expected_routes = [
'@router.post("/create-subscription"',
'@router.get("/subscription/{subscription_id}"',
'@router.post("/webhook"'
]
found_routes = []
for route in expected_routes:
if route in content:
found_routes.append(route)
print(f" ✓ Found: {route}")
else:
print(f" ✗ Missing: {route}")
if len(found_routes) == len(expected_routes):
print("✓ All payment routes are defined in payments.py")
return True
else:
print(f"✗ Only {len(found_routes)}/{len(expected_routes)} routes found")
return False
except Exception as e:
print(f"✗ Route file test failed: {str(e)}")
return False
def test_database_migration():
"""Test that database migration was applied"""
try:
import sqlite3
conn = sqlite3.connect('app.db')
cursor = conn.cursor()
# Check if paddle_customer_id column exists
cursor.execute("PRAGMA table_info(users)")
columns = cursor.fetchall()
column_names = [col[1] for col in columns]
conn.close()
if 'paddle_customer_id' in column_names:
print("✓ paddle_customer_id column exists in users table")
return True
else:
print("✗ paddle_customer_id column not found in users table")
return False
except Exception as e:
print(f"✗ Database migration test failed: {str(e)}")
return False
def main():
"""Run all tests"""
print("🧪 Testing Paddle Payment Integration\n")
tests = [
("Configuration", test_paddle_config),
("Paddle SDK", test_paddle_sdk),
("Payment Routes", test_payment_routes),
("Database Migration", test_database_migration),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n--- {test_name} Test ---")
if test_func():
passed += 1
print()
print(f"📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Paddle integration is ready.")
print("\nNext steps:")
print("1. Set your Paddle API credentials in .env file")
print("2. Configure webhook endpoint: /v1/payments/webhook")
print("3. Test with sandbox environment first")
print("4. Deploy and test production payments")
else:
print("❌ Some tests failed. Please check the errors above.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)