-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaystack_payment.py
45 lines (34 loc) · 1.05 KB
/
paystack_payment.py
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
import os
import requests
from dotenv import load_dotenv
load_dotenv()
PAYSTACK_SECRET_KEY = os.getenv('PAYSTACK_SECRET_KEY')
def create_paystack_payment(amount, email, reference):
"""
Create a payment request with Paystack.
Args:
amount (int): The payment amount in kobo (for NGN).
email (str): The customer's email.
reference (str): Unique transaction reference.
Returns:
dict: Paystack payment response.
"""
headers = {
"Authorization": f"Bearer {PAYSTACK_SECRET_KEY}",
"Content-Type": "application/json"
}
data = {
"email": email,
"amount": amount, # In kobo for NGN
"reference": reference
}
response = requests.post("https://api.paystack.co/transaction/initialize", json=data, headers=headers)
return response.json()
# Example usage
if __name__ == "__main__":
payment = create_paystack_payment(
50000,
"tx_ref_001",
)
print(payment)