Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Split the different pages you need to visit #577

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mshmoustafa
Copy link
Contributor

Motivation / Description

Split the different pages you need to visit for enabling the Google Developer and reporting api to make it clearer that there are two pages to visit.

Changes introduced

Linear ticket (if any)

Additional comments

@RCGitBot
Copy link
Contributor

Previews

temp/apple-app-store.md

See contents

👍

This section assumes you've followed our Quickstart section of our Getting Started guide to install and configure our SDK.

Sandbox Considerations

Products, prices, and metadata

In sandbox, StoreKit Test, and TestFlight environments, prices will often not reflect the actual prices set in App Store Connect. This is due to these environments being relatively unstable, does not necessarily indicate an issue with your implementation, and is not commonly seen in the production environment.

In these testing environments, you should ensure the purchase flow works as expected, rather than the prices and metadata being accurate. Unfortunately Apple's API can sometimes just be inaccurate, especially with different regions set for devices/accounts.

Create a Sandbox Test Account

In order to test your purchases, you'll need a sandbox test account. You can create test accounts from your App Store Connect dashboard > Users and Access > Sandbox Testers.

If you need help, you can refer to Apple's guide on creating sandbox testers here.

sandbox tester account

📘 Valid email required for sandbox accounts

Keep in mind you'll need to create sandbox accounts with valid emails that you can verify you own.

Localization

To test purchases in different regions, you should set your sandbox user's App Store Country or Region property to the territory you'd like to test.

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/7a32b3e-984a1f91-3d0c-4f36-b020-b48275dfbcf4.png",
"984a1f91-3d0c-4f36-b020-b48275dfbcf4.png",
1252
],
"align": "center",
"sizing": "80",
"border": true
}
]
}
[/block]

Testing on Device

This section is for testing on a physical device. If you want to test on the simulator, skip to the next section for instructions on how to get started with StoreKit testing.

Add the Sandbox Test Account to Your Device

On iOS 13 and earlier, even for sandbox purchases, you'll need to test on a real device. Starting from iOS 12, you're able to add a sandbox account to your device without having to sign out of your Apple Developer account.

On iOS 12 or greater, navigate to Settings > [Your Account] > App Store > Sandbox Account.

On iOS 13 or greater, navigate to Settings > App Store > Sandbox Account.

On macOS 11.5.2 or greater, navigate to App Store > Preferences > Sandbox Account.

Add the sandbox account credentials that you previously created. (The sandbox account credentials won't appear until you've made a purchase using a sandbox account in a development build.)

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/527a407-IMG_3EC533BFA443-1.jpeg",
"IMG_3EC533BFA443-1.jpeg",
1170
],
"align": "center",
"sizing": "80",
"border": true,
"caption": "Add your sandbox account under iOS settings to streamline testing"
}
]
}
[/block]

📘

If you do not see the option to add a sandbox account under iOS settings, make a sandbox purchase in your app. Apple will show a popup to enter login details, then you will see your account in iOS settings.

iOS 14+ Only: Testing on the Simulator

Starting from iOS 14, you can test sandbox purchases in the simulator. If you're using a physical device, you can skip this section.

Testing on the simulator requires one of these SDK versions:

SDK Version
iOS 3.9.0+
Flutter 2.0.0+
React Native 4.0.0+
Cordova 2.0.0+
Unity 3.0.0+

📘 StoreKit testing works on iOS 14 and later

Make sure to test on a real device if testing on iOS 13 or earlier.

📘 StoreKit testing requires running app from Xcode

StoreKit testing only works if you are running your app directly through Xcode. Any command line tools that use the xcodebuild command to start running an app (like flutter run or Flutter's VSCode plugin) won't use the StoreKit Configuration File specified in your scheme. This is a known issue and we have filed a feedback to Apple.

🚧 StoreKit testing is currently incompatible with macOS

While you can upload a StoreKit configuration file with a macOS app, this setup is currently incompatible with the SDK. When making test purchases on the simulator, the transactions will appear to go through but you'll receive an error from our backend. It's recommended to test without configuration files until this is addressed.

❗️ StoreKit testing won't show cancellation or refund events

While you can cancel and refund subscriptions through Xcode's Manage Transactions... window, these types of events are not stored in the receipt and will not appear on the RevenueCat dashboard.

However, the RevenueCat SDK is still able to detect there are no active subscriptions and the appropriate entitlements will be removed when the app is restarted again.

Step 1: Add a StoreKit Configuration File

Go to File > New > File... in the menu bar and select StoreKit Configuration File.

You can enable the "Sync this file with an app in App Store Connect" checkbox to have the file automatically configured with the in-app purchases or subscriptions already set up in App Store Connect.

Save the file in the top-level folder of your project and add it to your targets.

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/37ff24b-Screen_Shot_2020-12-01_at_11.56.19_AM.png",
"Screen Shot 2020-12-01 at 11.56.19 AM.png",
2538
],
"align": "center",
"caption": "Search for "storekit" to find the configuration file template quicker."
}
]
}
[/block]

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/abdf69a-Screen_Shot_2020-12-01_at_11.58.59_AM.png",
"Screen Shot 2020-12-01 at 11.58.59 AM.png",
2538
],
"align": "center",
"caption": "Add the configuration file to your targets and save."
}
]
}
[/block]

