Is there webhook to get notification about cancelled inapps in Google Play?
Asked Answered
S

3

11

In my app, I need to handle cancelation of in-app purchases (not subscriptions) on the backend. In the best case, I'd like to get some notification when a user cancels in-app.

So I've found this API: https://developer.android.com/google/play/billing/realtime_developer_notifications . But this thing seems to be suitable only for subscriptions.

This API has sense: https://developers.google.com/android-publisher/api-ref/purchases/voidedpurchases/list . I can check it periodically, but this task can become too time-consuming as the count of users grows.

So is there some more clean way to get notifications about canceled in-apps? Or do I have to check statuses all the time?

Surrogate answered 25/3, 2019 at 8:41 Comment(2)
Are you talking about a way to detect if a user requested a refund within 48 hours of purchase?Flake
@Flake yes, exactly!Surrogate
J
6

Currently voidedpurchases is the only answer. If you use the startTime parameter it shouldn't be that messy to track when last you called the API and just ask for voided purchases since then.

Jobber answered 2/4, 2019 at 15:42 Comment(1)
But voidedpurchases doesn't return cancelled orders, only refundsMouser
P
2

It's amazing that a company as big as Google that charges 30% on top of subscriptions makes it so hard to implement. Their docs are honestly some of the worst I've ever seen. Entire companies like Revenue cat revolve around making something that should be easy for the developer, in-fact, easy..

Currently we have to record the users purchases on a database, then we have a checked that CRONs every 2 weeks with a 'last checked value' so it doesn't bulk up. We also track what is active and not, not pinging active subs.

The following code requires 'googleapis' and that setup for nodejs.

/**
 * Use expiryTimeMillis to check if the subscription is still valid
 */
export const androidCheckSubscriptionStatus = async (props: {
  token: string;
  skuName: string;
}): Promise<androidpublisher_v3.Schema$SubscriptionPurchase> => {
  try {
    const { token, skuName } = props;
    await initAndroidApisClient();

    /**
     * If this throws, it might be bad request, and not that the token is invalid.
     * For example connection issues.
     */
    const result = await androidClient.purchases.subscriptions.get({
      packageName: 'com.vegiano.app',
      subscriptionId: skuName,
      // The token is from the original payment.
      token: token,
    });

    /**
     * It will expire so unassign it.
     * The unassign will unassign when the month ends for the subscription.
     */
    if (result.data.expiryTimeMillis) {
      const tokensToUnassign = await SubscriptionToken.findAll({
        where: {
          subscriptionMeta: token,
        },
      });
      for (const token of tokensToUnassign) {
        if (token.activeUserIdSubscribedTo) {
          const user = await User.findOne({ where: { id: token.userId } });
          const updatedToken = await unassignToken({ tokenId: token.id, owner: user!, paymentFailed: true });
        }
      }
    }

    return result.data;

    //
  } catch (error) {
    console.error('checkAndroidSubscriptionValid failed');
    console.error(error);
    throw error;
  }
};
Pieplant answered 30/1, 2023 at 17:34 Comment(0)
G
0

https://developer.android.com/google/play/billing/test

Ordinarily, the Google Play Billing Library is blocked for apps that aren't signed and uploaded to Google Play. License testers can bypass this check, meaning you can sideload apps for testing, even for apps using debug builds with debug signatures without the need to upload to the new version of your app. Note that the package name must match that of the app that is configured for Google Play, and the Google account must be a license tester for the Google Play Console account.

Gopher answered 14/9, 2022 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.