12 April 2018 - By Ernst
Note: in this post I give the outline of a way to accept ethereum payments on your own site in an easy manner. That means it's not the best way, it's simply the easiest way without having any blockchain knowledge. Although I mention php in the title (because I use php on this site), the methodology works with other languages as well. Have any feedback? Let me know through my Twitter.
Before I dive into how I managed to build my own crypto currency payment system, it is interesting to look at why I decided to accept crypto payments in the first place, and what made me decided to go for a self-built approach.
After the launch of CoinShilling in December there was one particular point of feedback I kept receiving: "It's funny that you can't pay in crypto currency". Although it does sound weird at first for a crypto related site to not support this, there were however two reason why I didn't support crypto payments:
When a new customer comes in through the Stripe (credit card) process, it is easy. You hook them up to the subscription service, and every period end the credit card gets charged. Little hassle for the customer, and a nice income stream for the merchant. However you can't automatically charge a crypto wallet (which is a good thing btw). Well, there is one way, but asking for the secret key of a wallet isn't a good idea.
So it basically comes down to what is more appealing: forcing clients to pay with a credit card and thus having a better recurring payment rate, or trying to get in on some people only willing to spent their ETH. I choose the latter. Having faith in the product, that after the period end customers won't be able to go without it, and renew regardless.
Going to market ASAP
This speaks for itself. With the crypto hype skyrocketing in December, I needed to get CoinShilling out there as soon as I could. The simple fact that adding another payment method would cost me at least half a day, was something I considered too much. I already reached the MVP with adding the Stripe payment. So launch without crypto payments option.
When I was ready to start implementing a crypto payment platform I turned to Google. Looking for the Strip of crypto. Although I found a few, none of them gave me a feeling of trustworthiness. Platform reviews often mentioned the platform not paying out the received crypto's, so that's a no go. So I posted as question to ProductHunt ASK. The only recommendation that I received was CoinBase. At that time CoinBase had temporarily closed the enrollment of new merchant accounts, so that wasn't an option either. They are now accepting new users again!
Ok, so the way I solved the problem is the following. My methodology is built around 4 different services:
With the help of MEW I created a few wallets. Why a few? Because you can only use one wallet at a time to receive payments. Although smart contracts could be used to negotiate the account the payment is for, this surpasses the "easy" in our implementation.
Since my fiat currency is Euro, and all my subscriptions are priced in euro's, I needed an API to help me convert the EUR to ETH. That's where CoinMarketCap comes to use. Every time a user wants to start an Ethereum payment, the current exchange rate is calculated and used.
Etherscan can be used to track balances of wallets on the Ethereum blockchain. With the help of Etherscan we can register a payment being received.
Telegram BOT API
As mentioned a wallet can only be used for one payment at a time. Depending on the amount of paying customers, and the amount of wallets you created it might happen that there is no wallet available for receiving a new payment. Although I made sure the user is presented with a message to try again later, it could very well happen that this user is forever gone. That's where the Telegram BOT API comes in play. When the scenario arises that there are no free wallets left, the Telegram bot sends a message to me notifying me about the problem so I can quickly add a new wallets.
So from start to finish, what happens when a user selects "Ethereum" and proceeds to the payment?
The subscription amount in Euro's is transformed into the amount of ETH we need with the help of CoinMarketCap.
We check our own database to find a wallet which is currently not being used. If no wallet could be found, sent alert through the Telegram bot.
A new payment is created for the amount due. The payment is linked to the user account, and the passive wallet from step 2. We also add a timestamp to the payment, so we know when it started. This is because the user has limited time to actually pay the amount due, before the wallet is released again for reuse.
Inform the user about the exact amount of ETH he needs to send, and what our public key of the used wallet is. The page also shows the amount of minutes the user has left to complete the payment.
This step is actually a more continuously process. With the help of a timed event (CRON) the script checks the balance of all our wallets every minute. If a raise in the balance is noticed, it adds this amount to the paid amount of the currently running payment for that wallet. If this raise means that the entire amount is paid, we give the user the subscription he choose.
So a user could actually pay his subscription fee from multiple wallets.
Furthermore, every week more platforms emerge that make this process even easier. For example take a look at Munt.
Received my first ETH subscription payment 🔥 pic.twitter.com/cswCVSyuEP— Ernst Mulders (@ernstmul) April 3, 2018
CoinShilling keeps track of social meta data for the top crypto coins. If you want to know more about CoinShilling? I'm building it out in the open! Full transparency in regards to income, users, visitors etc. Follow me on my Twitter to stay posted.