-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_pesapal_urls.py
More file actions
72 lines (60 loc) · 2.34 KB
/
Copy pathadd_pesapal_urls.py
File metadata and controls
72 lines (60 loc) · 2.34 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
#!/usr/bin/env python3
"""
Add missing PesaPal URLs to .env file
"""
def add_pesapal_urls():
print("🔧 Adding missing PesaPal URLs to .env file...")
# Read current .env
try:
with open('.env', 'r') as f:
content = f.read()
except FileNotFoundError:
print("❌ .env file not found!")
return False
# URLs to add
missing_urls = []
# Check if callback URL exists
if 'PESAPAL_CALLBACK_URL=' not in content:
missing_urls.append('PESAPAL_CALLBACK_URL=https://denncathy.co.ke/payment/callback')
# Check if notification URL exists
if 'PESAPAL_NOTIFICATION_URL=' not in content:
missing_urls.append('PESAPAL_NOTIFICATION_URL=https://denncathy.co.ke/payment/ipn')
if missing_urls:
# Add the missing URLs to the PesaPal section
pesapal_section = "# 🏦 PesaPal Production Configuration"
if pesapal_section in content:
# Find the end of the PesaPal section
lines = content.split('\n')
insert_index = -1
for i, line in enumerate(lines):
if pesapal_section in line:
# Find the next empty line or different section
for j in range(i + 1, len(lines)):
if lines[j].strip() == '' or lines[j].startswith('# '):
insert_index = j
break
break
if insert_index != -1:
# Insert the missing URLs
for url in missing_urls:
lines.insert(insert_index, url)
insert_index += 1
content = '\n'.join(lines)
else:
# Append to end of file
content += '\n' + '\n'.join(missing_urls)
else:
# Add PesaPal section
content += f'\n\n{pesapal_section}\n' + '\n'.join(missing_urls)
# Write back to .env
with open('.env', 'w') as f:
f.write(content)
print("✅ Added missing PesaPal URLs:")
for url in missing_urls:
print(f" + {url}")
return True
else:
print("ℹ️ All PesaPal URLs already configured")
return False
if __name__ == "__main__":
add_pesapal_urls()