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)

        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_client.customers.list()

            body += '<p>No customer ID specified. Attempting to retrieve the first page of '
            body += 'customers and grabbing the first.</p>'

            if not len(customers):
                body += '<p>You have no customers. You can create one from the examples.</p>'
                return body

            customer = next(customers)
        else:
            customer = mollie_client.customers.get(customer_id)

        #
        # Generate a unique webshop 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.
        #
        my_webshop_id = int(time.time())

        #
        # See: https://www.mollie.com/nl/docs/reference/customers/create-payment
        #
        payment = mollie_client.customer_payments.with_parent_id(customer.id).create({
            'amount': {
                'currency': 'EUR',
                'value': '100.00'
            },
            'description': 'My first API payment',
            'webhookUrl': '{root}02-webhook_verification'.format(root=flask.request.url_root),
            'redirectUrl': '{root}03-return-page?my_webshop_id={id}'.format(
                root=flask.request.url_root, id=my_webshop_id),
            'metadata': {
                'my_webshop_id': str(my_webshop_id)
            },
        })
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        return '<p>Created payment of {curr} {value} for {cust} ({id})<p>'.format(
            curr=payment.amount['currency'], value=payment.amount['value'], cust=customer.name, id=customer.id)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
示例#2
0
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)

        #
        # Generate a unique webshop order id 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.
        #
        my_webshop_id = int(time.time())

        #
        # Payment parameters:
        # amount        Currency and value. This example creates a € 120,- payment.
        # description   Description of the payment.
        # webhookUrl    Webhook location, used to report when the payment changes state.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        #
        payment = mollie_client.payments.create({
            'amount': {
                'currency': 'EUR',
                'value': '120.00'
            },
            'description':
            'My first API payment',
            'webhookUrl':
            '{root}02-webhook_verification'.format(
                root=flask.request.url_root),
            'redirectUrl':
            '{root}03-return-page?my_webshop_id={id}'.format(
                root=flask.request.url_root, id=my_webshop_id),
            'metadata': {
                'my_webshop_id': str(my_webshop_id)
            }
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
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)

        #
        # Generate a unique webshop order id 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.
        #
        my_webshop_id = int(time.time())

        #
        # Payment parameters:
        # amount        Currency and value. This example creates a € 120,- payment.
        # description   Description of the payment.
        # webhookUrl    Webhook location, used to report when the payment changes state.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        #
        payment = mollie_client.payments.create({
            'amount': {
                'currency': 'EUR',
                'value': '120.00'
            },
            'description': 'My first API payment',
            'webhookUrl': '{root}02-webhook_verification'.format(root=flask.request.url_root),
            'redirectUrl': '{root}03-return-page?my_webshop_id={id}'.format(root=flask.request.url_root,
                                                                            id=my_webshop_id),
            'metadata': {
                'my_webshop_id': str(my_webshop_id)
            }
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
示例#4
0
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')

        #
        # 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())

        #
        # Payment parameters:
        # amount        Amount in EUROs. This example creates a € 10,- payment.
        # description   Description of the payment.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        #
        payment = mollie.payments.create({
            'amount':
            10.00,
            '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
            }
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        database_write(order_nr, payment['status'])

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.getPaymentUrl())

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
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)

        #
        # Retrieve the payment's current state.
        #
        if 'id' not in flask.request.form:
            flask.abort(404, 'Unknown payment id')

        payment_id = flask.request.form['id']
        payment = mollie_client.payments.get(payment_id)
        my_webshop_id = payment.metadata['my_webshop_id']

        #
        # Update the order in the database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        if payment.is_paid():
            #
            # At this point you'd probably want to start the process of delivering the product to the customer.
            #
            return 'Paid'
        elif payment.is_pending():
            #
            # The payment has started but is not complete yet.
            #
            return 'Pending'
        elif payment.is_open():
            #
            # The payment has not started yet. Wait for it.
            #
            return 'Open'
        else:
            #
            # The payment isn't paid, pending nor open. We can assume it was aborted.
            #
            return 'Cancelled'

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
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)

        #
        # Retrieve the payment's current state.
        #
        if 'id' not in flask.request.form:
            flask.abort(404, 'Unknown payment id')

        payment_id = flask.request.form['id']
        payment = mollie_client.payments.get(payment_id)
        my_webshop_id = payment.metadata['my_webshop_id']

        #
        # Update the order in the database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        if payment.is_paid():
            #
            # At this point you'd probably want to start the process of delivering the product to the customer.
            #
            return 'Paid'
        elif payment.is_pending():
            #
            # The payment has started but is not complete yet.
            #
            return 'Pending'
        elif payment.is_open():
            #
            # The payment has not started yet. Wait for it.
            #
            return 'Open'
        else:
            #
            # The payment isn't paid, pending nor open. We can assume it was aborted.
            #
            return 'Cancelled'

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
示例#7
0
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')

        #
        # Retrieve the payment's current state.
        #
        if 'id' not in flask.request.form:
            flask.abort(404, 'Unknown payment id')

        payment_id = flask.request.form['id']
        payment = mollie.payments.get(payment_id)
        order_nr = payment['metadata']['order_nr']

        #
        # Update the order in the database.
        #
        database_write(order_nr, payment['status'])

        if payment.isPaid():
            #
            # At this point you'd probably want to start the process of delivering the product to the customer.
            #
            return 'Paid'
        elif payment.isPending():
            #
            # The payment has started but is not complete yet.
            #
            return 'Pending'
        elif payment.isOpen():
            #
            # The payment has not started yet. Wait for it.
            #
            return 'Open'
        else:
            #
            # The payment isn't paid, pending nor open. We can assume it was aborted.
            #
            return 'Cancelled'

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
def main():
    try:
        #
        # Initialize the Mollie API library with your API key.
        #
        # See: https://www.lib.nl/beheer/account/profielen/
        #
        mollie = Mollie.API.Client()
        mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp')

        #
        # Retrieve the payment's current state.
        #
        if 'id' not in flask.request.form:
            flask.abort(404, 'Unknown payment id')

        payment_id = flask.request.form['id']
        payment = mollie.payments.get(payment_id)
        order_nr = payment['metadata']['order_nr']

        #
        # Update the order in the database.
        #
        database_write(order_nr, payment['status'])

        if payment.isPaid():
            #
            # At this point you'd probably want to start the process of delivering the product to the customer.
            #
            return 'Paid'
        elif payment.isPending():
            #
            # The payment has started but is not complete yet.
            #
            return 'Pending'
        elif payment.isOpen():
            #
            # The payment has not started yet. Wait for it.
            #
            return 'Open'
        else:
            #
            # The payment isn't paid, pending nor open. We can assume it was aborted.
            #
            return 'Cancelled'

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
示例#9
0
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)
        #
        # After your webhook has been called with the order ID in its body, you'd like
        # to handle the order's status change. This is how you can do that.
        #
        # See: https://docs.mollie.com/reference/v2/orders-api/get-order
        #
        if 'id' not in flask.request.form:
            flask.abort(404, 'Unknown order id')

        order_id = flask.request.form['id']
        order = mollie_client.orders.get(order_id)
        my_webshop_id = order.metadata['my_webshop_id']
        #
        # Update the order in the database.
        #
        data = {'order_id': order.id, 'status': order.status}
        database_write(my_webshop_id, data)

        if order.is_paid() or order.is_authorized():
            #
            # At this point you'd probably want to start the process of delivering the product to the customer.
            #
            return 'Paid'
        if order.is_canceled():
            #
            # At this point you'd probably want to inform the customer that the order has been canceled.
            #
            return 'Canceled'
        if order.is_completed():
            #
            # At this point you could inform the customer that all deliveries to the customer have started.
            #
            return 'Completed'

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
def main():
    try:
        #
        # Initialize the Mollie API library with your API key.
        #
        # See: https://www.mollie.nl/beheer/account/profielen/
        #
        mollie = Mollie.API.Client()
        mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp')

        #
        # 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())

        #
        # Payment parameters:
        # amount        Amount in EUROs. This example creates a € 10,- payment.
        # description   Description of the payment.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        #
        payment = mollie.payments.create({
            'amount': 10.00,
            '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
            }
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        database_write(order_nr, payment['status'])

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.getPaymentUrl())

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
示例#11
0
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)

        # Generate a unique webshop order id for this example.
        my_webshop_id = int(time.time())

        #
        # Order creation parameters.
        #
        # See: https://docs.mollie.com/reference/v2/orders-api/create-order
        #
        order = mollie_client.orders.create({
            'amount': {
                'value': '299.00',
                'currency': 'EUR'
            },
            'billingAddress': {
                'streetAndNumber': 'Keizersgracht 313',
                'city': 'Amsterdam',
                'region': 'Noord-Holland',
                'postalCode': '1234AB',
                'country': 'NL',
                'givenName': 'Piet',
                'familyName': 'Mondriaan',
                'email': '*****@*****.**',
            },
            'shippingAddress': {
                'streetAndNumber': 'Prinsengracht 313',
                'city': 'Haarlem',
                'region': 'Noord-Holland',
                'postalCode': '5678AB',
                'country': 'NL',
                'givenName': 'Chuck',
                'familyName': 'Norris',
                'email': '*****@*****.**'
            },
            'metadata': {
                'my_webshop_id': str(my_webshop_id),
                'description': 'Lego cars'
            },
            'consumerDateOfBirth':
            '1958-01-31',
            'locale':
            'nl_NL',
            'orderNumber':
            '1337',
            'redirectUrl':
            '{root}17-order-return-page?my_webshop_id={id}'.format(
                root=flask.request.url_root, id=my_webshop_id),
            'webhookUrl':
            '{root}13-order-webhook-verification'.format(
                root=flask.request.url_root),
            'lines': [
                {
                    'type': 'physical',
                    'sku': '5702016116977',
                    'name': 'LEGO 42083 Bugatti Chiron',
                    'productUrl':
                    'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
                    'imageUrl':
                    'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
                    'quantity': 1,
                    'vatRate': '21.00',
                    'unitPrice': {
                        'currency': 'EUR',
                        'value': '399.00'
                    },
                    'totalAmount': {
                        'currency': 'EUR',
                        'value': '299.00'
                    },
                    'discountAmount': {
                        'currency': 'EUR',
                        'value': '100.00'
                    },
                    'vatAmount': {
                        'currency': 'EUR',
                        'value': '51.89'
                    }
                },
            ]
        })
        data = {'status': order.status, 'order_id': order.id}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the order payment.
        #
        return flask.redirect(order.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
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 += '<p>No customer ID specified. Attempting to retrieve all customers and grabbing the first.</p>'

            if int(customers['totalCount']) == 0:
                body += '<p>You have no customers. You can create one from the examples.</p>'
                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 '<p>Created payment of %s EUR for %s (%s)<p>' % (
            payment['amount'], customer['name'], customer['id'])

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
示例#13
0
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)

        #
        # First, let the customer pick the bank in a simple HTML form. This step is actually optional.
        #
        if 'issuer' not in flask.request.form:
            body = '<form method="post">Select your bank: <select name="issuer">'
            for issuer in mollie_client.methods.get('ideal',
                                                    include='issuers').issuers:
                body += '<option value="{id}">{issuer}</option>'.format(
                    id=issuer.id, issuer=issuer.name)
            body += '<option value="">or select later</option>'
            body += '</select><button>OK</button></form>'
            return body

        else:
            #
            # Get the posted issuer id.
            #
            issuer_id = None

            if flask.request.form['issuer']:
                issuer_id = str(flask.request.form['issuer'])

        #
        # Generate a unique webshop order id 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.
        #
        my_webshop_id = int(time.time())

        #
        # Payment parameters:
        # amount        Currency and value. This example creates a € 10,- payment.
        # description   Description of the payment.
        # webhookUrl    Webhook location, used to report when the payment changes state.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        # method        Payment method "ideal".
        # issuer        The customer's bank. If empty the customer can select it later.
        #
        payment = mollie_client.payments.create({
            'amount': {
                'currency': 'EUR',
                'value': '10.00'
            },
            'description':
            'My first API payment',
            'webhookUrl':
            '{root}02-webhook_verification'.format(
                root=flask.request.url_root),
            'redirectUrl':
            '{root}03-return-page?my_webshop_id={id}'.format(
                root=flask.request.url_root, id=my_webshop_id),
            'metadata': {
                'my_webshop_id': str(my_webshop_id),
            },
            'method':
            'ideal',
            'issuer':
            issuer_id,
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
示例#14
0
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)

        # Generate a unique webshop order id for this example.
        my_webshop_id = int(time.time())

        #
        # Order creation parameters.
        #
        # See: https://docs.mollie.com/reference/v2/orders-api/create-order
        #
        order = mollie_client.orders.create({
            'amount': {
                'value': '299.00',
                'currency': 'EUR'
            },
            'billingAddress': {
                'streetAndNumber': 'Keizersgracht 313',
                'city': 'Amsterdam',
                'region': 'Noord-Holland',
                'postalCode': '1234AB',
                'country': 'NL',
                'givenName': 'Piet',
                'familyName': 'Mondriaan',
                'email': '*****@*****.**',
            },
            'shippingAddress': {
                'streetAndNumber': 'Prinsengracht 313',
                'city': 'Haarlem',
                'region': 'Noord-Holland',
                'postalCode': '5678AB',
                'country': 'NL',
                'givenName': 'Chuck',
                'familyName': 'Norris',
                'email': '*****@*****.**'
            },
            'metadata': {
                'my_webshop_id': str(my_webshop_id),
                'description': 'Lego cars'
            },
            'consumerDateOfBirth': '1958-01-31',
            'locale': 'nl_NL',
            'orderNumber': '1337',
            'redirectUrl': '{root}17-order-return-page?my_webshop_id={id}'.format(root=flask.request.url_root,
                                                                                  id=my_webshop_id),
            'webhookUrl': '{root}13-order-webhook-verification'.format(root=flask.request.url_root),
            'lines': [
                {
                    'type': 'physical',
                    'sku': '5702016116977',
                    'name': 'LEGO 42083 Bugatti Chiron',
                    'productUrl': 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
                    'imageUrl': 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
                    'quantity': 1,
                    'vatRate': '21.00',
                    'unitPrice': {
                        'currency': 'EUR',
                        'value': '399.00'
                    },
                    'totalAmount': {
                        'currency': 'EUR',
                        'value': '299.00'
                    },
                    'discountAmount': {
                        'currency': 'EUR',
                        'value': '100.00'
                    },
                    'vatAmount': {
                        'currency': 'EUR',
                        'value': '51.89'
                    }
                },

            ]
        })
        data = {'status': order.status, 'order_id': order.id}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the order payment.
        #
        return flask.redirect(order.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
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)

        #
        # First, let the customer pick the bank in a simple HTML form. This step is actually optional.
        #
        if 'issuer' not in flask.request.form:
            body = '<form method="post">Select your bank: <select name="issuer">'
            for issuer in mollie_client.methods.get('ideal', include='issuers').issuers:
                body += '<option value="{id}">{issuer}</option>'.format(id=issuer.id, issuer=issuer.name)
            body += '<option value="">or select later</option>'
            body += '</select><button>OK</button></form>'
            return body

        else:
            #
            # Get the posted issuer id.
            #
            issuer_id = None

            if flask.request.form['issuer']:
                issuer_id = str(flask.request.form['issuer'])

        #
        # Generate a unique webshop order id 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.
        #
        my_webshop_id = int(time.time())

        #
        # Payment parameters:
        # amount        Currency and value. This example creates a € 10,- payment.
        # description   Description of the payment.
        # webhookUrl    Webhook location, used to report when the payment changes state.
        # redirectUrl   Redirect location. The customer will be redirected there after the payment.
        # metadata      Custom metadata that is stored with the payment.
        # method        Payment method "ideal".
        # issuer        The customer's bank. If empty the customer can select it later.
        #
        payment = mollie_client.payments.create({
            'amount': {
                'currency': 'EUR',
                'value': '10.00'
            },
            'description': 'My first API payment',
            'webhookUrl': '{root}02-webhook_verification'.format(root=flask.request.url_root),
            'redirectUrl': '{root}03-return-page?my_webshop_id={id}'.format(
                root=flask.request.url_root, id=my_webshop_id),
            'metadata': {
                'my_webshop_id': str(my_webshop_id),
            },
            'method': 'ideal',
            'issuer': issuer_id,
        })

        #
        # In this example we store the order with its payment status in a database.
        #
        data = {'status': payment.status}
        database_write(my_webshop_id, data)

        #
        # Send the customer off to complete the payment.
        #
        return flask.redirect(payment.checkout_url)

    except Error as err:
        return 'API call failed: {error}'.format(error=err)
def main ():
    try:
        #
        # Initialize the Mollie API library with your API key.
        #
        # See: https://www.lib.nl/beheer/account/profielen/
        #
        mollie = Mollie.API.Client()
        mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp')

        #
        # First, let the customer pick the bank in a simple HTML form. This step is actually optional.
        #
        if 'issuer' not in flask.request.form:
            body = '<form method="post">Select your bank: <select name="issuer">'

            for issuer in mollie.issuers.all():
                if issuer['method'] == Mollie.API.Object.Method.IDEAL:
                    body += '<option value="%s">%s</option>' % (issuer['id'], issuer['name'])

            body += '<option value="">or select later</option>'
            body += '</select><button>OK</button></form>'
            return body

        else:
            #
            # Get the posted issuer id.
            #
            issuer_id = None

            if flask.request.form['issuer']:
                issuer_id = str(flask.request.form['issuer'])

            #
            # 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())

            #
            # Payment parameters:
            # amount        Amount in EUROs. This example creates a € 10,- payment.
            # description   Description of the payment.
            # redirectUrl   Redirect location. The customer will be redirected there after the payment.
            # metadata      Custom metadata that is stored with the payment.
            # method        Payment method "ideal".
            # issuer        The customer's bank. If empty the customer can select it later.
            #
            payment = mollie.payments.create({
                'amount': 10.00,
                'description': 'My first API payment',
                'redirectUrl': flask.request.url_root + '3-return-page?order_nr=' + str(order_nr),
                'metadata': {
                    'order_nr': order_nr
                },
                'method': 'ideal',
                'issuer': issuer_id
            })

            #
            # In this example we store the order with its payment status in a database.
            #
            database_write(order_nr, payment['status'])

            #
            # Send the customer off to complete the payment.
            #
            return flask.redirect(payment.getPaymentUrl())

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message
示例#17
0
def main():
    try:
        #
        # Initialize the Mollie API library with your API key.
        #
        # See: https://www.lib.nl/beheer/account/profielen/
        #
        mollie = Mollie.API.Client()
        mollie.setApiKey('test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp')

        #
        # First, let the customer pick the bank in a simple HTML form. This step is actually optional.
        #
        if 'issuer' not in flask.request.form:
            body = '<form method="post">Select your bank: <select name="issuer">'

            for issuer in mollie.issuers.all():
                if issuer['method'] == Mollie.API.Object.Method.IDEAL:
                    body += '<option value="%s">%s</option>' % (issuer['id'],
                                                                issuer['name'])

            body += '<option value="">or select later</option>'
            body += '</select><button>OK</button></form>'
            return body

        else:
            #
            # Get the posted issuer id.
            #
            issuer_id = None

            if flask.request.form['issuer']:
                issuer_id = str(flask.request.form['issuer'])

            #
            # 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())

            #
            # Payment parameters:
            # amount        Amount in EUROs. This example creates a € 10,- payment.
            # description   Description of the payment.
            # redirectUrl   Redirect location. The customer will be redirected there after the payment.
            # metadata      Custom metadata that is stored with the payment.
            # method        Payment method "ideal".
            # issuer        The customer's bank. If empty the customer can select it later.
            #
            payment = mollie.payments.create({
                'amount':
                10.00,
                'description':
                'My first API payment',
                'redirectUrl':
                flask.request.url_root + '3-return-page?order_nr=' +
                str(order_nr),
                'metadata': {
                    'order_nr': order_nr
                },
                'method':
                'ideal',
                'issuer':
                issuer_id
            })

            #
            # In this example we store the order with its payment status in a database.
            #
            database_write(order_nr, payment['status'])

            #
            # Send the customer off to complete the payment.
            #
            return flask.redirect(payment.getPaymentUrl())

    except Mollie.API.Error as e:
        return 'API call failed: ' + e.message