Skip to main content

Python 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:

  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.

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

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.

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.

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.

import twikey

tx = twikey.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)

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.

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. 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

twikey_api_python-0.2.3.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twikey_api_python-0.2.3-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file twikey_api_python-0.2.3.tar.gz.

File metadata

  • Download URL: twikey_api_python-0.2.3.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for twikey_api_python-0.2.3.tar.gz
Algorithm Hash digest
SHA256 dff9427e3e2cf0710c1cede620e029c4b447f0c145f934f2a3fac938697d53c6
MD5 ad5ac794544254ad7a9835371649b68b
BLAKE2b-256 d0ef9f4562c97ca1ad32557f72bf9bf8ce794995932a4aef6ca30301b2a0142f

See more details on using hashes here.

File details

Details for the file twikey_api_python-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for twikey_api_python-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 424e8b635f3bad24e9f6d8ee53d1e8f8442bfc6d4ddc8dd023bd8f07f262bdbb
MD5 6103ffd35b3f13fb64012db0b283e79a
BLAKE2b-256 b1fa358a74b782eae31b0c2a7bc450446453a596acfad848c4f3d6f4d39a1f1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page