Package: twikey-api-python
Twikey API client for PythonWant 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.RequirementsTo use the Twikey API client, the following things are required:Get yourself aTwikey account.Python >= 3.0Up-to-date OpenSSL (or other SSL/TLS toolkit)Pip InstallationThe easiest way to install the Twikey API client is
withpip.$ pip install twikey-api-pythonHow to create anythingThe 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 onapi.twikey.com.Getting startedInitializing the Twikey API client using the Requests library.
and configure your API key which you can find in theTwikey merchant interface.importtwikeyAPIKEY='apikey_as_found_in_twikey'twikeyClient=twikey.TwikeyClient(APIKEY,"apiurl_as_found_in_twikey")DocumentsInvite 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.importtwikeyct=123# See settings/profile in twikeyinvite=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).FeedOnce 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.importtwikeyclassMyDocumentFeed(twikey.DocumentFeed):defnewDocument(self,doc,evt_time):print("new ",doc["MndtId"])defupdatedDocument(self,original_mandate_number,doc,reason,evt_time):print("update ",doc["MndtId"],"b/c",reason["Rsn"])defcancelDocument(self,doc_number,reason,evt_time):print("cancelled ",doc_number,"b/c",reason["Rsn"])twikey.TwikeyClient.document.feed(MyDocumentFeed())TransactionsSend new transactions and act upon feedback from the bank.importtwikeytx=twikey.TwikeyClient.transaction.create({"mndtId":"CORERECURRENTNL16318","message":"Test Message","ref":"Merchant Reference","amount":10.00,"place":"Here"})FeedimporttwikeyclassMyFeed(twikey.TransactionFeed):deftransaction(self,transaction):print("TX ",transaction.ref,transaction.state)twikey.TwikeyClient.transaction.feed(MyFeed())WebhookWhen wants to inform you about new updates about documents or payments awebhookUrlspecified in your api settings be called.importFlaskimporturllibimporttwikeyAPIKEY='apikey_as_found_in_twikey'app=Flask(__name__)@app.route('/webhook',methods=['GET'])defwebhook(request):payload=urllib.parse.unquote(request.query_string)received_sign=request.headers.get('X-Signature')ifnotreceived_sign:returnFalseiftwikey.Webhook.verify_signature(payload,received_sign,APIKEY):# trigger feed fetchingreturn'Successfully',200return'Forbidden',403if__name__=='__main__':#setup dev serverapp.debug=Trueapp.run(host="0.0.0.0",port=8000)API documentationIf you wish to learn more about our API, please visit theTwikey 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
takepull requests.SupportContact:www.twikey.com