Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,11 @@ describe('SubscriptionController', () => {
controller.metadata,
'anonymous',
),
).toMatchInlineSnapshot(`Object {}`);
).toMatchInlineSnapshot(`
Object {
"trialedProducts": Array [],
}
`);
});
});

Expand All @@ -965,6 +969,7 @@ describe('SubscriptionController', () => {
).toMatchInlineSnapshot(`
Object {
"subscriptions": Array [],
"trialedProducts": Array [],
}
`);
});
Expand All @@ -981,6 +986,7 @@ describe('SubscriptionController', () => {
).toMatchInlineSnapshot(`
Object {
"subscriptions": Array [],
"trialedProducts": Array [],
}
`);
});
Expand All @@ -997,6 +1003,7 @@ describe('SubscriptionController', () => {
).toMatchInlineSnapshot(`
Object {
"subscriptions": Array [],
"trialedProducts": Array [],
}
`);
});
Expand Down
19 changes: 18 additions & 1 deletion packages/subscription-controller/src/SubscriptionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
} from './types';

export type SubscriptionControllerState = {
customerId?: string;
trialedProducts: ProductType[];
subscriptions: Subscription[];
pricing?: PricingResponse;
};
Expand Down Expand Up @@ -127,6 +129,7 @@ export type SubscriptionControllerOptions = {
export function getDefaultSubscriptionControllerState(): SubscriptionControllerState {
return {
subscriptions: [],
trialedProducts: [],
};
}

Expand All @@ -145,6 +148,18 @@ const subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState>
anonymous: false,
usedInUi: true,
},
customerId: {
includeInStateLogs: true,
persist: true,
anonymous: false,
usedInUi: true,
},
trialedProducts: {
includeInStateLogs: true,
persist: true,
anonymous: true,
usedInUi: true,
},
pricing: {
includeInStateLogs: true,
persist: true,
Expand Down Expand Up @@ -242,11 +257,13 @@ export class SubscriptionController extends BaseController<
}

async getSubscriptions() {
const { subscriptions } =
const { subscriptions, customerId, trialedProducts } =
await this.#subscriptionService.getSubscriptions();

this.update((state) => {
state.subscriptions = subscriptions;
state.customerId = customerId;
state.trialedProducts = trialedProducts;
});

return subscriptions;
Expand Down
Loading