Step 2: Create a New Scheme for StoreKit Testing

Click the scheme in the scheme menu and click Manage Schemes...

Select your current scheme and click Duplicate.

In the scheme editor, add the StoreKit Configuration file you created in Step 1 and click Close.

Step 3: Setting up the StoreKit Configuration File

In the editor, click the "+" button at the bottom and create a new product. In this tutorial, an auto-renewable subscription will be created.

Enter a name for a new subscription group and click Done. The subscription group name should match one that is set up for your app in App Store Connect, but it's not a requirement. That means you can test your subscription groups and products in the simulator and then create the products in App Store Connect later.

📘 Products in the configuration file must be set up in RevenueCat

Even though products don't have to be set up in App Store Connect, they have to be set up in RevenueCat so that RevenueCat can validate the sandbox receipt. Refer to the Configuring Products guide for more information.

Configure the subscription as needed by filling in the Reference Name, Product ID, Price, Subscription Duration, and optionally an Introductory Offer. Again, this product doesn't have to exist in App Store Connect for you to test purchasing in the simulator. Here is a sample configuration:

Repeat this for as many products as you want.

Step 4: Uploading the Public Certificate to RevenueCat

Go to Editor > Save Public Certificate and save the public certificate to your project.

Go to your app's configuration page in your RevenueCat project settings (Project Settings > Apps > [Your App]). Expand the dropdown StoreKit testing framework and upload the certificate to your app. If successful, you should see Certificate added.

👍 You did it!

You're ready to make purchases locally in the simulator!

Make a Purchase

Build and run your app on your device. When you attempt to make a purchase, you may be still be prompted to sign in with the sandbox account you just created.

📘

Apple may prompt you to sign in with an Apple ID whenever you make or restore a purchase. When using the SDK, this could only happen when you call .purchase(package:) or .restorePurchases. Developers don't have control over the type of prompt that is shown (Face ID, Touch ID, password, etc.)

❗️ Sandbox May Be Slow

Apple's App Store Sandbox is notoriously unperformant. A sandbox purchase experience may take upwards of 15s to fully complete. This is normal. In production, total purchase times are usually in the low seconds.

Verify the Transaction Appears in the Dashboard

After a purchase is successful, you should be able to view the transaction immediately in the RevenueCat dashboard. If the purchase does not appear in the dashboard, it's not being tracked by RevenueCat.

📘 Make sure Sandbox Data is enabled

Make sure the the View Sandbox Data toggle is enabled in the navigation bar.

Working with Subscriptions

In the the sandbox environment, subscription renewals happen at an accelerated rate, and auto-renewable subscriptions renew a maximum of six times per day. This enables you to test how your app handles a subscription renewal, a subscription lapse, and a subscription history that includes gaps.

Because of the accelerated expiration and renewal rates, sometimes not all renewals are reflected in the RevenueCat customer dashboard.

Deleting Test Users

When testing, it may be helpful to delete a customer and all their receipts from RevenueCat to simulate a new installation. You can delete a specific user from the customer dashboard in RevenueCat. See our docs on deleting users for more information.

❗️ Maximum number of App Store subscription receipts

For performance reasons, RevenueCat limits the number of App Store subscription receipts per customer to 100. Having more than 100 subscription receipts on a single customer is not going to happen in production, but can easily happen during sandbox testing. Simply deleting the customer will solve this problem.

TestFlight

TestFlight is a hybrid environment that uses production Apple IDs but purchases occur in sandbox, which can cause unexpected issues that are very likely undocumented by Apple.

Common Errors

If you're getting the error "Account Not In This Store" when attempting to make a purchase on macOS, try to:

  • Switch your region to the recommended region
  • Sign out of the App Store
  • Relaunch the TestFlight app
  • Attempt to make the purchase again, and sign in when prompted

📘 Make sure to log out of the sandbox user on your testing device

Deleting the user from RevenueCat doesn't delete the user's purchase history with Apple. It only deletes the user's receipt and metadata from our servers. That means making or restoring purchases will restore those purchases with RevenueCat. To simulate purchasing as a completely new user, make sure to log out of the sandbox account on your device and create a new one.

Next Steps

For more information, take a look at the official Apple documentation:
Apple App Store: Testing in-app purchases

temp/creating-play-service-credentials.md

See contents

