API based approach for accepting Ethereum payments with php

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.

Money on a table

Why? (businesslike)

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:

  1. Subscriptions through crypto payments is hard
  2. I wanted to get to market ASAP

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

Why? (technically)

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!

The setup

Ok, so the way I solved the problem is the following. My methodology is built around 4 different services:

  • MyEtherWallet (MEW)
  • CoinMarketCap
  • Etherscan.io
  • Telegram BOT API

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.

The process

So from start to finish, what happens when a user selects "Ethereum" and proceeds to the payment?

Step 1
The subscription amount in Euro's is transformed into the amount of ETH we need with the help of CoinMarketCap.

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

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

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

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

That's it

Without any required further knowledge of the underlying blockchain technology you can accept Ethereum payments. As noted above, there are technically more sound implementations. Especially in regards to running out of a passive wallet to use. But it works: Furthermore, every week more platforms emerge that make this process even easier. For example take a look at Munt.

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.


CoinShilling is the first and biggest aggregation website of social crypto currency data. For any help questions, please let me know via my Twitter account: @ernstmul.


- Register
- Releases
- Blog
- Support
Twitter profile picture