The U.S. economy defied expectations in the second quarter as gross domestic product (GDP) jumped 2.4% sequentially, an acceleration from 2% in the first quarter and well above the forecasted 1.8% growth. Better yet, that momentum is snowballing. Current projections show third-quarter GDP soaring 4.1% on strong consumer spending and business investments, according to data from the Federal Reserve Bank of Atlanta.

That momentum comes in part from cooling inflation and forecasts that the Fed is nearing the end of its rate hike campaign, meaning credit conditions will soon stabilize. In any case, strong GDP growth is a bullish signal for Wall Street. It points to possible stock market gains because increases in consumer spending and business investments will likely boost corporate revenues and profits.

Here's why Shopify (SHOP 1.11%) and Mastercard (MA 0.07%) can help investors capitalize on that momentum.

1. Shopify

Shopify taps into the global economy by providing merchants with a turnkey solution for omnichannel commerce. Its software allows businesses to manage orders and inventory across physical and digital storefronts from a single dashboard. Shopify also provides adjacent merchant solutions for payment processing, logistics support, and cross-border commerce, and its enterprise-grade platform Shopify Plus offers more sophisticated tools for artificial intelligence-powered marketing and business-to-business (B2B) commerce.

Shopify is the market leader in e-commerce software and omnichannel commerce software, and its merchants collectively accounted for 10% of online retail sales in the U.S. last year. That puts Shopify in second place behind Amazon (and ahead of third place Walmart).

Shopify recently reported stellar results for the second quarter. Revenue rose 31% to $1.7 billion, a sharp acceleration from 16% growth in the prior year, and the company recorded a non-GAAP profit of $0.14 per diluted share, up from a loss of $0.03 per diluted share in the prior year. Better yet, Shopify should be able to maintain that growth trajectory for years to come.

The e-commerce software market is expected to increase at 12.5% annually through 2032. That points to solid growth in subscription software sales. But Shopify also earns a good chunk of revenue by providing payment processing services, and retail e-commerce sales are projected to climb at 13.6% annually through 2030, while B2B e-commerce sales are forecasted to increase at 20.2% annually during the same period.

Shopify should outpace the industry average in all areas given its strong competitive position, so the company has a good shot at 20% annual revenue growth (or better) through the end of the decade. In that context, shares look quite reasonable at their current valuation of 11.2 times sales, especially when compared to the five-year average of 28.7 times sales. That's why this stock is worth buying.

2. Mastercard

Mastercard operates one of the largest payments networks in the world in terms of acceptance locations, and it handled 24% of all payment card purchase transactions last year, which puts the company in third place behind Visa (39%) and UnionPay (34%). Mastercard monetizes its network by assessing fees based on gross dollar volume (GDV) and the number of processed transactions. That makes the company a tollbooth of sorts that taps directly into the global economy by taking a cut of consumer and business spending.

Mastercard has a virtually unassailable moat. The first part of that moat is a network effect: Each cardholder makes the network more valuable for merchants, and each merchant makes the network more valuable for cardholders. Immense scale makes that network effect particularly powerful. Merchants are all but obligated to accept Mastercard because consumers expect it.

The second part of the moat is a cost advantage: Mastercard earns higher profit margins than smaller payment card companies like American Express and Discover Financial Services because it can spread expenses over more transactions. By the same logic, Mastercard could afford to undercut smaller competitors on price if they attempted to enter the market or take share. Disrupting the status quo in the card payments industry would be next to impossible.

Given Mastercard's position as an economic barometer, it should come as no surprise that the company reported solid financial results in the second quarter. Revenue climbed 14% to $6.3 billion on strong momentum in GDV and processed transactions, and GAAP earnings soared 28% to $3.00 per diluted share. That swift bottom-line growth can be attributed to excellent cost control and $2.4 billion in share repurchases.

Mastercard is well-positioned to maintain that momentum. The credit card market is projected to grow at 9% annually through 2031, and the B2B virtual card market -- an area where Mastercard has a leadership position -- is expected to grow at 12% annually through 2032, according to Future Market Insights. Mastercard also has opportunities in B2B account-based transactions and value-added services.

Here's the bottom line: Mastercard should be able to grow revenue in the low-double-digits for many years to come. That estimate fits its profile from the past decade, during which the company increased revenue at 11.7% annually. Assuming that continues, the current valuation of 16 times sales seems reasonable, especially when the five-year average is 18 times sales. That's why this growth stock is worth buying.