mirror of
https://github.com/aljazceru/payments-rest-api.git
synced 2025-12-21 07:24:23 +01:00
example client
This commit is contained in:
32
README.md
32
README.md
@@ -61,4 +61,34 @@ aws cloudformation describe-stacks \
|
|||||||
--stack-name breez-integration \
|
--stack-name breez-integration \
|
||||||
--query 'Stacks[0].Outputs'
|
--query 'Stacks[0].Outputs'
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Output will look like this:
|
||||||
|
```
|
||||||
|
root@2edec8635e65:/# aws cloudformation describe-stacks --stack-name breez-integration --query 'Stacks[0].Outputs'
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"OutputKey": "ApiGatewayBaseURL",
|
||||||
|
"OutputValue": "https://yxzjorems5.execute-api.us-east-1.amazonaws.com/prod",
|
||||||
|
"Description": "Base URL for API Gateway"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"OutputKey": "SendEndpoint",
|
||||||
|
"OutputValue": "https://yxzjorems5.execute-api.us-east-1.amazonaws.com/prod/send_payment",
|
||||||
|
"Description": "Send endpoint URL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"OutputKey": "PaymentsEndpoint",
|
||||||
|
"OutputValue": "https://yxzjorems5.execute-api.us-east-1.amazonaws.com/prod/list_payments",
|
||||||
|
"Description": "Payments endpoint URL"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"OutputKey": "ReceiveEndpoint",
|
||||||
|
"OutputValue": "https://yxzjorems5.execute-api.us-east-1.amazonaws.com/prod/receive_payment",
|
||||||
|
"Description": "Receive endpoint URL"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
```
|
||||||
|
### Example usage
|
||||||
|
You can use example-client.py to test the functionality. Take Base URL from the above output and put it in API_URL in example-client.py
|
||||||
|
API_KEY is the secret you set at the begining.
|
||||||
68
example-client.py
Normal file
68
example-client.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
API_URL = "https://yxzjorems5.execute-api.us-east-1.amazonaws.com/prod"
|
||||||
|
|
||||||
|
API_KEY = "1234567890"
|
||||||
|
|
||||||
|
class BreezClient:
|
||||||
|
def __init__(self):
|
||||||
|
# Load API key from file
|
||||||
|
self.api_url = API_URL
|
||||||
|
self.headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'x-api-key': API_KEY
|
||||||
|
}
|
||||||
|
|
||||||
|
def list_payments(self, from_timestamp=None, to_timestamp=None, offset=None, limit=None):
|
||||||
|
"""List all payments with optional filters."""
|
||||||
|
params = {
|
||||||
|
"from_timestamp": from_timestamp,
|
||||||
|
"to_timestamp": to_timestamp,
|
||||||
|
"offset": offset,
|
||||||
|
"limit": limit
|
||||||
|
}
|
||||||
|
response = requests.get(f"{self.api_url}/list_payments", params=params, headers=self.headers)
|
||||||
|
print(response.json())
|
||||||
|
print(self.headers)
|
||||||
|
return self._handle_response(response)
|
||||||
|
|
||||||
|
def receive_payment(self, amount, method="LIGHTNING"):
|
||||||
|
"""Generate a Lightning/Bitcoin/Liquid invoice to receive payment."""
|
||||||
|
payload = {
|
||||||
|
"amount": amount,
|
||||||
|
"method": method
|
||||||
|
}
|
||||||
|
response = requests.post(f"{self.api_url}/receive_payment", json=payload, headers=self.headers)
|
||||||
|
return self._handle_response(response)
|
||||||
|
|
||||||
|
def send_payment(self, destination, amount=None, drain=False):
|
||||||
|
"""Send a payment via Lightning or Liquid."""
|
||||||
|
payload = {
|
||||||
|
"destination": destination,
|
||||||
|
"amount": amount,
|
||||||
|
"drain": drain
|
||||||
|
}
|
||||||
|
response = requests.post(f"{self.api_url}/send_payment", json=payload, headers=self.headers)
|
||||||
|
return self._handle_response(response)
|
||||||
|
|
||||||
|
def _handle_response(self, response):
|
||||||
|
"""Helper method to handle API responses."""
|
||||||
|
if response.status_code == 200:
|
||||||
|
return response.json()
|
||||||
|
else:
|
||||||
|
return {"error": f"Request failed with status {response.status_code}", "details": response.text}
|
||||||
|
|
||||||
|
# Initialize client
|
||||||
|
breez = BreezClient()
|
||||||
|
|
||||||
|
# Example Usage
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("🔄 Listing Payments...")
|
||||||
|
print(breez.list_payments())
|
||||||
|
|
||||||
|
#print("\n💰 Receiving Payment...")
|
||||||
|
#print(breez.receive_payment(amount=1000, method="LIGHTNING"))
|
||||||
|
|
||||||
|
#print("\n🚀 Sending Payment...")
|
||||||
|
#print(breez.send_payment(destination="lnbc...", amount=1000))
|
||||||
Reference in New Issue
Block a user