Android Publisher Api How to Convert Region Prices with Proper Bounds

37 views Asked by At

I'm wondering if anyone has experience using androidPublisher api to create a subscription and to supply all of the regionalConfigs automatically that fit within the bounds of the regionsVersion.version.

My Example code here:

const regionPrices = await this.androidPublisher.monetization.convertRegionPrices({
            packageName: "",
            requestBody: {
                price: {
                    currencyCode: "USD",
                    units: String(units),
                    nanos: nanos ?? 0,
                },
            },
        });

let seenRegionCodes = { US: true };
for (const region of Object.values(regionPrices?.data?.convertedRegionPrices ?? {})) {
            if (!region || !region.regionCode || seenRegionCodes[region?.regionCode]) {
                this.logger.info("Already seen region: ", region.regionCode);
                continue;
            } else {
                seenRegionCodes[region.regionCode] = true;
                regionConfigs.push({
                    newSubscriberAvailability: true,
                    price: {
                        currencyCode: region.price?.currencyCode,
                        units: String(region.price?.units),
                        nanos: region.price?.nanos,
                    },
                    regionCode: region.regionCode,
                });
            }
        }


const subscription = await this.androidPublisher.monetization.subscriptions.create({
            packageName: "",
            productId: subscriptionId,
            "regionsVersion.version": "2022/02",
            requestBody: {
                basePlans: [
                    {
                        autoRenewingBasePlanType: {
                            billingPeriodDuration: "P1W",
                            legacyCompatible: false,
                        },
                        basePlanId: basePlanId,
                        regionalConfigs: regionConfigs,
                    },
                ],
                listings: [
                    {
                        title: `Subscription - ${user.username}`,
                        languageCode: "en-US",
                        description: `Subscription for userId: ${user.id}`,
                    },
                ],
                packageName: "",
                productId: subscriptionId,
            },
        });

The problem with this is the convertRegionPrices call seems to return nanos and units that are outside of the bounds listed here. Also it will return some regions that are not billable by Google play. So the call will fail.

Is there a method that we can use that will give me the prices within the bounds? Or do I need to write the logic for the 175 regionCodes manually?

0

There are 0 answers