import {z} from 'zod' export type UndoCancelSubscriptionRequest = Record; export type CreateApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdUndoCancelArgs = {partnersId: string, subscriptionsId: string, body: UndoCancelSubscriptionRequest}; export type CreateApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdUndoCancelOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const subscriptionCancellationDetails = z.object({reason: z.enum(["CANCELLATION_REASON_UNSPECIFIED", "CANCELLATION_REASON_FRAUD", "CANCELLATION_REASON_REMORSE", "CANCELLATION_REASON_ACCIDENTAL_PURCHASE", "CANCELLATION_REASON_PAST_DUE", "CANCELLATION_REASON_ACCOUNT_CLOSED", "CANCELLATION_REASON_UPGRADE_DOWNGRADE", "CANCELLATION_REASON_USER_DELINQUENCY", "CANCELLATION_REASON_SYSTEM_ERROR", "CANCELLATION_REASON_SYSTEM_CANCEL", "CANCELLATION_REASON_BILLING_SYSTEM_SWITCH", "CANCELLATION_REASON_OTHER"]).optional()}); export const amount = z.object({amountMicros: z.string().optional(), currencyCode: z.string().optional()}); export const subscriptionLineItemBundleDetailsBundleElementDetails = z.object({product: z.string().optional(), userAccountLinkedTime: z.string().optional()}); export const subscriptionLineItemBundleDetails = z.object({bundleElementDetails: z.array(subscriptionLineItemBundleDetailsBundleElementDetails).optional()}); export const finiteBillingCycleDetails = z.object({billingCycleCountLimit: z.string().optional()}); export const duration = z.object({count: z.number().int().optional(), unit: z.enum(["UNIT_UNSPECIFIED", "MONTH", "DAY", "HOUR"]).optional()}); export const promotionIntroductoryPricingDetailsIntroductoryPricingSpec = z.object({discountAmount: amount.optional(), discountRatioMicros: z.string().optional(), recurrenceCount: z.number().int().optional(), regionCode: z.string().optional()}); export const promotionIntroductoryPricingDetails = z.object({introductoryPricingSpecs: z.array(promotionIntroductoryPricingDetailsIntroductoryPricingSpec).optional()}); export const subscriptionPromotionSpec = z.object({freeTrialDuration: duration.optional(), introductoryPricingDetails: promotionIntroductoryPricingDetails.optional(), promotion: z.string().optional(), type: z.enum(["PROMOTION_TYPE_UNSPECIFIED", "PROMOTION_TYPE_FREE_TRIAL", "PROMOTION_TYPE_INTRODUCTORY_PRICING"]).optional()}); export const servicePeriod = z.object({endTime: z.string().optional(), startTime: z.string().optional()}); export const subscriptionLineItemOneTimeRecurrenceDetails = z.object({servicePeriod: servicePeriod.optional()}); export const googleHomePayload = z.object({attachedToGoogleStructure: z.boolean().optional(), googleStructureId: z.string().optional(), partnerStructureId: z.string().optional()}); export const googleOnePayload = z.object({campaigns: z.array(z.string()).optional(), offering: z.enum(["OFFERING_UNSPECIFIED", "OFFERING_VAS_BUNDLE", "OFFERING_VAS_STANDALONE", "OFFERING_HARD_BUNDLE", "OFFERING_SOFT_BUNDLE"]).optional(), salesChannel: z.enum(["CHANNEL_UNSPECIFIED", "CHANNEL_RETAIL", "CHANNEL_ONLINE_WEB", "CHANNEL_ONLINE_ANDROID_APP", "CHANNEL_ONLINE_IOS_APP"]).optional(), storeId: z.string().optional()}); export const youtubePayload = z.object({accessEndTime: z.string().optional(), partnerEligibilityIds: z.array(z.string()).optional(), partnerPlanType: z.enum(["PARTNER_PLAN_TYPE_UNSPECIFIED", "PARTNER_PLAN_TYPE_STANDALONE", "PARTNER_PLAN_TYPE_HARD_BUNDLE", "PARTNER_PLAN_TYPE_SOFT_BUNDLE"]).optional()}); export const productPayload = z.object({googleHomePayload: googleHomePayload.optional(), googleOnePayload: googleOnePayload.optional(), youtubePayload: youtubePayload.optional()}); export const subscriptionLineItem = z.object({amount: amount.optional(), bundleDetails: subscriptionLineItemBundleDetails.optional(), description: z.string().optional(), finiteBillingCycleDetails: finiteBillingCycleDetails.optional(), lineItemFreeTrialEndTime: z.string().optional(), lineItemIndex: z.number().int().optional(), lineItemPromotionSpecs: z.array(subscriptionPromotionSpec).optional(), name: z.string().optional(), oneTimeRecurrenceDetails: subscriptionLineItemOneTimeRecurrenceDetails.optional(), planType: z.enum(["LINE_ITEM_PLAN_TYPE_UNSPECIFIED", "LINE_ITEM_PLAN_TYPE_BASE", "LINE_ITEM_PLAN_TYPE_ADDON"]).optional(), product: z.string().optional(), productPayload: productPayload.optional(), recurrenceType: z.enum(["LINE_ITEM_RECURRENCE_TYPE_UNSPECIFIED", "LINE_ITEM_RECURRENCE_TYPE_PERIODIC", "LINE_ITEM_RECURRENCE_TYPE_ONE_TIME"]).optional(), state: z.enum(["LINE_ITEM_STATE_UNSPECIFIED", "LINE_ITEM_STATE_ACTIVE", "LINE_ITEM_STATE_INACTIVE", "LINE_ITEM_STATE_NEW", "LINE_ITEM_STATE_ACTIVATING", "LINE_ITEM_STATE_DEACTIVATING", "LINE_ITEM_STATE_WAITING_TO_DEACTIVATE", "LINE_ITEM_STATE_OFF_CYCLE_CHARGING"]).optional()}); export const subscriptionMigrationDetails = z.object({legacyCreationTime: z.string().optional(), migratedSubscriptionId: z.string().optional()}); export const location = z.object({postalCode: z.string().optional(), regionCode: z.string().optional()}); export const subscriptionUpgradeDowngradeDetails = z.object({billingCycleSpec: z.enum(["BILLING_CYCLE_SPEC_UNSPECIFIED", "BILLING_CYCLE_SPEC_ALIGN_WITH_PREVIOUS_SUBSCRIPTION", "BILLING_CYCLE_SPEC_START_IMMEDIATELY", "BILLING_CYCLE_SPEC_DEFERRED_TO_NEXT_RECURRENCE"]).optional(), previousSubscriptionId: z.string().optional()}); export const subscription = z.object({cancellationDetails: subscriptionCancellationDetails.optional(), createTime: z.string().optional(), cycleEndTime: z.string().optional(), endUserEntitled: z.boolean().optional(), freeTrialEndTime: z.string().optional(), lineItems: z.array(subscriptionLineItem).optional(), migrationDetails: subscriptionMigrationDetails.optional(), name: z.string().optional(), partnerUserToken: z.string().optional(), processingState: z.enum(["PROCESSING_STATE_UNSPECIFIED", "PROCESSING_STATE_CANCELLING", "PROCESSING_STATE_RECURRING", "PROCESSING_STATE_RESUMING", "PROCESSING_STATE_SUSPENDING"]).optional(), products: z.array(z.string()).optional(), promotionSpecs: z.array(subscriptionPromotionSpec).optional(), promotions: z.array(z.string()).optional(), purchaseTime: z.string().optional(), redirectUri: z.string().optional(), renewalTime: z.string().optional(), serviceLocation: location.optional(), state: z.enum(["STATE_UNSPECIFIED", "STATE_CREATED", "STATE_ACTIVE", "STATE_CANCELLED", "STATE_IN_GRACE_PERIOD", "STATE_CANCEL_AT_END_OF_CYCLE", "STATE_SUSPENDED"]).optional(), updateTime: z.string().optional(), upgradeDowngradeDetails: subscriptionUpgradeDowngradeDetails.optional()}); export const undoCancelSubscriptionResponse = z.object({subscription: subscription.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Currently, it is used by **Google One, Play Pass** partners. Revokes the pending cancellation of a subscription, which is currently in `STATE_CANCEL_AT_END_OF_CYCLE` state. If the subscription is already cancelled, the request will fail. It should be called directly by the partner using service accounts. * * POST /v1/partners/{partnersId}/subscriptions/{subscriptionsId}:undoCancel */ export const createApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdUndoCancel = async (args: CreateApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdUndoCancelArgs, options?: CreateApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdUndoCancelOptions) => { const {baseUrl = "https://paymentsresellersubscription.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/partners/${encodeURIComponent(String(args.partnersId))}/subscriptions/${encodeURIComponent(String(args.subscriptionsId))}:undoCancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(undoCancelSubscriptionResponse, await res.json()) };