Walmart made a big splash in the payments world Thursday by introducing a new feature on its existing app that will let shoppers pay at the company’s stores using their mobile phones. The service effectively replaces swiping a credit card or writing a check.

Walmart joins a long list of companies pushing into in-store mobile payments including Apple, Samsung, Google, and PayPal. These companies are clamoring to take a stake in a potentially huge mobile payments market, which is expected to handle $142 billion in transactions by 2019, according to Forrester Research.

Walmart’s WMT payments play was surprisingly smart and could actually pay off, said Sucharita Mulpuru, analyst at Forrester. That’s because the company has basically emulated one of the smartest and most successful mobile payments apps in retail history: the Starbucks app.

The coffee giant’s app evolved from being able to store and pay with Starbuck’s SBUX gift cards into letting customers store credit cards and scan their phones at cash registers in coffee shops. Now mobile payments account for 20% of all the chain’s 9 million weekly in-store transactions, more than double the figure Starbucks reported two years ago.

It wasn’t an obvious move for Walmart to copy Starbuck’s strategy. It’s no secret that Walmart has been forced to play catch up on e-commerce technology in the face of Amazon’s dominance.

Walmart also famously decided not to accept Apple’s mobile payments technology when it was introduced a last fall. Walmart instead joined the Merchant Customer Exchange, a partnership of major store and restaurant chains including brick and mortar rival Target, with ambitions of creating an Apple Pay-rival. But MCX has stumbled and only started testing its service in the past few months.

Walmart could have tried to replicate Apple Pay AAPL or even join forces with Apple on payments. But it made a smart decision not to, explained Mulpuru. Similar to the Starbucks app, Walmart Pay will be integrated into its dedicated payments app, which has 22 million active users. An already loyal (and large) userbase of shoppers could help increase adoption of the payments.

Walmart’s new payment service requires users to upload a credit card number into a mobile wallet. When checking out at the store, the app will create a QR code, or a digital barcode, that can be scanned at the cash register. Unlike Apple Pay or Google’s Android Pay GOOG , the app does not use NFC, or a contactless payments, to complete the transaction.

One difference between Walmart Pay and the Starbucks app is that Walmart doesn’t have a loyalty program integrated into the app. “Loyalty rewards creates a lot of stickiness in an app,” said Mulpuru. Another challenge for Walmart Pay is that a decent amount of in-store transactions at Walmart stores are still made in cash, Mulpuru added.

But the opportunity for Walmart is also massive. Starbucks has seen success with its feature that lets shoppers place and pay for orders ahead of time and then pick them up at a selected time. Walmart could figure out a way for shoppers to checkout within the app instead of having to scan a code at a cash register.

“Walmart will have to figure out a way to continue the relationship with their customers, and incentivize people to keep using the app,” Mulpuru said.

For more about Starbucks, watch this video: