diff --git a/.changeset/add-purchase-type-and-recurring-cycle-limit.md b/.changeset/add-purchase-type-and-recurring-cycle-limit.md new file mode 100644 index 0000000000..1ffd361b8a --- /dev/null +++ b/.changeset/add-purchase-type-and-recurring-cycle-limit.md @@ -0,0 +1,5 @@ +--- +'@shopify/ui-extensions': minor +--- + +Add purchaseType and recurringCycleLimit subscribable fields to the DiscountsApi for discount function settings extensions. diff --git a/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.doc.ts b/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.doc.ts index 0064eace72..a9f29e37df 100644 --- a/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.doc.ts +++ b/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/discount-function-settings.doc.ts @@ -35,6 +35,12 @@ const data: ReferenceEntityTemplateSchema = { 'The `data` object exposed to the extension containing the discount function settings. Provides access to the discount identifier and associated [metafields](/docs/apps/build/metafields) that store function configuration values. Use this data to populate your settings UI and understand the current function configuration in the `admin.discount-details.function-settings.render` target.', type: 'DiscountFunctionSettingsData', }, + { + title: 'discounts', + description: + 'The reactive API for managing discount function configuration, including discount classes, discount method, purchase type, and recurring cycle limit.', + type: 'DiscountsApi', + }, ], examples: { description: 'Configure discount function settings', diff --git a/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/launch-options.ts b/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/launch-options.ts index d1a28fbcac..0b9f33057f 100644 --- a/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/launch-options.ts +++ b/packages/ui-extensions/src/surfaces/admin/api/discount-function-settings/launch-options.ts @@ -31,6 +31,11 @@ export type DiscountClass = 'product' | 'order' | 'shipping'; */ type DiscountMethod = 'automatic' | 'code'; +/** + * The purchase type that determines which purchases the discount applies to. Use `'one_time_purchase'` for one-time purchases only, `'subscription'` for subscription purchases only, or `'both'` for both. + */ +export type PurchaseType = 'one_time_purchase' | 'subscription' | 'both'; + /** * The `data` object exposed to discount function settings extensions in the `admin.discount-details.function-settings.render` target. Use this to access the current discount configuration and populate your settings interface with existing values. */ @@ -57,4 +62,20 @@ export interface DiscountsApi { * A signal that contains the discount method (`'automatic'` or `'code'`). Read this to determine whether the discount applies automatically at checkout or requires a customer-entered code. */ discountMethod: ReadonlySignalLike; + /** + * A signal that contains the purchase type. Read this to determine whether the discount applies to one-time purchases, subscriptions, or both. + */ + purchaseType: ReadonlySignalLike; + /** + * A function that updates the purchase type to change which types of purchases the discount applies to. Call this with a `PurchaseType` value (`'one_time_purchase'`, `'subscription'`, or `'both'`). + */ + updatePurchaseType: UpdateSignalFunction; + /** + * A signal that contains the recurring cycle limit for subscription purchases. A positive integer limits how many billing cycles the discount applies for. Both `0` and `null` mean unlimited (no limit). `null` is the default when no value has been explicitly set. + */ + recurringCycleLimit: ReadonlySignalLike; + /** + * A function that updates the recurring cycle limit for subscription purchases. Pass a positive integer to limit the number of billing cycles, `0` or `null` to remove the limit. + */ + updateRecurringCycleLimit: UpdateSignalFunction; }