twikey-api-python


Nametwikey-api-python JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/twikey/twikey-api-python
SummaryPython interface with the Twikey api
upload_time2023-09-14 11:24:00
maintainer
docs_urlNone
authorTwikey
requires_python>=3.6
licenseMIT
keywords twikey api payments
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://cdn.twikey.com/img/logo.png" height="64"/>
</p>
<h1 align="center">Twikey API client for Python</h1>

Want to allow your customers to pay in the most convenient way, then Twikey is right what you need.

Recurring or occasional payments via (Recurring) Credit Card, SEPA Direct Debit or any other payment method by bringing 
your own payment service provider or by leveraging your bank contract.

Twikey offers a simple and safe multichannel solution to negotiate and collect recurring (or even occasional) payments.
Twikey has integrations with a lot of accounting and CRM packages. It is the first and only provider to operate on a
European level for Direct Debit and can work directly with all major Belgian and Dutch Banks. However you can use the
payment options of your favorite PSP to allow other customers to pay as well.

## Requirements ##

To use the Twikey API client, the following things are required:

+ Get yourself a [Twikey account](https://www.twikey.com).
+ Python >= 3.0
+ Up-to-date OpenSSL (or other SSL/TLS toolkit)

## Pip Installation ##

The easiest way to install the Twikey API client is 
with [pip](https://pip.pypa.io).

    $ pip install twikey-api-python

## How to create anything ##

The api works the same way regardless if you want to create a mandate, a transaction, an invoice or even a paylink.
the following steps should be implemented:

1. Use the Twikey API client to create or import your item.

2. Once available, our platform will send an asynchronous request to the configured webhook
   to allow the details to be retrieved. As there may be multiple items ready for you a "feed" endpoint is provided
   which acts like a queue that can be read until empty till the next time.

3. The customer returns, and should be satisfied to see that the action he took is completed.

Find our full documentation online on [api.twikey.com](https://api.twikey.com).

## Getting started ##

Initializing the Twikey API client using the Requests library. 
and configure your API key which you can find in the [Twikey merchant interface](https://www.twikey.com).

```python
import twikey

APIKEY = 'apikey_as_found_in_twikey'
twikeyClient = twikey.TwikeyClient(APIKEY, "apiurl_as_found_in_twikey")
``` 

## Documents

Invite a customer to sign a SEPA mandate using a specific behaviour template (ct) that allows you to configure 
the behaviour or flow that the customer will experience. This 'ct' can be found in the template section of the settings.

```python
import twikey

ct = 123 # See settings/profile in twikey

invite = twikey.TwikeyClient.document.create({
   "ct": ct,
   "email": "info@twikey.com",
   "firstname": "Info",
   "lastname": "Twikey"
})
```

_After creation, the link available in invite['url'] can be used to redirect the customer into the signing flow or even 
send him a link through any other mechanism. Ideally you store the mandatenumber for future usage (eg. sending transactions)._


### Feed

Once signed, a webhook is sent (see below) after which you can fetch the detail through the document feed, which you can actually
think of as reading out a queue. Since it'll return you the changes since the last time you called it.

```python
import twikey

class MyDocumentFeed(twikey.DocumentFeed):
    def newDocument(self, doc, evt_time):
        print("new ", doc["MndtId"])

    def updatedDocument(self, original_mandate_number, doc, reason, evt_time):
        print("update ", doc["MndtId"], "b/c", reason["Rsn"])

    def cancelDocument(self, doc_number, reason, evt_time):
        print("cancelled ", doc_number, "b/c", reason["Rsn"])

twikey.TwikeyClient.document.feed(MyDocumentFeed())
```

## Transactions

Send new transactions and act upon feedback from the bank.

```python
import twikey

tx = twikey.TwikeyClient.transaction.create({
   "mndtId" : "CORERECURRENTNL16318",
   "message" : "Test Message",
   "ref" : "Merchant Reference",
   "amount" : 10.00, 
   "place" : "Here"
})
```

### Feed

```python
import twikey

class MyFeed(twikey.TransactionFeed):
    def transaction(self, transaction):
        print("TX ", transaction.ref, transaction.state)

twikey.TwikeyClient.transaction.feed(MyFeed())
```

## Webhook ##

When wants to inform you about new updates about documents or payments a `webhookUrl` specified in your api settings be called.  

```python
import Flask 
import urllib
import twikey

APIKEY = 'apikey_as_found_in_twikey'
app = Flask(__name__)

@app.route('/webhook', methods=['GET'])
def webhook(request):
   payload = urllib.parse.unquote(request.query_string)
   received_sign = request.headers.get('X-Signature')
   if not received_sign:
      return False
   if twikey.Webhook.verify_signature(payload,received_sign,APIKEY):
      # trigger feed fetching
      return 'Successfully', 200
   return 'Forbidden', 403

if __name__ == '__main__':
   #setup dev server
   app.debug = True
   app.run(host = "0.0.0.0",port=8000)
```

## API documentation ##

If you wish to learn more about our API, please visit the [Twikey Api Page](https://api.twikey.com).
API Documentation is available in English.

## Want to help us make our API client even better? ##

Want to help us make our API client even better? We
take [pull requests](https://github.com/twikey/twikey-api-python/pulls). 

## Support ##

Contact: [www.twikey.com](https://www.twikey.com)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/twikey/twikey-api-python",
    "name": "twikey-api-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "twikey api payments",
    "author": "Twikey",
    "author_email": "support@twikey.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/30/8feb7332c698f5ca7ae15cfb970fd7ae62a521235269249d459bc8dd19da/twikey-api-python-0.2.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://cdn.twikey.com/img/logo.png\" height=\"64\"/>\n</p>\n<h1 align=\"center\">Twikey API client for Python</h1>\n\nWant to allow your customers to pay in the most convenient way, then Twikey is right what you need.\n\nRecurring or occasional payments via (Recurring) Credit Card, SEPA Direct Debit or any other payment method by bringing \nyour own payment service provider or by leveraging your bank contract.\n\nTwikey offers a simple and safe multichannel solution to negotiate and collect recurring (or even occasional) payments.\nTwikey has integrations with a lot of accounting and CRM packages. It is the first and only provider to operate on a\nEuropean level for Direct Debit and can work directly with all major Belgian and Dutch Banks. However you can use the\npayment options of your favorite PSP to allow other customers to pay as well.\n\n## Requirements ##\n\nTo use the Twikey API client, the following things are required:\n\n+ Get yourself a [Twikey account](https://www.twikey.com).\n+ Python >= 3.0\n+ Up-to-date OpenSSL (or other SSL/TLS toolkit)\n\n## Pip Installation ##\n\nThe easiest way to install the Twikey API client is \nwith [pip](https://pip.pypa.io).\n\n    $ pip install twikey-api-python\n\n## How to create anything ##\n\nThe api works the same way regardless if you want to create a mandate, a transaction, an invoice or even a paylink.\nthe following steps should be implemented:\n\n1. Use the Twikey API client to create or import your item.\n\n2. Once available, our platform will send an asynchronous request to the configured webhook\n   to allow the details to be retrieved. As there may be multiple items ready for you a \"feed\" endpoint is provided\n   which acts like a queue that can be read until empty till the next time.\n\n3. The customer returns, and should be satisfied to see that the action he took is completed.\n\nFind our full documentation online on [api.twikey.com](https://api.twikey.com).\n\n## Getting started ##\n\nInitializing the Twikey API client using the Requests library. \nand configure your API key which you can find in the [Twikey merchant interface](https://www.twikey.com).\n\n```python\nimport twikey\n\nAPIKEY = 'apikey_as_found_in_twikey'\ntwikeyClient = twikey.TwikeyClient(APIKEY, \"apiurl_as_found_in_twikey\")\n``` \n\n## Documents\n\nInvite a customer to sign a SEPA mandate using a specific behaviour template (ct) that allows you to configure \nthe behaviour or flow that the customer will experience. This 'ct' can be found in the template section of the settings.\n\n```python\nimport twikey\n\nct = 123 # See settings/profile in twikey\n\ninvite = twikey.TwikeyClient.document.create({\n   \"ct\": ct,\n   \"email\": \"info@twikey.com\",\n   \"firstname\": \"Info\",\n   \"lastname\": \"Twikey\"\n})\n```\n\n_After creation, the link available in invite['url'] can be used to redirect the customer into the signing flow or even \nsend him a link through any other mechanism. Ideally you store the mandatenumber for future usage (eg. sending transactions)._\n\n\n### Feed\n\nOnce signed, a webhook is sent (see below) after which you can fetch the detail through the document feed, which you can actually\nthink of as reading out a queue. Since it'll return you the changes since the last time you called it.\n\n```python\nimport twikey\n\nclass MyDocumentFeed(twikey.DocumentFeed):\n    def newDocument(self, doc, evt_time):\n        print(\"new \", doc[\"MndtId\"])\n\n    def updatedDocument(self, original_mandate_number, doc, reason, evt_time):\n        print(\"update \", doc[\"MndtId\"], \"b/c\", reason[\"Rsn\"])\n\n    def cancelDocument(self, doc_number, reason, evt_time):\n        print(\"cancelled \", doc_number, \"b/c\", reason[\"Rsn\"])\n\ntwikey.TwikeyClient.document.feed(MyDocumentFeed())\n```\n\n## Transactions\n\nSend new transactions and act upon feedback from the bank.\n\n```python\nimport twikey\n\ntx = twikey.TwikeyClient.transaction.create({\n   \"mndtId\" : \"CORERECURRENTNL16318\",\n   \"message\" : \"Test Message\",\n   \"ref\" : \"Merchant Reference\",\n   \"amount\" : 10.00, \n   \"place\" : \"Here\"\n})\n```\n\n### Feed\n\n```python\nimport twikey\n\nclass MyFeed(twikey.TransactionFeed):\n    def transaction(self, transaction):\n        print(\"TX \", transaction.ref, transaction.state)\n\ntwikey.TwikeyClient.transaction.feed(MyFeed())\n```\n\n## Webhook ##\n\nWhen wants to inform you about new updates about documents or payments a `webhookUrl` specified in your api settings be called.  \n\n```python\nimport Flask \nimport urllib\nimport twikey\n\nAPIKEY = 'apikey_as_found_in_twikey'\napp = Flask(__name__)\n\n@app.route('/webhook', methods=['GET'])\ndef webhook(request):\n   payload = urllib.parse.unquote(request.query_string)\n   received_sign = request.headers.get('X-Signature')\n   if not received_sign:\n      return False\n   if twikey.Webhook.verify_signature(payload,received_sign,APIKEY):\n      # trigger feed fetching\n      return 'Successfully', 200\n   return 'Forbidden', 403\n\nif __name__ == '__main__':\n   #setup dev server\n   app.debug = True\n   app.run(host = \"0.0.0.0\",port=8000)\n```\n\n## API documentation ##\n\nIf you wish to learn more about our API, please visit the [Twikey Api Page](https://api.twikey.com).\nAPI Documentation is available in English.\n\n## Want to help us make our API client even better? ##\n\nWant to help us make our API client even better? We\ntake [pull requests](https://github.com/twikey/twikey-api-python/pulls). \n\n## Support ##\n\nContact: [www.twikey.com](https://www.twikey.com)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python interface with the Twikey api",
    "version": "0.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/twikey/twikey-api-python/issues",
        "Homepage": "https://github.com/twikey/twikey-api-python",
        "Source Code": "https://github.com/twikey/twikey-api-python"
    },
    "split_keywords": [
        "twikey",
        "api",
        "payments"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68305018a986b2a039a594ac859bfe2d39ab5fe4f331c3cce89af9028d2b8169",
                "md5": "91147c81dfc57951b951235ed0ea5f0e",
                "sha256": "552464d858b82d0f891d0adacdf358ed6e5c45c3ee46faef0f12b4727685e95f"
            },
            "downloads": -1,
            "filename": "twikey_api_python-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "91147c81dfc57951b951235ed0ea5f0e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 12904,
            "upload_time": "2023-09-14T11:23:58",
            "upload_time_iso_8601": "2023-09-14T11:23:58.764601Z",
            "url": "https://files.pythonhosted.org/packages/68/30/5018a986b2a039a594ac859bfe2d39ab5fe4f331c3cce89af9028d2b8169/twikey_api_python-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f308feb7332c698f5ca7ae15cfb970fd7ae62a521235269249d459bc8dd19da",
                "md5": "df6512bb153340390a95e09357fcba92",
                "sha256": "aabd8e5690651288b07150315cfcafee5ef8ea901808c81b869c86baa8c3d7d1"
            },
            "downloads": -1,
            "filename": "twikey-api-python-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "df6512bb153340390a95e09357fcba92",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 14264,
            "upload_time": "2023-09-14T11:24:00",
            "upload_time_iso_8601": "2023-09-14T11:24:00.423470Z",
            "url": "https://files.pythonhosted.org/packages/6f/30/8feb7332c698f5ca7ae15cfb970fd7ae62a521235269249d459bc8dd19da/twikey-api-python-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 11:24:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "twikey",
    "github_project": "twikey-api-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "twikey-api-python"
}
        
Elapsed time: 0.11172s