-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd6787c
commit e0db151
Showing
5 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use server"; | ||
import { SubscriptionOfferingFilter, SubscriptionOffering } from "@elasticpath/js-sdk"; | ||
import { ElasticPath } from "@elasticpath/js-sdk"; | ||
|
||
export async function getSubscriptionOfferingsByProductId(client: ElasticPath, productId: string) { | ||
if (!client?.SubscriptionOfferings) return []; | ||
|
||
const filter : SubscriptionOfferingFilter = { | ||
eq: { | ||
"products.external_ref": productId | ||
} | ||
} | ||
try { | ||
const response = await client.SubscriptionOfferings | ||
.Filter(filter) | ||
.With(['plans', 'products'] as const) | ||
.All(); | ||
|
||
// @ts-ignore - Ignoring type issues as we know the structure is correct | ||
return { | ||
offerings: response.data || [], | ||
plans: response.included?.plans || [] | ||
}; | ||
} catch (error) { | ||
console.error('Error fetching subscription offerings:', error); | ||
return { offerings: [], plans: [] }; | ||
} | ||
} | ||
|