Few companies have provided the type of returns this year that investors have seen from Shopify (NYSE:SHOP), which provides a platform for anyone to build an e-commerce presence, and Square (NYSE:SQ), king of easy and cheap digital payment processing.

SHOP Chart

SHOP data by YCharts

But of the two companies, which is the better buy today? 

That question is impossible to answer with 100% certainty. In fact -- though I judge these match-ups based on a minimum three-year time frame -- when I wrote about these same two companies seven months ago, I sided with Shopify. Since then, Square has out-gained by a whopping 63 percentage points.

Much has changed since May, so when we run the two companies through the gauntlet this time, let's see whose stock comes out looking like a better buy.

Sustainable competitive advantages

In the world of long-term, buy-to-hold investors, there's nothing more important than an underlying company's sustainable competitive advantage, or "moat." A moat is the special something that keeps customers coming back year after year, all while holding the competition at bay.

In May, I called out Shopify's high switching-costs as the primary moat: when companies have all of their e-commerce data on one platform, they are loath to change, both because of the financial costs involved and also the headaches, retraining, and potential downtime that might have to be endured.

Since then, noted short-seller Citron Research has called out Shopify's tactics for recruiting merchants, and challenged the fact that Shopify claims to have 500,000 such sellers using the platform. I'm not worried, but I am disappointed that management has not published a revenue retention metric for its subscription service to help us see just how high the switching costs are.

At the same time, another moat has become more significant since May as well: the network effect. Shopify allows third-party app developers to use the company's platform, and because the company has so many merchants already signed on those app developers are flocking to Shopify. This further incentivizes merchants to join, which could bring in even more merchants.

With Square, my appreciation of the business has changed over the last six months as well. In May I wrote that this was a low-moat business, as payments processing was a very competitive market with low barriers-to-entry. Since then, Shopify has proven its ability to keep customers on board.

Last month, Square announced it was developing a way to support the purchase and sale of bitcoin. This could eventually lead to customers and merchants paying for goods and services with the cryptocurrency. There isn't a huge moat around Square for this reason, but being the first-mover is important, as it could draw early adopters into Square's eco-system.

A bitcoin

Image source: Getty Images

And that ecosystem has shown broad and robust results over the past year. Subscription and service-based revenue -- crucially, the kinds that have high switching costs and include Square Deposit, Square Capital, and Caviar -- grew 84% last quarter. Just as important, the company launched Square register for larger merchants, which because of its data analytics potential also has potentially high switching costs.

Add all of this together, and I'm willing to call this a tie -- whereas Shopify alone got the nod in May.

Winner = Tie

Financial fortitude

Both of these companies are "growth" stories in nature. That means most investors like to see continual redeployment of sales into new opportunities for the future. While there's certainly a time and place for such investments, there's something to be said for a boring pile of cash laying around.

That's because all companies must be prepared for financial crises. There's no telling when they'll come, but there's also no denying that they'll come. Firms with lots of cash on hand can actually benefit from such downturns by buying back stock on the cheap, acquiring rivals, or outspending the competition to gain long-term market share.

Keeping in mind that Square's market capitalization is about 33% larger than Shopify's, here's how they stack up.

Company Cash Debt Free Cash Flow
Shopify $927 million $0 ($22 million)
Square $1.14 billion $354 million $106 million

Data source: Yahoo! Finance, SEC filings. Cash includes long- and short-term debt. Free cash flow presented on trailing twelve month basis.

There's a lot to like from both companies. Square is cash flow positive, which is a big deal for a company at this point in its maturation. And while Shopify isn't, it also isn't losing that much money. The fact that it carries no debt is also a huge plus.

In the end, I think the effect of an economic downturn would have relatively the same effect on both, with neither having an upper hand when it comes to profiting from such a downturn.

Winner = Tie

Valuation

There's no single, magical metric that can tell us how cheap or expensive a stock is. Instead, we can consult multiple data points to get an idea for which is the better value.

Company P/E P/FCF P/S PEG Ratio 
Shopify N/A N/A 18.0 N/A
Square 240 132 6.8 0.8

Data source: Yahoo! Finance, E*Trade. P/E calculated using non-GAAP earnings when applicable.

No one would ever call either of these companies cheap. But Square has the definite advantage of at least being profitable and free cash flow positive. Additionally, a PEG ratio -- which takes earnings growth into account -- below 1.0 is very rare to find in today's market.

For those reasons, I give the nod here to Square.

Winner = Square

My winner is...

So there you have it. We have two fairly wide-moat companies with solid balance sheets. But Square's valuation makes it a better deal at today's prices. 

This was a surprising finding for me, as I don't own shares of Square, but Shopify accounts for 4% of my real-life holdings. Because of this, I'm going to consider whether Square needs to be added as well, and give the company an outperform rating in my own CAPS profile. The emergence of a moat, and the company's play on crytocurrencies, is enough to warrant further research.

Brian Stoffel owns shares of Shopify. The Motley Fool owns shares of and recommends Shopify. The Motley Fool owns shares of Square. The Motley Fool has a disclosure policy.