Ludovic Frank - Freelance developer

Accept cryptocurrency payments (Bitcoin, eGold) as a craftsman

ionicons-v5-k Ludovic Frank Feb 9, 2022
96 reads Level:

Hello hello hello,
Today, we're going to talk about my latest little adventure: enabling a 142-year-old company to accept cryptocurrencies.

Setting the scene

I've been working with Les Frères Marchand, for over a year now, at first we made a website together (it was Ludo Dev CMS's second instance), then we got the urge to create an online cheese shop together, which has been online since September 2021.

On this cheese shop, everything is automated to simplify life for customers and for Frères Marchand.When I say everything is automated, I mean that invoice creation is too... and given that today we're talking about new means of payment... it's important.

What about accepting cryptocurrencies?

Being a big tech fan myself (well, you're on a site called developpeur-freelance.io, so you guessed it). I know the world of cryptocurrencies and I follow it assiduously.

While doing my due diligence I realized that it was possible for Les Frères Marchand to accept cryptocurrencies, so I asked them, "Do you want to accept crypto? ". And the answer was "yes", a company of 142, very open to the future....

Let's look at the constraints on the project

For the company

A company is a little more complicated than managing these personal accounts. There are accounts to keep, tax documents to create (invoices), and I couldn't ask the Frères Marchand accounting department to keep one account per "type of crypto", given that we accept several.
Generally speaking, as Bitcoin is not a state currency, it's not possible for a company to invoice in Bitcoin; you have to invoice in euros.

It is possible for a company to hold cryptocurrency, but then it's called an "asset."

Everything must remain automated as it was before the addition of cryptocurrencies, in the report sent to the cellars, only orders for which payment is certain to be received are sent to preparation.With credit card payment, for example, the info is passed on to the cellars when what we call the "loan" on the card is validated, basically when the bank has authorized us to "block" the funds on the customer's credit card even if the transfer hasn't actually been made yet.

For customers

It was imperative that existing customers who pay by bank card, Google Pay and Apple Pay were not lost. Allow them to continue to use the online cheese shop seamlessly as they always have.
Finally, I didn't want to treat customers wishing to order with cryptocurrency as "second-class" customers, for me it was clear that their experience must be as seamless as those who pay by card, Apple Pay or Google Pay.

How are we going to get there?

The great thing about the Frères Marchand online cheese shop is that it's built with "Ludo Dev E-Shop", itself built on "Symfony" and "Sylius Framework". Do you know what that means? It means I have total freedom to add the payment gateways I want, without depending on anyone else. And that's very important for the future.

Let's take a look at what's available on the market

Coinbase Commerce

First of all, I inevitably came across Coinbase Commerce, as Coinbase is the leader in the cryptocurrency world... They're also present in e-commerce, so I tested their solutions a little, but I didn't choose it, here's why:

  • I find the customer experience perfectible, it's not fluid like I like, it should be hyper simple, I give the amount, I give the address or transfer that amount and it works.
  • From a merchant's point of view, it's not automated at all, let me explain, when a cryptocurrency payment is received, it arrives on a wallet hosted on the platform, it is then necessary to connect to your account.When a cryptocurrency payment is received, it arrives on a wallet hosted on the platform, and then you have to connect to your pro account to transform it into euros and transfer it to the merchant's bank account.

Moue, no, not convinced by coinçasse commerce, at least not for this project.

UTRUST

Being part of the Elrond ecosystem myself (my hero: @ludodev), I was naturally interested in Elrond's latest acquisition, UTRUST.

So I started "playing customer" and testing the customer experience on the dev net.

On blockchain projects, there are often several networks:

  • The devnet: network for app developers.
  • The test net: so that the public can test on a larger scale.
  • Finally, the main net: this is simply the real network, where digital assets really have value, and it can be expensive to use it for testing?

I liked the experiment, it looks like "Stripe", but for crypto, it's not bad.

Time for implementation

The tests were conclusive, so it was time for implementation.
I read the documentation, and it's pretty similar to what Stripe can do, with one difference.

Even though Stripe uses webhooks, they can be quite optional for a normal payment "flow", they're useful for repayment especially (and it's true in some cases to completely validate the imprint on a card).

On a cryptocurrency transaction, payment is completely asynchronous and this is perfectly normal. Some networks, like Elrond, are very quick to process a transaction, while others are more congested (Ethereum, by chance?).

As a result, when the customer exits the payment interface, there is in fact only one validation of the transaction on the network (the blockchain), at which point he is redirected to the "success" page, but the network has not completely validated the transaction.

Therefore, don't take this redirection as a success, but wait for the webhook with the event "ORDER.PAYMENT.RECEIVED" event arrives, but be sure to check that the accompanying state is set to "completed", as during a pre-check the event may trigger not "complete", but "received".

Creating the "order

I'll leave it to you to read the UTRUST doc for this, the thing to know is that prices must be sent as a string and name as an int or float.
The email and first name must be present when the order is created, otherwise the UTRUST API will refuse to create the "order".

Finally, it is absolutely necessary to send three URLs,

  • The return URL: Where do we redirect the customer when we have confirmation from the blockchain?
  • The cancel URL: Where do we redirect them if they cancel their order?
  • Most importantly, webhook URL: Here you have to provide the URL to be called in POST when an event occurs, I think it's very clever to have put it in the request.

It all depends on the SDK used, but for PHP, for example, the SDK allows you to check the array sent to UTRUST before sending the request.think about using it to avoid sending requests to the API for nothing?.

How does the webhook work?

Once you've configured the webhook, you'll receive a POST request to the URL you've entered. Of course, the data is signed, so ! If you don't, anyone can say "The blockchain has confirmed that payment 651 has been validated".

And as I said earlier, the event you're most interested in is "ORDER.PAYMENT.RECEIVED" with the state "complete", at which point you can be sure that the entire network has validated the transaction (on Elrond, this takes 40 seconds).

Video of the premiere

Below you can see the video of the world premiere of the crypto cheese purchase.

Thanks

For this project, thanks go to the following people/groups:

  • Les Frères Marchand: A fine company that blends tradition and modernity and is therefore the first cheesemakers to accept cryptocurrencies.
  • The Elrond France community: The welcome given to Frères Marchand by the French-speaking Elrond community was just crazy, thank you for them!
  • UTRUST: they made themselves available for the few small questions and technical details I asked them about.

Conclusion

The idea of this article is not to rewrite the UTRUST doc, because it's well done, but to give you the little info you need to know if you ever want to integrate cryptocurrency payments into your e-commerce platform.
Have a great week!