Package: liquichain-api-python
Liquichain API client for PythonAccepting Licoin, Paypal, online payments without fixed monthly costs or any punishing registration procedures. Just use the Liquichain API to receive payments directly on your website or easily refund transactions to your customers.RequirementsTo use the Liquichain API client, the following things are required:Get yourself a freeLiquichain account. No sign up costs.Create a newWebsite profileto generate API keys and setup your webhook.Now you're ready to use the Liquichain API client in test mode.Followa few stepsto enable payment methods in live mode, and let us handle the rest.Python >= 3.6Up-to-date OpenSSL (or other SSL/TLS toolkit)Liquichain API client for Python has a dependency onRequestsandRequests-OAuthlibInstallationBy far the easiest way to install the Liquichain API client is to install it withpip. The command below will install the latest released version of the client.$ pip install liquichain-api-pythonYou may also git checkout ordownload all the files, and include the Liquichain API client manually.Create and activate a Python >= 3.6 virtual environment (inside a git checkout or downloaded archive).$ cd liquichain-api-python
$ python -m venv .venv
$ source .venv/bin/activateInstall the additional requirements for the examples, then install the Liquichain API client itself.$ pip install flask
$ pip install -e .Run the examples.export LIQUICHAIN_API_KEY=test_YourApiKey
$ python examples/app.pyHow to receive paymentsTo successfully receive a payment, these steps should be implemented:Use the Liquichain API client to create a payment with the requested amount, tocken symbol (LIC for licoin), description and optionally, a payment method. It is important to specify a unique redirect URL where the customer is supposed to return to after the payment is completed.Immediately after the payment is completed, our platform will send an asynchronous request to the configured webhook to allow the payment details to be retrieved, so you know when exactly to start processing the customer's order.The customer returns, and should be satisfied to see that the order was paid and is now being processed.Find our full documentation online ondocs.liquichain.io.Getting startedImporting the Liquichain API Clientfromliquichain.api.clientimportClientInitializing the Liquichain API client, and setting your API keyliquichain_client=Client()liquichain_client.set_api_key('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM')Creating a new payment.payment=liquichain_client.payments.create({'amount':{'currency':'LIC','value':'0.00000001'},'description':'My first API payment','redirectUrl':'https://webshop.example.org/order/12345/','webhookUrl':'https://webshop.example.org/liquichain-webhook/',})After creation, the payment id is available in thepayment.idproperty. You should store this id with your order.After storing the payment id you can send the customer to the checkout using thepayment.checkout_url.For a payment create example, seeExample 1 - New Payment.In general, request body parameters for an API endpoint should be added to a dictionary and provided as the first argument (ordatakeyword argument). Query string parameters can be provided as keyword arguments.Retrieving paymentsWe can use thepayment.idto retrieve a payment and check if the paymentisPaid.payment=liquichain_client.payments.get(payment.id)ifpayment.is_paid():print('Payment received.')Or retrieve a collection of payments.payments=liquichain_client.payments.list()For an extensive example of listing payments with the details and status, seeExample 5 - Payments History.Payment webhookWhen the status of a payment changes thewebhookUrlwe specified in the creation of the payment will be called.There we can use theidfrom our POST parameters to check te status and act upon that, seeExample 2 - Webhook verification.Multicurrency (paying with tokens)Payments using liquichain tokens is now supported.
A full list of available tokens can be foundin our documentation.payment=liquichain_client.payments.create({'amount':{'currency':'TOK','value':'10.00'},'description':'Order #12345','redirectUrl':'https://webshop.example.org/order/12345/','webhookUrl':'https://webshop.example.org/liquichain-webhook/',})After the customer completes the payment, thepayment.settlement_amountwill contain the amount + currency that will be settled on your account.Refunding paymentsThe API also supports refunding payments. Note that there is no confirmation and that all refunds are immediate and
definitive. Refunds are only supported for Licoin. Other types of payments cannot be refunded through our API at the moment.payment=liquichain_client.payments.get(payment.id)# Refund € 2 of this paymentrefund=liquichain_client.refunds.on(payment).create({'amount':{'currency':'LCN','value':'0.0000000001'}})For a working example, seeExample 11 - Refund payment.Oauth2Athttps://docs.liquichain.io/oauth/getting-startedthe oauth process is explained. Please read this first.Oauth authentication process redirects back to your application. Therefore you should expose your local web server (the examples) as public urls. A webservice likengrok.comcan help you with that. Make sure to set REDIRECT_URI accordingly.Run the oauth2 examples:FLASK_APP=examples/oauth/app.py \
CLIENT_ID=your_client_id \
CLIENT_SECRET=your_client_secret \
REDIRECT_URI=https://your_domain.tld/callback \
flask runThe Authorize endpoint is the endpoint on the Liquichain web site where the merchant logs in, and grants authorization to your client application. E.g. when the merchant clicks on the Connect with Liquichain button, you should redirect the merchant to the Authorize endpoint.The resource owner can then grant the authorization to your client application for the scopes you have requested.Liquichain will then redirect the resource owner back to theredirect_uriyou have specified. The redirect_uri will be appended with a code parameter, which will contain the auth token. At the redirect_uri, you should extract that token, and use it to request a regular oauth token.Initializing via oauth2You should implement theget_tokenandset_tokenmethods yourself. They should retrieve and store the oauth token that is sent from Liquichain somewhere in your application (f.i. in the database).The token data is a python dict.These are example methods, you should use a storage method that fits your application.defget_token():""":return: token (dict) or None"""ifos.path.exists('token.json'):withopen('token.json','r')asfile:returnjson.loads(file.read())defset_token(token):""":param token: token (dict):return: None"""withopen('token.json','w')asfile:file.write(json.dumps(token))liquichain_client=Client()is_authorized,authorization_url=liquichain_client.setup_oauth(client_id,client_secret,redirect_uri,scope,get_token(),set_token,)# When "is_authorized" is False, you need to redirect the user to the authorization_url.# After the user confirmed she is redirected back to your redirect_uri.# The view on this uri should call setup_oauth_authorization_response(), with authorization_response as parameter.# This is the full callback URL (string)liquichain.setup_oauth_authorization_response(authorization_response)# The token will be stored via your `set_token` method for future use. Expired tokens will be refreshed by the client automatically.# Now You can query the API:liquichain.organizations.get('me')API documentationIf you wish to learn more about our API, please visit theLiquichain Developer Portal. 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.LicenseBSD (Berkeley Software Distribution) License.
Copyright (c) 2014-2020,Mollie B.V.whose original source code comes fromSupportContact:liquichain.io