android Google Play中是否有webhook可用于获取有关已取消inapps的通知?

gg0vcinb  于 2023-02-02  发布在  Android
关注(0)|答案(3)|浏览(166)

在我的应用中,我需要在后端处理应用内购买(而不是订阅)的取消。在最好的情况下,我希望在用户取消应用内购买时收到一些通知。
我找到了这个API:https://developer.android.com/google/play/billing/realtime_developer_notifications .但是这个东西似乎只适合订阅。
此API具有以下意义:https://developers.google.com/android-publisher/api-ref/purchases/voidedpurchases/list。我可以定期检查它,但随着用户数量的增长,这项任务可能会变得非常耗时。
那么,有没有更干净的方法来获得取消应用程序的通知呢?或者我必须一直检查状态吗?

juud5qan

juud5qan1#

目前voidedpurchases是唯一的答案,如果你使用startTime参数,那么跟踪你上次调用API的时间,并询问从那以后的voidedpurchases,就不会那么麻烦了。

nhaq1z21

nhaq1z212#

https://developer.android.com/google/play/billing/test
通常情况下,Google Play计费库会针对未签名并上传到Google Play的应用进行阻止。许可证测试人员可以绕过此检查,这意味着您可以旁载应用进行测试,即使是使用带有调试签名的调试构建版本的应用,也无需上传到新版本的应用。请注意,软件包名称必须与为Google Play配置的应用的名称匹配。并且Google帐户必须是Google Play控制台帐户的许可证测试人员。

vc9ivgsu

vc9ivgsu3#

令人惊讶的是,像谷歌这样大的公司收取30%的订阅费,这使得它很难实现。老实说,他们的文档是我见过的最糟糕的一些。像Revenue cat这样的整个公司都围绕着做一些对开发人员来说应该很容易的东西,事实上,很容易。
目前,我们必须记录用户购买的数据库,然后我们有一个检查,每两个星期的“最后检查值”,所以它不会大量增加。我们还跟踪什么是活跃的,而不是,不ping活跃的潜艇。
下面的代码需要“googleapis”和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;
  }
};

相关问题