import {z} from 'zod' export type Duration = {count?: number | undefined, unit?: ('UNIT_UNSPECIFIED' | 'MONTH' | 'DAY' | 'HOUR') | undefined}; export type CycleOptions = {initialCycleDuration?: Duration | undefined}; export type SubscriptionCancellationDetails = {reason?: ('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') | undefined}; 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 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 SubscriptionMigrationDetails = {legacyCreationTime?: unknown | undefined, migratedSubscriptionId?: string | undefined}; export type Location = {postalCode?: string | undefined, regionCode?: string | undefined}; export type SubscriptionUpgradeDowngradeDetails = {billingCycleSpec?: ('BILLING_CYCLE_SPEC_UNSPECIFIED' | 'BILLING_CYCLE_SPEC_ALIGN_WITH_PREVIOUS_SUBSCRIPTION' | 'BILLING_CYCLE_SPEC_START_IMMEDIATELY' | 'BILLING_CYCLE_SPEC_DEFERRED_TO_NEXT_RECURRENCE') | undefined, previousSubscriptionId?: string | undefined}; export type Subscription = {cancellationDetails?: SubscriptionCancellationDetails | undefined, createTime?: unknown | undefined, cycleEndTime?: unknown | undefined, endUserEntitled?: boolean | undefined, freeTrialEndTime?: unknown | undefined, lineItems?: Array | undefined, migrationDetails?: SubscriptionMigrationDetails | undefined, name?: string | undefined, partnerUserToken?: string | undefined, processingState?: ('PROCESSING_STATE_UNSPECIFIED' | 'PROCESSING_STATE_CANCELLING' | 'PROCESSING_STATE_RECURRING' | 'PROCESSING_STATE_RESUMING' | 'PROCESSING_STATE_SUSPENDING') | undefined, products?: Array | undefined, promotionSpecs?: Array | undefined, promotions?: Array | undefined, purchaseTime?: unknown | undefined, redirectUri?: string | undefined, renewalTime?: unknown | undefined, serviceLocation?: Location | undefined, state?: ('STATE_UNSPECIFIED' | 'STATE_CREATED' | 'STATE_ACTIVE' | 'STATE_CANCELLED' | 'STATE_IN_GRACE_PERIOD' | 'STATE_CANCEL_AT_END_OF_CYCLE' | 'STATE_SUSPENDED') | undefined, updateTime?: unknown | undefined, upgradeDowngradeDetails?: SubscriptionUpgradeDowngradeDetails | undefined}; export type CreateSubscriptionIntent = {cycleOptions?: CycleOptions | undefined, parent?: string | undefined, subscription?: Subscription | undefined, subscriptionId?: string | undefined}; export type EntitleSubscriptionIntent = {name?: string | undefined}; export type IntentPayloadIntentOptions = {enableOfferOverride?: boolean | undefined}; export type IntentPayload = {createIntent?: CreateSubscriptionIntent | undefined, entitleIntent?: EntitleSubscriptionIntent | undefined, intentOptions?: IntentPayloadIntentOptions | undefined}; export type GenerateUserSessionRequest = {intentPayload?: IntentPayload | undefined}; export type CreateApiV1PartnersPartnersIdUserSessionsGenerateArgs = {partnersId: string, body: GenerateUserSessionRequest}; export type CreateApiV1PartnersPartnersIdUserSessionsGenerateOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const userSession = z.object({expireTime: z.string().optional(), token: z.string().optional()}); export const generateUserSessionResponse = z.object({userSession: userSession.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 }; /** * This API replaces user authorized OAuth consent based APIs (Create, Entitle). Issues a timed session token for the given user intent. You can use the session token to redirect the user to Google to finish the signup flow. You can re-generate new session token repeatedly for the same request if necessary, regardless of the previous tokens being expired or not. By default, the session token is valid for 1 hour. * * POST /v1/partners/{partnersId}/userSessions:generate */ export const createApiV1PartnersPartnersIdUserSessionsGenerate = async (args: CreateApiV1PartnersPartnersIdUserSessionsGenerateArgs, options?: CreateApiV1PartnersPartnersIdUserSessionsGenerateOptions) => { 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))}/userSessions:generate${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(generateUserSessionResponse, await res.json()) };