The rise of e-commerce has been a nightmare for big-box retailers. Stores became massive showrooms for online purchases, and mobile price comparison apps forced retailers to match online prices. A wide variety of home delivery options also threaten to reduce foot traffic in stores.

However, investors can profit from the growth of e-commerce by investing in the right stocks. Let's look at three companies -- (NASDAQ:AMZN), Petmed Express (NASDAQ:PETS), and PayPal -- that might be good long-term investment opportunities based on the growth of e-commerce. The 800-pound gorilla
Amazon, the 800-pound gorilla in e-commerce, has an uncanny ability to grow its ecosystem beyond online retail. In 2007, it introduced the Kindle, which streamlined the book delivery process with e-books. In 2011, it turned the Kindle into a color tablet with the Kindle Fire, which enabled the delivery of streaming video and music to customers.

Amazon Prime. Source: Amazon.

Amazon sells its Kindle devices at thin margins to tether users to its product search ecosystem for physical and digital goods. It expanded that strategy with the Fire TV set-top box, Fire TV Stick, and the Fire Phone. With Prime, its $99 per year membership service, customers get free two-day shipping, exclusive discounts, free streaming of media content, free e-books from the lending library, unlimited cloud storage for photos, and other perks.

That clever combination of cheap electronic devices and Prime membership has considerably boosted Amazon's sales per customer. A CIRP survey last year found that Kindle owners spent 30% more per year at Amazon than non-Kindle owners, while Prime members spent twice as much as non-Prime members. As Prime gains more users and Amazon unveils new "smart home" products -- such as the Echo speaker and Dash bar-code scanner and buttons -- it will widen its defensive moat against ecosystem rivals such as Google.

Petmed Express: A niche income generator
Petmed Express, also known as 1-800-PetMeds, is an under-the-radar niche player in e-commerce.

The company is the largest pet pharmacy in the U.S., and generates its revenue from over-the-counter and prescription drugs. The company has an extremely loyal customer base -- last year, 83% of its revenue was generated by reorders. It sells 80% of its products online, and ships 80% of those products within 24 hours. The other 20% of Petmed's products are sold through contract centers.

Source: Author's screenshot.

Although Petmed Express has a first-mover advantage and a loyal customer base, it faces fierce competition from larger companies such as Amazon, Wal-Mart, Petco, and PetSmart. Since Petmed doesn't have a substantial price advantage over those rivals, its top and bottom-line growth could slow as those retailers sell more pet medications. That's why Petmed's revenue slipped 1.7% annually last year as net income fell 2.9%.

On the bright side, the average size of individual Petmed orders has been rising, due to a mix of higher-priced products and higher doses, and the company is protecting its bottom line by reducing operating costs. It also pays a hefty forward annual dividend yield of 4.3%, making it one of the highest-yielding e-commerce stocks on the market.

PayPal: A pure play on online payments
PayPal, which eBay (NASDAQ:EBAY) acquired for $1.5 billion in 2002, will soon be spun off in an IPO, which would make it a pure-play investment in online payments. Forrester Research estimates that the amount spent on U.S. mobile payments annually could rise from $12.8 billion in 2013 to $90 billion in 2017.

Last year, PayPal's revenue rose 19% annually, accounting for 44% of eBay's top line. By comparison, revenue at the Marketplace unit, which generated the rest of eBay's revenue, only rose 8%. PayPal's total payment volume surged 27% to $48.3 billion, and roughly a third of those transactions were made via mobile devices -- compared to just 1% in 2010.

PayPal's mobile app. Source: Google Play.

PayPal was originally used for email payments, but the service is now employed by third-party websites for online payments and reaches brick-and-mortar stores through payment kiosks, Bluetooth beacons, physical cards, and card-swiping dongles. eBay also acquired Braintree, the maker of peer-to-peer payments app Venmo, to bolster PayPal's mobile presence. In addition, PayPal recently became a payment option for Bigcommerce's e-commerce network of over 90,000 online retailers.

Despite those strengths, PayPal faces intense competition from rivals including Apple Pay, Google's Android Pay, and Amazon's own payments platform for third-party websites. Facebook and Twitter's new mobile payment systems could also challenge PayPal in peer-to-peer payments.

The key takeaways
Amazon, Petmed, and PayPal offer three different ways to invest in e-commerce -- through an established market leader, a niche income generator, and a pure play on online payments, respectively.

However, investors shouldn't overlook their weaknesses. Amazon has great top-line growth but inconsistent profitability, while both Petmed and Paypal face intense competition from larger rivals. Nonetheless, investors interested in e-commerce should look at all three stocks.