In order for RevenueCat's servers to communicate with Google on your behalf, you need to provide a set of service credentials. The process for configuring these credentials is a bit complex, but the added level of control improves security by providing RevenueCat with only the access we need.

📘 Credentials can take up to 36 hours after being created to be valid

It can take up to 36 hours for your Play Service Credentials to work properly with the Google Play Developer API. You may see "Invalid Play Store credentials" errors (503 or 521) and be unable to make purchases with RevenueCat until this happens.

Setup

Note that this setup takes place on both the Google Play Console and the Google Cloud Console. Due to the nature of the process, there’s some switching back and forth between each console that can’t be helped, but each step will make clear which console you should be looking at.

1. Enable the Google Developer and Reporting API

To enable the Developer and Reporting APIs for your Google Cloud Project, you’ll want to do the following:

  1. Go to the API Console.
  2. From the projects list, select a project or create a new one.
  3. Go to the following pages and click Enable ((This will say Manage when it is enabled):
    1. Google Play Android Developer API page
    2. Google Play Developer Reporting API page

steponeGIFv2

After enabling the API, you will be redirected to your Google Cloud API page. From there, if you do not have credentials, you will need to create these following the prompt. You'll want to select that you are using the Google Play Android Developer API. Note that you'll want to generate these with either the owner of the project or a user that has the permissions from step 3 enabled in Google Play Console.

You will then be redirected to create your form of credentials which you can follow step 2 for. If you just created your credentials, you may see the “To use this API, you may need credentials” message on your API console, this is because your credentials have not yet been validated. This will be done automatically by Google.

2. Create a Service Account

  • Where: Google Cloud Console
  • Cloud Console :fa-arrow-right: IAM & Admin :fa-arrow-right: Service Account
  • You can also reach this page from the last screen used in Google Play Console. Click 'Learn how to create service accounts', then 'Google Cloud Platform' from the pop up. This will ensure that you're in the same project that you linked in Step 1 - if using the the links above or another way, double check this before creating the service account.

a. Create and name the service account key credentials and add roles.

Select the button to 'Create Service Account'. These are the credentials that RevenueCat will need to communicate with Google. Name your new account, then select 'Create and continue'.

On the step named 'Grant this service account access to project', you'll add two Roles:

  • Pub/Sub Admin - this enables Platform Server Notifications
  • Monitoring Viewer - this allows monitoring of the notification queue

Note that searching by name in the filter does not always bring up both roles. You can also find each by scrolling through the list - in the Pub/Sub and Monitoring folders respectively.

You can skip the optional third step, and select done.

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/7706775-Crede_Step2aaaa.gif",
null,
"Google Cloud Console"
],
"align": "center",
"caption": "Google Cloud Console"
}
]
}
[/block]

b. Create and download the public key

In the 'Service Accounts' section of the Google Cloud Console, select the three dots for the Actions dropdown menu, then Manage Keys.

Select Add Key, then Create new key. On the pop up, make sure JSON is selected, and then create and download the JSON Key. We'll use this in Step 4.

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/a6896be-Crede_Step2b.gif",
null,
"Google Cloud Console"
],
"align": "center",
"caption": "Google Cloud Console"
}
]
}
[/block]

📘 Enable the Pub/Sub API for Google Developer Notifications

While you're in the Google Cloud Console, get a head start on setting up Google real-time developer notifications by ensuring Google Cloud Pub/Sub is enabled for your project. You can enable it here.

3. Grant Financial Access to RevenueCat

  • Where: Google Play Console
  • Developer homepage :fa-arrow-right: Users and permissions

In the Google Play Console, go to the 'Users and Permissions' section' and select invite user. You'll want to invite the service account you created in Step 2. Under 'App permissions' you need to add your app. Then under 'Account permissions', you need to grant certain permissions in order for RevenueCat to properly work.

Grant the following permissions:

  • View app information and download bulk reports (read-only)
  • View financial data, orders, and cancellation survey response
  • Manage orders and subscriptions

All other choices are yours - the other boxes can be checked or unchecked according to your needs, as long as those three are selected.

Select invite user at the bottom of the page, and send the invite. You'll then be redirected to 'Users and Permissions', where you should see your newly created account as active.

stepthreeGIF

4. Enter the Credentials JSON in RevenueCat

  • Where: RevenueCat Dashboard
  • Project Page :fa-arrow-right: Google Play App Settings

Find your credentials JSON file that was downloaded in Step 2 and either drop it into your project settings or select it from the finder. Be sure to save changes. Within approximately 36 hours, your credentials will be activated and we’ll be ready to handle Google Play purchases!

[block:image]
{
"images": [
{
"image": [
"https://files.readme.io/c0354f7-Crede_Step4.gif",
null,
"RevenueCat Dashboard"
],
"align": "center",
"caption": "RevenueCat Dashboard"
}
]
}
[/block]

