It's hard to believe, but e-commerce still only accounts for about 10% of all retail purchases in the United States. The runway for growth is enormous, which helps explain why the two companies we'll be looking at today -- Shopify (NYSE:SHOP) and Square (NYSE:SQ) -- have done so well: Each has both an e-commerce presence and a finger in brick-and-mortar sales.

Over the past three years, the two stocks have produced average returns of 500%. But between them, which company is the better buy moving forward?

Blank point-of-sale screen inside of a store

Image source: Getty Images

Obviously, we can't answer that with 100% certainty. But by comparing them on three different facets of performance, we can get a better idea of which is a more intriguing buy at today's prices.

Financial fortitude

When investigating financial fortitude, there's one question you should ask above all else: How would this company be affected by a prolonged economic downturn?

Companies with lots of debt and meager cash flows are often in trouble -- they're forced to narrow their scope and cede market share just to stay afloat. Those with lots of cash, on the other hand, have options, like buying back stock or acquiring rivals to gain market share.

Here's how Shopify and Square stack up in terms of financial fortitude.

Companies Cash Debt Free Cash Flow
Shopify $2 billion $0 ($19 million)
Square $1.6 billion $900 million $234 million

Data source: Yahoo! Finance. Cash includes short and long-term investments. Free cash flow presented on a trailing twelve-month basis.

Both companies are decidedly on firm footing, and would likely continue to gain market share from a downturn. I would argue, however, that Shopify is slightly better positioned. 

Shopify has no debt to speak of, which gives it more flexibility in a pinch. And while some may balk at the company's negative free cash flow, that is more management's choice -- it could easily turn on the free cash flow spigot should circumstances require such a move.

Square would be just fine in a downturn, too, but Shopify would have more options.

Winner = Shopify

Valuation

Next we have valuation, which is a decidedly difficult task. Since there's no one metric that tells investors if a stock is "cheap" or "expensive", we can consult a number of different data points.

Companies P/E P/FCF PEG Ratio P/S
Shopify 602 N/A 9.1 22.5
Square 158 130 2.1 9.3

Data source: Yahoo! Finance, E*Trade. P/E = price to earnings. P/FCF = price to free cash flow. PEG = price to earnings growth. P/S = price to sales. P/E presented using non-GAAP earnings. 

Putting all of this data together, it should be clear that both of these stocks would be considered pricey by almost any standard. But between the two, Square is demonstrably cheaper...on every valuation metric.

Winner = Square

Sustainable competitive advantages

Finally, we have the most important aspect worth investigating: each company's sustainable competitive advantage, or its moat.

Shopify's moat comes in two forms. The first is via high switching costs: When up-and-coming e-tailers use a single platform to manage their website, track sales, ship products, and collect payments, they don't want to go through the hassle of changing platforms. They want to focus on whatever service or product they're offering. That leads Shopify clients to stay with it for the long haul.

But Shopify also benefits from powerful network effects -- each additional merchant that joins makes the platform more powerful. But it's not as straight-forward as you may think. Shopify has an App Store where third-party merchants can build tools for users. Those third-parties love that Shopify has over 800,000 merchants. More merchants mean more incentive for third-party tools, which leads to more merchants -- a virtuous cycle.

Square, on the other hand, is primarily a payments processor for small and medium-sized businesses. This is a decidedly low-moat business -- there's little locking customers in for the long-haul, or preventing competition from coming in.

As my colleague Adam Levy discussed last year, however, Square is forming a moat via its ecosystem. Specifically, the company is tailoring additional services -- like the ability to manage multiple locations, paying employees, and tracking inventory -- toward larger clients. Such services also result in higher switching-costs once merchants are locked in.

That being said, I consider Shopify's moat to be wider, and give it the nod here.

Winner = Shopify

And my winner is...

So there you have it. Both of these companies are worthy investments, but Shopify's slightly better financial fortitude and wider moat give it the edge -- even though its stock is pricier.

I've given both companies out-perform ratings on my CAPS profile, but only Shopify has earned a spot in my real-life portfolio, garnering a 7% allocation. If you have to choose between the two, I suggest starting with Shopify. But they are both worthy of research in building up your market-beating nest egg.