paybridge 0.1.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.
@@ -0,0 +1,673 @@
1
+ Metadata-Version: 2.4
2
+ Name: paybridge
3
+ Version: 0.1.0
4
+ Summary: Unified payment gateway integration for Python
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: httpx>=0.27
8
+ Requires-Dist: pydantic>=2.0
9
+
10
+ # PayBridge Documentation
11
+
12
+ Unified payment gateway integration for Python developers.
13
+
14
+ PayBridge provides a single interface for integrating multiple payment gateways without rewriting payment logic for every provider.
15
+
16
+ ---
17
+
18
+ # Features
19
+
20
+ - Unified payment API
21
+ - Multiple gateway support
22
+ - Easy provider switching
23
+ - Fallback gateway handling
24
+ - Payment verification
25
+ - Refund support
26
+ - Webhook handling
27
+ - Scalable architecture
28
+ - Developer-friendly API
29
+ - FastAPI support
30
+
31
+ ---
32
+
33
+ # Supported Providers
34
+
35
+ - Paystack
36
+ - Flutterwave
37
+ - Stripe
38
+ - More coming soon
39
+
40
+ ---
41
+
42
+ # Installation
43
+
44
+ Install PayBridge using pip:
45
+
46
+ ```bash
47
+ pip install paybridge
48
+ ```
49
+
50
+ Upgrade to the latest version:
51
+
52
+ ```bash
53
+ pip install --upgrade paybridge
54
+ ```
55
+
56
+ ---
57
+
58
+ # Quick Start
59
+
60
+ ## Import PayBridge
61
+
62
+ ```python
63
+ from paybridge import PayBridge
64
+ ```
65
+
66
+ ---
67
+
68
+ # Initialize a Provider
69
+
70
+ ## Paystack Example
71
+
72
+ ```python
73
+ paybridge = PayBridge(
74
+ provider="paystack",
75
+ secret_key="sk_test_xxxxxxxxx"
76
+ )
77
+ ```
78
+
79
+ ---
80
+
81
+ # Initialize Payment
82
+
83
+ ```python
84
+ response = paybridge.initialize_payment(
85
+ amount=5000,
86
+ email="customer@example.com",
87
+ currency="NGN",
88
+ reference="TXN_001"
89
+ )
90
+
91
+ print(response)
92
+ ```
93
+
94
+ ---
95
+
96
+ # Verify Payment
97
+
98
+ Always verify payments server-side after payment completion.
99
+
100
+ ```python
101
+ verification = paybridge.verify_payment(
102
+ reference="TXN_001"
103
+ )
104
+
105
+ print(verification)
106
+ ```
107
+
108
+ ---
109
+
110
+ # Charge a Customer
111
+
112
+ ```python
113
+ response = paybridge.charge(
114
+ amount=10000,
115
+ email="customer@example.com"
116
+ )
117
+
118
+ print(response)
119
+ ```
120
+
121
+ ---
122
+
123
+ # Refund a Payment
124
+
125
+ ```python
126
+ refund = paybridge.refund(
127
+ reference="TXN_001",
128
+ amount=5000
129
+ )
130
+
131
+ print(refund)
132
+ ```
133
+
134
+ ---
135
+
136
+ # Webhook Handling
137
+
138
+ Webhooks allow your application to receive real-time payment events.
139
+
140
+ ## Flask Example
141
+
142
+ ```python
143
+ from flask import Flask, request
144
+
145
+ app = Flask(__name__)
146
+
147
+ @app.route("/webhook", methods=["POST"])
148
+ def webhook():
149
+ payload = request.json
150
+
151
+ print(payload)
152
+
153
+ return {"status": "success"}
154
+ ```
155
+
156
+ ---
157
+
158
+ # Using Multiple Gateways
159
+
160
+ One of PayBridge’s most powerful features is multi-gateway support.
161
+
162
+ This allows developers to:
163
+ - Create fallback systems
164
+ - Reduce downtime
165
+ - Route payments dynamically
166
+ - Improve reliability
167
+ - Avoid vendor lock-in
168
+
169
+ ---
170
+
171
+ # Initialize Multiple Providers
172
+
173
+ ```python
174
+ from paybridge import PayBridge
175
+
176
+ paystack = PayBridge(
177
+ provider="paystack",
178
+ secret_key="PAYSTACK_SECRET_KEY"
179
+ )
180
+
181
+ flutterwave = PayBridge(
182
+ provider="flutterwave",
183
+ secret_key="FLUTTERWAVE_SECRET_KEY"
184
+ )
185
+ ```
186
+
187
+ ---
188
+
189
+ # Gateway Fallback Example
190
+
191
+ If one provider fails, automatically switch to another.
192
+
193
+ ```python
194
+ try:
195
+ response = paystack.initialize_payment(
196
+ amount=5000,
197
+ email="customer@example.com"
198
+ )
199
+
200
+ except Exception:
201
+ response = flutterwave.initialize_payment(
202
+ amount=5000,
203
+ email="customer@example.com"
204
+ )
205
+
206
+ print(response)
207
+ ```
208
+
209
+ ---
210
+
211
+ # Dynamic Provider Selection
212
+
213
+ ```python
214
+ def get_provider(currency):
215
+ if currency == "NGN":
216
+ return paystack
217
+
218
+ return flutterwave
219
+
220
+
221
+ provider = get_provider("NGN")
222
+
223
+ response = provider.initialize_payment(
224
+ amount=10000,
225
+ email="customer@example.com"
226
+ )
227
+
228
+ print(response)
229
+ ```
230
+
231
+ ---
232
+
233
+ # Provider Configuration System
234
+
235
+ ```python
236
+ providers = {
237
+ "paystack": PayBridge(
238
+ provider="paystack",
239
+ secret_key="PAYSTACK_SECRET"
240
+ ),
241
+
242
+ "flutterwave": PayBridge(
243
+ provider="flutterwave",
244
+ secret_key="FLUTTERWAVE_SECRET"
245
+ )
246
+ }
247
+ ```
248
+
249
+ Using a provider dynamically:
250
+
251
+ ```python
252
+ selected_provider = providers["paystack"]
253
+
254
+ response = selected_provider.initialize_payment(
255
+ amount=5000,
256
+ email="customer@example.com"
257
+ )
258
+ ```
259
+
260
+ ---
261
+
262
+ # Smart Routing Example
263
+
264
+ ```python
265
+ def route_payment(amount):
266
+ if amount > 100000:
267
+ return flutterwave
268
+
269
+ return paystack
270
+
271
+
272
+ provider = route_payment(5000)
273
+
274
+ response = provider.initialize_payment(
275
+ amount=5000,
276
+ email="customer@example.com"
277
+ )
278
+ ```
279
+
280
+ ---
281
+
282
+ # Retry Logic Example
283
+
284
+ ```python
285
+ providers = [paystack, flutterwave]
286
+
287
+ for provider in providers:
288
+ try:
289
+ response = provider.initialize_payment(
290
+ amount=5000,
291
+ email="customer@example.com"
292
+ )
293
+
294
+ print("Payment initialized successfully")
295
+ break
296
+
297
+ except Exception as e:
298
+ print(f"Provider failed: {e}")
299
+ ```
300
+
301
+ ---
302
+
303
+ # FastAPI Integration
304
+
305
+ This section shows how to integrate PayBridge into a FastAPI application.
306
+
307
+ ---
308
+
309
+ # Install FastAPI Dependencies
310
+
311
+ ```bash
312
+ pip install fastapi uvicorn
313
+ ```
314
+
315
+ ---
316
+
317
+ # Basic FastAPI Integration
318
+
319
+ ```python
320
+ from fastapi import FastAPI
321
+ from paybridge import PayBridge
322
+
323
+ app = FastAPI()
324
+
325
+ paybridge = PayBridge(
326
+ provider="paystack",
327
+ secret_key="sk_test_xxxxxxxxx"
328
+ )
329
+
330
+
331
+ @app.get("/")
332
+ async def home():
333
+ return {"message": "PayBridge API Running"}
334
+
335
+
336
+ @app.post("/initialize-payment")
337
+ async def initialize_payment():
338
+
339
+ response = paybridge.initialize_payment(
340
+ amount=5000,
341
+ email="customer@example.com",
342
+ currency="NGN",
343
+ reference="TXN_001"
344
+ )
345
+
346
+ return response
347
+ ```
348
+
349
+ ---
350
+
351
+ # Run FastAPI Server
352
+
353
+ ```bash
354
+ uvicorn main:app --reload
355
+ ```
356
+
357
+ ---
358
+
359
+ # FastAPI Verify Payment Example
360
+
361
+ ```python
362
+ @app.get("/verify-payment/{reference}")
363
+ async def verify_payment(reference: str):
364
+
365
+ verification = paybridge.verify_payment(
366
+ reference=reference
367
+ )
368
+
369
+ return verification
370
+ ```
371
+
372
+ ---
373
+
374
+ # FastAPI Request Body Example
375
+
376
+ ```python
377
+ from pydantic import BaseModel
378
+
379
+
380
+ class PaymentRequest(BaseModel):
381
+ amount: int
382
+ email: str
383
+ currency: str = "NGN"
384
+
385
+
386
+ @app.post("/pay")
387
+ async def pay(data: PaymentRequest):
388
+
389
+ response = paybridge.initialize_payment(
390
+ amount=data.amount,
391
+ email=data.email,
392
+ currency=data.currency
393
+ )
394
+
395
+ return response
396
+ ```
397
+
398
+ ---
399
+
400
+ # FastAPI Multi-Gateway Example
401
+
402
+ ```python
403
+ from fastapi import FastAPI
404
+ from paybridge import PayBridge
405
+
406
+ app = FastAPI()
407
+
408
+ paystack = PayBridge(
409
+ provider="paystack",
410
+ secret_key="PAYSTACK_SECRET"
411
+ )
412
+
413
+ flutterwave = PayBridge(
414
+ provider="flutterwave",
415
+ secret_key="FLUTTERWAVE_SECRET"
416
+ )
417
+
418
+
419
+ @app.post("/payment")
420
+ async def payment():
421
+
422
+ try:
423
+ response = paystack.initialize_payment(
424
+ amount=5000,
425
+ email="customer@example.com"
426
+ )
427
+
428
+ except Exception:
429
+
430
+ response = flutterwave.initialize_payment(
431
+ amount=5000,
432
+ email="customer@example.com"
433
+ )
434
+
435
+ return response
436
+ ```
437
+
438
+ ---
439
+
440
+ # FastAPI Dynamic Routing Example
441
+
442
+ ```python
443
+ def get_provider(currency: str):
444
+
445
+ if currency == "NGN":
446
+ return paystack
447
+
448
+ return flutterwave
449
+
450
+
451
+ @app.post("/dynamic-payment")
452
+ async def dynamic_payment(data: PaymentRequest):
453
+
454
+ provider = get_provider(data.currency)
455
+
456
+ response = provider.initialize_payment(
457
+ amount=data.amount,
458
+ email=data.email,
459
+ currency=data.currency
460
+ )
461
+
462
+ return response
463
+ ```
464
+
465
+ ---
466
+
467
+ # FastAPI Webhook Example
468
+
469
+ ```python
470
+ from fastapi import Request
471
+
472
+
473
+ @app.post("/webhook")
474
+ async def webhook(request: Request):
475
+
476
+ payload = await request.json()
477
+
478
+ print(payload)
479
+
480
+ return {
481
+ "status": "success"
482
+ }
483
+ ```
484
+
485
+ ---
486
+
487
+ # FastAPI Refund Example
488
+
489
+ ```python
490
+ @app.post("/refund/{reference}")
491
+ async def refund(reference: str):
492
+
493
+ response = paybridge.refund(
494
+ reference=reference,
495
+ amount=5000
496
+ )
497
+
498
+ return response
499
+ ```
500
+
501
+ ---
502
+
503
+ # Environment Variables
504
+
505
+ Never hardcode secret keys in production.
506
+
507
+ ## Example `.env`
508
+
509
+ ```env
510
+ PAYSTACK_SECRET_KEY=sk_test_xxxxx
511
+ FLUTTERWAVE_SECRET_KEY=FLWSECK_TEST_xxxxx
512
+ ```
513
+
514
+ ---
515
+
516
+ # Using python-dotenv
517
+
518
+ ```python
519
+ from dotenv import load_dotenv
520
+ import os
521
+
522
+ load_dotenv()
523
+
524
+ secret_key = os.getenv("PAYSTACK_SECRET_KEY")
525
+ ```
526
+
527
+ ---
528
+
529
+ # Full Integration Example
530
+
531
+ ```python
532
+ from paybridge import PayBridge
533
+
534
+ paybridge = PayBridge(
535
+ provider="paystack",
536
+ secret_key="sk_test_xxxxx"
537
+ )
538
+
539
+ payment = paybridge.initialize_payment(
540
+ amount=5000,
541
+ email="customer@example.com",
542
+ currency="NGN",
543
+ reference="TXN_001"
544
+ )
545
+
546
+ print(payment)
547
+ ```
548
+
549
+ ---
550
+
551
+ # Recommended Architecture
552
+
553
+ ```text
554
+ Client Request
555
+
556
+ FastAPI Routes
557
+
558
+ Payment Service
559
+
560
+ Provider Router
561
+
562
+ Paystack / Flutterwave / Stripe
563
+ ```
564
+
565
+ This architecture provides:
566
+ - Scalability
567
+ - Reliability
568
+ - Easier maintenance
569
+ - Better failover handling
570
+
571
+ ---
572
+
573
+ # Error Handling
574
+
575
+ Always handle payment failures properly.
576
+
577
+ ```python
578
+ try:
579
+ response = paybridge.initialize_payment(
580
+ amount=5000,
581
+ email="customer@example.com"
582
+ )
583
+
584
+ print(response)
585
+
586
+ except Exception as e:
587
+ print(f"Payment failed: {e}")
588
+ ```
589
+
590
+ ---
591
+
592
+ # FastAPI Error Handling
593
+
594
+ ```python
595
+ from fastapi import HTTPException
596
+
597
+
598
+ @app.post("/safe-payment")
599
+ async def safe_payment():
600
+
601
+ try:
602
+
603
+ response = paybridge.initialize_payment(
604
+ amount=5000,
605
+ email="customer@example.com"
606
+ )
607
+
608
+ return response
609
+
610
+ except Exception as e:
611
+
612
+ raise HTTPException(
613
+ status_code=400,
614
+ detail=str(e)
615
+ )
616
+ ```
617
+
618
+ ---
619
+
620
+ # Best Practices
621
+
622
+ - Always verify payments server-side
623
+ - Use environment variables for secret keys
624
+ - Implement webhook verification
625
+ - Add retry mechanisms
626
+ - Log failed transactions
627
+ - Monitor provider downtime
628
+ - Use fallback gateways
629
+ - Track transaction success rates
630
+ - Separate payment logic into services
631
+
632
+ ---
633
+
634
+ # Why PayBridge?
635
+
636
+ PayBridge helps developers:
637
+ - Reduce integration complexity
638
+ - Switch providers easily
639
+ - Build scalable fintech systems faster
640
+ - Avoid vendor lock-in
641
+ - Maintain cleaner codebases
642
+
643
+ ---
644
+
645
+ # Contributing
646
+
647
+ Contributions are welcome.
648
+
649
+ ## Steps
650
+
651
+ 1. Fork the repository
652
+ 2. Create a feature branch
653
+ 3. Commit your changes
654
+ 4. Push to your fork
655
+ 5. Open a pull request
656
+
657
+ ---
658
+
659
+ # License
660
+
661
+ MIT License
662
+
663
+ ---
664
+
665
+ # Support
666
+
667
+ GitHub Repository:
668
+
669
+ https://github.com/zinsu-moni/paybridge
670
+
671
+ Issues:
672
+
673
+ https://github.com/zinsu-moni/paybridge/issues