📘

There is a workaround to get this validated sooner. In Google Play Console, open your app's dashboard and visit the 'Monetize' section. Go to Products -> Subscriptions/in-app products, and change the description of any product and save the changes. This should work to enable the new service credentials right away (or very shortly) and you can revert the changes to that product. It's not guaranteed to work, but has worked for others in the past to get things working right away. Otherwise, it usually starts working within 24 hours but possibly more than 36.

👍

While you’re in your RevenueCat Play Store App settings and waiting for your credentials to activate, set up your Google Real-Time Developer Notifications. If you enabled Pub/Sub in Step 2 of this doc, skip ahead to step 2 of the setup.

Check the status of your credentials

With our Google Play credential validation, we will validate every time Google credentials are (re)uploaded or at any time through a click of a button. A summary message will appear with the results of the validation to provide you additional information about the status of your Google credentials.

Once your credentials are valid, you will see a "Valid credentials" message under your uploaded JSON file with all permissions checked.

Troubleshooting the credential validation

Before starting to dive deeper in troubleshooting your credentials, you should confirm the following:

  • The JSON file uploaded to RevenueCat is the correct file
  • You have re-uploaded the credentials into RevenueCat

subscriptions API

If the permission to call subscriptions API validation is not passing, that means we were unable to use your credentials to receive a response from Google's GET subscriptions endpoint.

Ensure that you have granted the following permissions:

  • View financial data in step 3a
  • Manage orders and subscriptions in step 3a
  • Once this is done, try to make a test purchase using a Sandbox user in order to check if the connection to the subscriptions API is working.

You will also want to make sure that you have uploaded your signed APK or Android App Bundle and have completed all the steps to approve the release.

inappproducts API

If the permission to call inappproducts API validation is not passing, that means we were unable to use your credentials to receive a response from Google's GET inappproducts endpoint.

Ensure that you have granted the following permission:

  • View app information and download bulk reports (read-only) in step 3a

monetization API

If the permission to call monetization API validation is not passing, that means we were unable to use your credentials to receive a response from Google's LIST monetization endpoint.

Ensure that you have granted the following permission:

After making changes to your Google credentials, it may take 24 hours, up to 36 hours, for the changes to populate throughout Google's servers.

Troubleshooting

This guide contains a lot of information and many steps, and it can be all too easy to move too quickly or simply misconfigure something. Break down each step by where it needs to take place as you're going through the guide or after the fact with our handy Checklist.

Error Handling

Commonly occurring errors when setting up your service credentials or developer notifications and what to do when you see them.

Error: Underlying message: What to do:
INVALID_GOOGLE_CREDENTIALS_ACCESS_ERROR 'Your Google Service Account credentials do not have permissions to access the needed Google resources. Refer to this guide for more information.' Confirm that the roles granted to your service account in Google Cloud match: Pub/Sub Admin and Monitoring Viewer. If you change them or update them at all, make sure that you re-generate your JSON key to add to RevenueCat.
INVALID_GOOGLE_CREDENTIALS_ERROR 'The provided Google Service Account credentials JSON is invalid.' Re-generate the JSON key from Google Cloud and try uploading it to RevenueCat again. If you get the same error, try re-creating your service account.
INVALID_PLAY_STORE_CREDENTIALS 'Invalid Play Store credentials.' Unfortunately, this one is a little vague. Run through the guide again, ensuring that all steps have been followed. If you've already waited for over 36 hours and continue to get this error, try starting over from the beginning.
MISSING_GOOGLE_SERVICE_ACCOUNT_CREDENTIALS 'Google Play service account credentials must be set up before using this feature.' This one is most likely to crop up if trying to perform an action that communicates with Google, such as importing products for Android, before setting up service credentials.
INVALID_PERMISSIONS_FOR_ENDPOINT 'Account permissions are invalid for this request.' Not all RevenueCat collaborators have the same permissions. In order to make changes to an app's configuration (such as creating service credentials), a user must be listed as an 'Admin'.
GOOGLE_PLAY_PUB_SUB_NOT_ENABLED 'Google Play Pub/Sub integration is not currently enabled for this app.' Enable access to the Pub/Sub API on the Google Cloud Console for the same project that you used to set up your service credentials.
PUBSUB_GENERIC_USER_PERMISSION_ERROR 'Your Google service account credentials do not have permissions to access the Google Cloud Pub/Sub API. Refer to this guide for more information.' This points to either the Pub/ Sub API access not being enabled, or the Pub/Sub role that has been added to the service account is not the admin role. Double check that your service account has the correct roles, and if changing them, re-generate the JSON key and re-add it to RevenueCat.

@mshmoustafa mshmoustafa marked this pull request as ready for review December 13, 2023 17:08
@mshmoustafa mshmoustafa requested a review from a team December 13, 2023 17:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants