-
Notifications
You must be signed in to change notification settings - Fork 55
/
05-payments-history.py
43 lines (31 loc) · 1.1 KB
/
05-payments-history.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
# Example: How to retrieve your payments history.
#
import os
from mollie.api.client import Client
from mollie.api.error import Error
def main():
try:
#
# Initialize the Mollie API library with your API key.
#
# See: https://www.mollie.com/dashboard/settings/profiles
#
api_key = os.environ.get("MOLLIE_API_KEY", "test_test")
mollie_client = Client()
mollie_client.set_api_key(api_key)
#
# Get the first page of payments for this API key ordered by newest.
#
payments = mollie_client.payments.list()
body = ""
if not len(payments):
body += "<p>You have no payments. You can create one from the examples.</p>"
return body
body += "<p>Showing the first page of payments for this API key</p>"
for payment in payments:
body += f'{payment.amount["currency"]} {payment.amount["value"]}, status: \'{payment.status}\'<br>'
return body
except Error as err:
return f"API call failed: {err}"
if __name__ == "__main__":
print(main())