import {z} from 'zod' export type Amount = {amountMicros?: unknown | undefined, currencyCode?: string | undefined}; export type SubscriptionLineItemBundleDetailsBundleElementDetails = {product?: string | undefined, userAccountLinkedTime?: unknown | undefined}; export type SubscriptionLineItemBundleDetails = {bundleElementDetails?: Array | undefined}; export type FiniteBillingCycleDetails = {billingCycleCountLimit?: unknown | undefined}; export type Duration = {count?: number | undefined, unit?: ('UNIT_UNSPECIFIED' | 'MONTH' | 'DAY' | 'HOUR') | undefined}; export type PromotionIntroductoryPricingDetailsIntroductoryPricingSpec = {discountAmount?: Amount | undefined, discountRatioMicros?: unknown | undefined, recurrenceCount?: number | undefined, regionCode?: string | undefined}; export type PromotionIntroductoryPricingDetails = {introductoryPricingSpecs?: Array | undefined}; export type SubscriptionPromotionSpec = {freeTrialDuration?: Duration | undefined, introductoryPricingDetails?: PromotionIntroductoryPricingDetails | undefined, promotion?: string | undefined, type?: ('PROMOTION_TYPE_UNSPECIFIED' | 'PROMOTION_TYPE_FREE_TRIAL' | 'PROMOTION_TYPE_INTRODUCTORY_PRICING') | undefined}; export type ServicePeriod = {endTime?: unknown | undefined, startTime?: unknown | undefined}; export type SubscriptionLineItemOneTimeRecurrenceDetails = {servicePeriod?: ServicePeriod | undefined}; export type GoogleHomePayload = {attachedToGoogleStructure?: boolean | undefined, googleStructureId?: string | undefined, partnerStructureId?: string | undefined}; export type GoogleOnePayload = {campaigns?: Array | undefined, offering?: ('OFFERING_UNSPECIFIED' | 'OFFERING_VAS_BUNDLE' | 'OFFERING_VAS_STANDALONE' | 'OFFERING_HARD_BUNDLE' | 'OFFERING_SOFT_BUNDLE') | undefined, salesChannel?: ('CHANNEL_UNSPECIFIED' | 'CHANNEL_RETAIL' | 'CHANNEL_ONLINE_WEB' | 'CHANNEL_ONLINE_ANDROID_APP' | 'CHANNEL_ONLINE_IOS_APP') | undefined, storeId?: string | undefined}; export type YoutubePayload = {accessEndTime?: unknown | undefined, partnerEligibilityIds?: Array | undefined, partnerPlanType?: ('PARTNER_PLAN_TYPE_UNSPECIFIED' | 'PARTNER_PLAN_TYPE_STANDALONE' | 'PARTNER_PLAN_TYPE_HARD_BUNDLE' | 'PARTNER_PLAN_TYPE_SOFT_BUNDLE') | undefined}; export type ProductPayload = {googleHomePayload?: GoogleHomePayload | undefined, googleOnePayload?: GoogleOnePayload | undefined, youtubePayload?: YoutubePayload | undefined}; export type SubscriptionLineItem = {amount?: Amount | undefined, bundleDetails?: SubscriptionLineItemBundleDetails | undefined, description?: string | undefined, finiteBillingCycleDetails?: FiniteBillingCycleDetails | undefined, lineItemFreeTrialEndTime?: unknown | undefined, lineItemIndex?: number | undefined, lineItemPromotionSpecs?: Array | undefined, name?: string | undefined, oneTimeRecurrenceDetails?: SubscriptionLineItemOneTimeRecurrenceDetails | undefined, planType?: ('LINE_ITEM_PLAN_TYPE_UNSPECIFIED' | 'LINE_ITEM_PLAN_TYPE_BASE' | 'LINE_ITEM_PLAN_TYPE_ADDON') | undefined, product?: string | undefined, productPayload?: ProductPayload | undefined, recurrenceType?: ('LINE_ITEM_RECURRENCE_TYPE_UNSPECIFIED' | 'LINE_ITEM_RECURRENCE_TYPE_PERIODIC' | 'LINE_ITEM_RECURRENCE_TYPE_ONE_TIME') | undefined, state?: ('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') | undefined}; export type PatchApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdLineItemsLineItemsIdArgs = {partnersId: string, subscriptionsId: string, lineItemsId: string, requestId?: string | undefined, updateMask?: unknown | undefined, body: SubscriptionLineItem}; export type PatchApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdLineItemsLineItemsIdOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; 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 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 }; /** * Updates a line item of a subscription. It should be authenticated with a service account. * * PATCH /v1/partners/{partnersId}/subscriptions/{subscriptionsId}/lineItems/{lineItemsId} */ export const patchApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdLineItemsLineItemsId = async (args: PatchApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdLineItemsLineItemsIdArgs, options?: PatchApiV1PartnersPartnersIdSubscriptionsSubscriptionsIdLineItemsLineItemsIdOptions) => { 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 (args.requestId != null) query.append("requestId", String(args.requestId)) if (args.updateMask != null) query.append("updateMask", String(args.updateMask)) 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))}/lineItems/${encodeURIComponent(String(args.lineItemsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(subscriptionLineItem, await res.json()) };