diff --git a/examples/1-new-payment.py b/examples/1-new-payment.py index bc72995d..5512be15 100644 --- a/examples/1-new-payment.py +++ b/examples/1-new-payment.py @@ -21,7 +21,7 @@ def main(): # # Initialize the Mollie API library with your API key. # - # See: https://www.mollie.nl/beheer/account/profielen/ + # See: https://www.mollie.com/dashboard/settings/profiles # mollie = Mollie.API.Client() mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') diff --git a/examples/10-customer-payment-history.py b/examples/10-customer-payment-history.py new file mode 100644 index 00000000..39652395 --- /dev/null +++ b/examples/10-customer-payment-history.py @@ -0,0 +1,70 @@ +# coding=utf-8 +# +# Example 10 - Retrieving the payment history for a customer +# +from __future__ import print_function + +import sys, os, time, flask + +# +# Add Mollie library to module path so we can import it. +# This is not necessary if you use pip or easy_install. +# +sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../')) + +import Mollie + +def main(): + try: + # + # Initialize the Mollie API library with your API key. + # + # See: https://www.mollie.com/dashboard/settings/profiles + # + mollie = Mollie.API.Client() + mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') + + body = '' + + customer_id = flask.request.args.get('customer_id') + + # If no customer ID was provided in the URL, we grab the first customer + if customer_id is None: + customers = mollie.customers.all() + + body += '

No customer ID specified. Attempting to retrieve all customers and grabbing the first.

' + + if int(customers['totalCount']) == 0: + body += '

You have no customers. You can create one from the examples.

' + return body + + for customer in customers: + customer_id = customer['id'] + break + + customer = mollie.customers.get(customer_id) + + amount_of_payments_to_retrieve = 20 + + # + # Retrieve the latest payments for the customer + # + # See: https://www.mollie.com/nl/docs/reference/customers/list-payments + # + payments = mollie.customer_payments.withParentId(customer_id).all(offset=0, count=amount_of_payments_to_retrieve) + + body += '

Customer "%s" has %s payments

' % (customer['id'], payments['totalCount']) + + if int(payments['totalCount']) > amount_of_payments_to_retrieve: + body += '

Note: Only showing first %s payments

' % amount_of_payments_to_retrieve + + for payment in payments: + body += "

Payment %s (%s) EUR

" % (payment['id'], payment['amount']) + + return body + + except Mollie.API.Error as e: + return 'API call failed: ' + e.message + +if __name__ == '__main__': + print(main()) diff --git a/examples/2-webhook-verification.py b/examples/2-webhook-verification.py index ce6061e8..e67dbc50 100644 --- a/examples/2-webhook-verification.py +++ b/examples/2-webhook-verification.py @@ -20,7 +20,7 @@ def main(): # # Initialize the Mollie API library with your API key. # - # See: https://www.lib.nl/beheer/account/profielen/ + # See: https://www.mollie.com/dashboard/settings/profiles # mollie = Mollie.API.Client() mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') diff --git a/examples/4-ideal-payment.py b/examples/4-ideal-payment.py index 19284052..eaccc9df 100644 --- a/examples/4-ideal-payment.py +++ b/examples/4-ideal-payment.py @@ -21,7 +21,7 @@ def main (): # # Initialize the Mollie API library with your API key. # - # See: https://www.lib.nl/beheer/account/profielen/ + # See: https://www.mollie.com/dashboard/settings/profiles # mollie = Mollie.API.Client() mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') diff --git a/examples/5-payments-history.py b/examples/5-payments-history.py index 96ccaace..12c09e0e 100644 --- a/examples/5-payments-history.py +++ b/examples/5-payments-history.py @@ -20,7 +20,7 @@ def main(): # # Initialize the Mollie API library with your API key. # - # See: https://www.lib.nl/beheer/account/profielen/ + # See: https://www.mollie.com/dashboard/settings/profiles # mollie = Mollie.API.Client() mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') diff --git a/examples/6-list-activated-methods.py b/examples/6-list-activated-methods.py index 8b22b883..5ab5120d 100644 --- a/examples/6-list-activated-methods.py +++ b/examples/6-list-activated-methods.py @@ -20,7 +20,7 @@ def main(): # # Initialize the Mollie API library with your API key. # - # See: https://www.mollie.nl/beheer/account/profielen/ + # See: https://www.mollie.com/dashboard/settings/profiles # mollie = Mollie.API.Client() mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') diff --git a/examples/7-new-customer.py b/examples/7-new-customer.py new file mode 100644 index 00000000..f14ea6df --- /dev/null +++ b/examples/7-new-customer.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# +# Example 7 - How to create a new customer with the Mollie API. +# +from __future__ import print_function + +import sys, os, flask + +# +# Add Mollie library to module path so we can import it. +# This is not necessary if you use pip or easy_install. +# +sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../')) + +import Mollie + + +def main(): + try: + # + # Initialize the Mollie API library with your API key. + # + # See: https://www.mollie.com/dashboard/settings/profiles + # + mollie = Mollie.API.Client() + mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') + + # + # See: https://www.mollie.com/nl/docs/reference/customers/create + # + customer = mollie.customers.create({ + 'name': 'Mr. First Customer', + 'email': 'first.customer@example.com', + 'locale': 'nl_NL' + }) + + return "Created new customer '%s' (%s)" % (customer['name'], customer['email']) + + except Mollie.API.Error as e: + return 'API call failed: ' + e.message + + +if __name__ == '__main__': + print(main()) diff --git a/examples/8-list-customers.py b/examples/8-list-customers.py new file mode 100644 index 00000000..f73986ef --- /dev/null +++ b/examples/8-list-customers.py @@ -0,0 +1,78 @@ +# coding=utf-8 +# +# Example 8 - Retrieving all of your customers with offset and count +# +from __future__ import print_function + +import sys, os + +# +# Add Mollie library to module path so we can import it. +# This is not necessary if you use pip or easy_install. +# +sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../')) + +import Mollie + + +def main(): + try: + # + # Initialize the Mollie API library with your API key. + # + # See: https://www.mollie.com/dashboard/settings/profiles + # + mollie = Mollie.API.Client() + mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') + + amount_of_customers_to_retrieve = 20 + + # + # Get the latest 20 customers + # + # See: https://www.mollie.com/nl/docs/reference/customers/list + # + customers = mollie.customers.all(offset=0, count=amount_of_customers_to_retrieve) + + body = '

