Humble python client to interface with the Twikey api
Project description
Twikey API client for Python
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.
- 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.
$ 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:
-
Use the Twikey API client to create or import your item.
-
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.
-
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.
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.
import twikey
twikeyClient = twikey.TwikeyClient(APIKEY, "https://api.beta.twikey.com")
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.
invite = 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.
import twikey
class MyDocumentFeed(twikey.DocumentFeed):
def newDocument(self, doc):
print("new ", doc["MndtId"])
def updatedDocument(self, doc, reason):
print("update ", doc["MndtId"], "b/c", reason["Rsn"])
def cancelDocument(self, docNumber, reason):
print("cancelled ", docNumber, "b/c", reason["Rsn"])
twikeyClient.document.feed(MyDocumentFeed())
Transactions
Send new transactions and act upon feedback from the bank.
tx = twikeyClient.transaction.create({
"mndtId" : "CORERECURRENTNL16318",
"message" : "Test Message",
"ref" : "Merchant Reference",
"amount" : 10.00,
"place" : "Here"
})
Feed
import twikey
class MyFeed(twikey.TransactionFeed):
def transaction(self, transaction):
print("TX ", transaction.ref, transaction.state)
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.
import Flask
import twikey
app = Flask(__name__)
@app.route('/webhook', methods=['GET'])
def webhook(request):
payload = 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. 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.
Support
Contact: www.twikey.com
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for twikey_api_python-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bde2e331a8a34cd25a69dfebaa86f4ed0bb6231c5cdfdbc32ac5634f78767ba |
|
MD5 | f1fd7e9865180a9d8770e7030ae7d28c |
|
BLAKE2b-256 | 05a60af7683a1fa243b536a6509ff1571ecde023aabe06ea1766021a68542d04 |