-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_payout.py
More file actions
242 lines (195 loc) · 8.19 KB
/
test_payout.py
File metadata and controls
242 lines (195 loc) · 8.19 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/env python
"""
Test script for Snippe SDK payout functionality.
Run with: python test_payout.py
"""
import os
import json
import time
from snippe import Snippe
from snippe.exceptions import SnippeError
# Hardcoded API key for testing
API_KEY = "snp_YOUR_API_KEY_HERE"
def test_mobile_payout():
"""Test creating a mobile money payout."""
client = Snippe(API_KEY)
try:
print("=" * 50)
print("Testing Mobile Money Payout")
print("=" * 50)
# Check balance first
print("\n1. Checking current balance...")
balance = client.get_balance()
print(f" Available: {balance.available_balance} {balance.currency}")
print(f" Total: {balance.balance} {balance.currency}")
# Check if sufficient balance
amount = 1000
print(f"\n2. Checking fee for {amount} TZS...")
fee_info = client.calculate_payout_fee(amount)
print(f" Fee: {fee_info.fee_amount} {fee_info.currency}")
print(f" Total needed: {fee_info.total_amount} {fee_info.currency}")
if balance.available_balance < fee_info.total_amount:
print(f"\n⚠️ Insufficient balance! Need {fee_info.total_amount} but have {balance.available_balance}")
return None
# Create mobile payout
print("\n3. Creating mobile payout...")
payout = client.create_mobile_payout(
amount=amount,
recipient_name="Jackson Mushi",
recipient_phone="255755660639",
narration="Test payout from SDK",
metadata={
"test_id": "payout-001",
"environment": "development"
},
idempotency_key=f"test-payout-{int(time.time())}" # Unique timestamp-based key
)
print(f"\n✅ Payout created successfully!")
print(f" Reference: {payout.reference}")
print(f" Status: {payout.status}")
print(f" Amount: {payout.amount.value} {payout.amount.currency}")
print(f" Fee: {payout.fees.value} {payout.fees.currency}")
print(f" Total deducted: {payout.total.value} {payout.total.currency}")
print(f" Channel: {payout.channel.provider}")
print(f" Recipient: {payout.recipient.name} ({payout.recipient.phone})")
if payout.narration:
print(f" Narration: {payout.narration}")
print("\n4. Getting payout status...")
time.sleep(2)
status = client.get_payout(payout.reference)
print(f" Status: {status.status}")
if status.completed_at:
print(f" Completed at: {status.completed_at}")
if status.failure_reason:
print(f" Failure reason: {status.failure_reason}")
return payout
except SnippeError as e:
print(f"\n❌ Error: {e.message}")
print(f" HTTP Code: {e.code}")
print(f" Error Code: {e.error_code}")
return None
finally:
client.close()
def test_list_payouts():
"""Test listing payouts."""
client = Snippe(API_KEY)
try:
print("\n" + "=" * 50)
print("Testing List Payouts")
print("=" * 50)
result = client.list_payouts(limit=5, offset=0)
print(f"\nTotal payouts: {result.total}")
print(f"Showing: {len(result.items)} payouts")
print()
for i, payout in enumerate(result.items, 1):
print(f"{i}. Reference: {payout.reference}")
print(f" Status: {payout.status}")
print(f" Amount: {payout.amount.value} {payout.amount.currency}")
print(f" Recipient: {payout.recipient.name}")
print(f" Created: {payout.created_at}")
print()
except SnippeError as e:
print(f"\n❌ Error: {e.message}")
finally:
client.close()
def test_payout_fee():
"""Test calculating payout fee."""
client = Snippe(API_KEY)
try:
print("\n" + "=" * 50)
print("Testing Calculate Payout Fee")
print("=" * 50)
amount = 5000
fee_info = client.calculate_payout_fee(amount)
print(f"\n✅ Fee calculated successfully!")
print(f"Amount: {fee_info.amount} {fee_info.currency}")
print(f"Fee: {fee_info.fee_amount} {fee_info.currency}")
print(f"Total: {fee_info.total_amount} {fee_info.currency}")
except SnippeError as e:
print(f"\n❌ Error: {e.message}")
finally:
client.close()
def test_bank_payout():
"""Test creating a bank transfer payout."""
client = Snippe(API_KEY)
try:
print("\n" + "=" * 50)
print("Testing Bank Transfer Payout")
print("=" * 50)
# Check balance first
print("\n1. Checking current balance...")
balance = client.get_balance()
print(f" Available: {balance.available_balance} {balance.currency}")
print(f" Total: {balance.balance} {balance.currency}")
# Test with a small amount
amount = 2000
print(f"\n2. Checking fee for {amount} TZS...")
fee_info = client.calculate_payout_fee(amount)
print(f" Fee: {fee_info.fee_amount} {fee_info.currency}")
print(f" Total needed: {fee_info.total_amount} {fee_info.currency}")
if balance.available_balance < fee_info.total_amount:
print(f"\n⚠️ Insufficient balance! Need {fee_info.total_amount} but have {balance.available_balance}")
return None
# Create bank payout
print("\n3. Creating bank transfer payout...")
payout = client.create_bank_payout(
amount=amount,
recipient_name="Jackson Mushi",
recipient_bank="SELCOMPESA", # Using CRDB as example
recipient_account="0755660639", # Example account number
narration="Test bank transfer from SDK",
metadata={
"test_id": "bank-payout-001",
"environment": "development"
},
idempotency_key=f"test-bank-{int(time.time())}"
)
print(f"\n✅ Bank payout created successfully!")
print(f" Reference: {payout.reference}")
print(f" Status: {payout.status}")
print(f" Amount: {payout.amount.value} {payout.amount.currency}")
print(f" Fee: {payout.fees.value} {payout.fees.currency}")
print(f" Total deducted: {payout.total.value} {payout.total.currency}")
print(f" Channel: {payout.channel.type} ({payout.channel.provider})")
print(f" Recipient: {payout.recipient.name}")
print(f" Bank: {payout.recipient.bank}")
print(f" Account: {payout.recipient.account}")
if payout.narration:
print(f" Narration: {payout.narration}")
print("\n4. Getting payout status...")
time.sleep(2)
status = client.get_payout(payout.reference)
print(f" Status: {status.status}")
if status.completed_at:
print(f" Completed at: {status.completed_at}")
if status.failure_reason:
print(f" Failure reason: {status.failure_reason}")
return payout
except SnippeError as e:
print(f"\n❌ Error: {e.message}")
print(f" HTTP Code: {e.code}")
print(f" Error Code: {e.error_code}")
return None
finally:
client.close()
if __name__ == "__main__":
print("🔧 SNIPPE SDK PAYOUT TEST")
print("=" * 50)
print(f"Using API key: {API_KEY[:10]}...{API_KEY[-10:]}")
print()
# Run tests
test_payout_fee()
test_list_payouts()
payout = test_mobile_payout()
if payout:
print("\n✅ Mobile payout test passed!")
else:
print("\n❌ Mobile payout test failed or skipped due to insufficient balance")
# Test bank payout (if balance available)
bank_payout = test_bank_payout()
if bank_payout:
print("\n✅ Bank payout test passed!")
else:
print("\n⚠️ Bank payout test skipped (insufficient balance)")
print("\n" + "=" * 50)
print("Tests completed!")