https://developer.apple.com/documentation/storekit/testing-in-app-purchases-with-sandbox
This is the official documentation that helped me.
Follow these steps to access sandbox controls for TestFlight in iOS:
Download your beta app from TestFlight. You need to be signed in with a production Apple Account to download a beta app. For more information, see TestFlight Overview.
Open Settings and select your Apple Account.
Select Media & Purchases.
On the pop-up menu, select Sign Out.
Next, open Settings and select Developer. (This option is available when you enable Developer Mode).
Scroll to the bottom of the screen, and select Sign In under Sandbox Apple Account. Enter your Sandbox Apple Account credentials.
Topic:
App & System Services
SubTopic:
StoreKit
Tags: