The KyberWidget WooCommerce plugin allows developers to easily add a cryptocurrency payment gateway to Wordpress sites.
- PHP version 7.2+
- WordPress 3.8+
- WooCommerce 3.0+
- Clone the code repo to your
cd <PATH>/wp-content/plugins/ git clone https://github.com/KyberNetwork/widget-woocommerce
- Install the required components
- Activate the plugin
From ZIP file
Download the plugin zip file here
Unzip to your WordPress folder
Activate the plugin in
After activation, you will find the plugin settings in your WordPress Dashboard under WooCommerce->Payment. Enabling the plugin will add an option to pay with tokens on your checkout page.
The configuration in this plugin is based on the widget configuration from the Widget Generator, and is modified to fit the WooCommerce model. Plugin settings include:
|The title to be displayed for the KyberWidget WooCommerce payment option for users in the checkout pages.||Kyber Payment Gateway|
|Describe what the payment gateway is for. It will be displayed under the payment options.||Pay with tokens|
|Wallet address to receive the payment. This address is required. Without this address, payment will not be processed||0xf6d420FAB01826386e39664770299eADD68617da|
|Token symbol of the token you want to receive from payments. The token must be supported by Kyber Network.||KNC|
|ETH network that the payment gateway will run in. Options are: ||Ropsten|
|Behavior of how the widget will appear to the user. Either ||popup|
|Node endpoint to check tx status. If you do not have one, create one using Infura||https://ropsten.infura.io/v3/fb1b33|
|Number of block confirmations to finalize the transaction||40|
|Registered ETH address that is part of the fee sharing program||0x2B522cABE9950D1153c26C1b399B293CaA99FcF9|
These parameters are defined in the widget as payment gateway settings in Woocommerce and also defined in the source file
The main logic of handling payments through the widget is defined in the source file
This plugin allows an e-commerce website using WooCommerce to accept payments with any token. Below is a sample walkthrough to use this plugin after installation and activation.
- Configure plugin settings.
- Set item prices in fiat.
- Item prices will be displayed in fiat.
- When checking out, pay your shopping cart using any token by selecting the Kyber Payment Gateway option.
- When the user pays for his shopping cart using the Kyber Payment Gateway, the KyberWidget will handle the rest. With the KyberWidget, user can pay using any tokens (supported by Kyber) and you (the vendor) will receive the token of your choice.
- The widget will return the transaction hash for the payment. The plugin will use this transaction hash for checking the transaction status.
- When the transaction succeeds, the order status will change from
Processing. At this stage, the website admin or vendor will receive a notification about the successful payment of the cart, and will start processing the shipment of the products.
- When the transaction fails, the order status will change from
Order created ->
Pending payment ->
On-Hold (payment broadcasted & mornitored) ->
Processing (successful payment) OR
Failed (failed payment)
In order to check if the payment is successful, we use widget-monitor-php to monitor the transaction.
This plugin will retrieve the transaction receipt from the blockchain and return its status as well as validate the payment. It provides 2 modes for monitoring the tx status:
useIntervalLoop or none. The
useIntervalLoop plugin will continuously query a node to get the tx receipt until it reaches the desired block confirmation number. Note that this approach will consume a lot of server resources if there are many orders on-hold and block confirmation numbers are large.
We recommend using a cronjob to check the order tx status periodically. We are already using wp_cron to monitor every 30 seconds. You can install and use WP Crontrol to view and edit that job.
The cron jobs above will run upon every page load. This approach has 2 main issues:
- As with any heavy job, it will slow down the page for users
- It is dependent on the user request to run the cronjob. Therefore, it is recommended to disable the WordPress default cronjob and setup a Linux (server) cronjob using crontab.
Here is a guide on how to do this:
Install crontab (if your server does not have it as default). You may need to search for instruction for your distro (Centos, RHEL, etc).
- Add the following line in order to run every minute to check the tx status.
* * * * * curl http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1
Please make sure you use correct path to wp-cron.php.
Alternatively, you can use WP-cli
* * * * * cd /var/www/example.com/htdocs; wp cron event run --due-now > /dev/null 2>&1
- You will need to disable WordPress default wp-cron. Add following to wp-config.php.
- Finally, restart crontab service so the new job can run.
sudo service cron restart
If you are a developer and want to contribute, please check out the following guidelines for contributing to the Woocommerce Kyber Widget repository.