export async function getGoogleSubResponse()

in typescript/src/update-subs/google.ts [69:118]


export async function getGoogleSubResponse(
  record: SQSRecord,
): Promise<Subscription[]> {
  const subscriptionReference = JSON.parse(
    record.body,
  ) as GoogleSubscriptionReference;

  let response;
  try {
    response = await fetchGoogleSubscription(
      subscriptionReference.subscriptionId,
      subscriptionReference.purchaseToken,
      subscriptionReference.packageName,
    );
  } catch (exception: any) {
    if (exception.statusCode === 410) {
      console.log(`Purchase expired a very long time ago, ignoring`);
      return [];
    }
    if (
      exception.statusCode === 400 &&
      exception?.result?.error?.message === 'Invalid Value'
    ) {
      console.warn(
        "The purchase token value was invalid, we can't recover from this error",
        exception,
      );
      throw new ProcessingError('Invalid token value', false);
    } else {
      throw exception;
    }
  }

  const billingPeriod =
    PRODUCT_BILLING_PERIOD[subscriptionReference.subscriptionId];
  if (billingPeriod === undefined) {
    console.warn(
      `Unable to get the billing period, unknown google subscription ID ${subscriptionReference.subscriptionId}`,
    );
  }

  const subscription = googleResponseBodyToSubscription(
    subscriptionReference.purchaseToken,
    subscriptionReference.packageName,
    subscriptionReference.subscriptionId,
    billingPeriod,
    response,
  );
  return [subscription];
}