Your API key has %u customers.

' % int(customers['totalCount']) + + if int(customers['totalCount']) == 0: + return body + + if int(customers['totalCount']) > amount_of_customers_to_retrieve: + body += '

Note: Only the first %s are shown here.

' % amount_of_customers_to_retrieve + + body += """ + + + + + + + + + + + + """ + + for customer in customers: + body += '' + body += '' % customer['id'] + body += '' % customer['name'] + body += '' % customer['email'] + body += '' % \ + customer['id'] + body += '' + + body += "
IDNameEmailPayment creationPayment History
%s%s%sCreate payment for customerShow payment history' % \ + customer['id'] + body += '
" + + return body + + except Mollie.API.Error as e: + return 'API call failed: ' + e.message + +if __name__ == '__main__': + print(main()) diff --git a/examples/9-create-customer-payment.py b/examples/9-create-customer-payment.py new file mode 100644 index 00000000..c1d7e01d --- /dev/null +++ b/examples/9-create-customer-payment.py @@ -0,0 +1,76 @@ +# coding=utf-8 +# +# Example 9 - Creating a payment for a customer +# +from __future__ import print_function + +import sys, os, time, flask +from app import database_write + +# +# Add Mollie library to module path so we can import it. +# This is not necessary if you use pip or easy_install. +# +sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../')) + +import Mollie + + +def main(): + try: + # + # Initialize the Mollie API library with your API key. + # + # See: https://www.mollie.com/dashboard/settings/profiles + # + mollie = Mollie.API.Client() + mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp') + + body = '' + + customer_id = flask.request.args.get('customer_id') + + # If no customer ID was provided in the URL, we grab the first customer + if customer_id is None: + customers = mollie.customers.all() + + body += '

No customer ID specified. Attempting to retrieve all customers and grabbing the first.

' + + if int(customers['totalCount']) == 0: + body += '

You have no customers. You can create one from the examples.

' + return body + + for customer in customers: + customer_id = customer['id'] + break + + customer = mollie.customers.get(customer_id) + + # + # Generate a unique order number for this example. It is important to include this unique attribute + # in the redirectUrl (below) so a proper return page can be shown to the customer. + # + order_nr = int(time.time()) + + # + # See: https://www.mollie.com/nl/docs/reference/customers/create-payment + # + payment = mollie.customer_payments.withParentId(customer_id).create({ + 'amount': (time.time() % 15) * 3, # Create some variety in the payment amounts + 'description': 'My first API payment', + 'webhookUrl': flask.request.url_root + '2-webhook-verification?order_nr=' + str(order_nr), + 'redirectUrl': flask.request.url_root + '3-return-page?order_nr=' + str(order_nr), + 'metadata': { + 'order_nr': order_nr + } + }) + + database_write(order_nr, payment['status']) + + return '

Created payment of %s EUR for %s (%s)

' % (payment['amount'], customer['name'], customer['id']) + + except Mollie.API.Error as e: + return 'API call failed: ' + e.message + +if __name__ == '__main__': + print(main()) diff --git a/examples/app.py b/examples/app.py index 2b4019f4..f85651c3 100644 --- a/examples/app.py +++ b/examples/app.py @@ -8,7 +8,11 @@ '3-return-page', '4-ideal-payment', '5-payments-history', - '6-list-activated-methods' + '6-list-activated-methods', + '7-new-customer', + '8-list-customers', + '9-create-customer-payment', + '10-customer-payment-history' ]