-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbtcpay_payment.py
46 lines (35 loc) · 1.03 KB
/
btcpay_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
46
import requests
import os
from dotenv import load_dotenv
load_dotenv()
BTCPAY_API_KEY = os.getenv('BTCPAY_API_KEY')
BTCPAY_BASE_URL = "https://your-btcpay-server.com"
def create_btcpay_invoice(amount, currency, buyer_email):
"""
Create an invoice in BTCPay Server.
Args:
amount (float): The amount to charge.
currency (str): Currency (e.g., "USD", "BTC").
buyer_email (str): Buyer's email.
Returns:
dict: BTCPay invoice response.
"""
headers = {
"Authorization": f"token {BTCPAY_API_KEY}",
"Content-Type": "application/json"
}
data = {
"price": amount,
"currency": currency,
"buyerEmail": buyer_email
}
response = requests.post(f"{BTCPAY_BASE_URL}/api/v1/invoices", json=data, headers=headers)
return response.json()
# Example usage
if __name__ == "__main__":
invoice = create_btcpay_invoice(
0.001,
"BTC",
)
print(invoice)