Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 27 additions & 2 deletions __tests__/paddle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ describe('plus pricing metadata', () => {

describe('plus pricing preview', () => {
const QUERY = /* GraphQL */ `
query PricingPreview($type: PricingType) {
pricingPreview(type: $type) {
query PricingPreview($type: PricingType, $locale: String) {
pricingPreview(type: $type, locale: $locale) {
metadata {
appsId
title
Expand Down Expand Up @@ -562,6 +562,31 @@ describe('plus pricing preview', () => {

expect(result).toEqual(result2);
});

it('should format prices according to locale', async () => {
loggedUser = 'whp-1';
const result = await client.query(QUERY, {
variables: {
type: PricingType.Plus,
locale: 'de-DE',
},
});
expect(result.data.pricingPreview).toHaveLength(1);
const preview = result.data.pricingPreview[0];
expect(preview.price.formatted).toMatch(/€\d+,\d+/); // German format with € and comma
});

it('should use default locale when not specified', async () => {
loggedUser = 'whp-1';
const result = await client.query(QUERY, {
variables: {
type: PricingType.Plus,
},
});
expect(result.data.pricingPreview).toHaveLength(1);
const preview = result.data.pricingPreview[0];
expect(preview.price.formatted).toMatch(/\$\d+\.\d+/); // Default USD format
});
});

describe('plus subscription', () => {
Expand Down
10 changes: 7 additions & 3 deletions src/schema/paddle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export const typeDefs = /* GraphQL */ `
pricePreviews: PricePreviews! @auth
corePricePreviews: PricePreviews! @auth
pricingMetadata(type: PricingType): [ProductPricingMetadata!]! @auth
pricingPreview(type: PricingType): [ProductPricingPreview!]! @auth
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@capJavert also removed the @auth directive since we don't require auth for requesting the prices anymore. For example, on Funnel.

pricingPreview(
type: PricingType
locale: String
): [ProductPricingPreview!]! @auth
}

${toGQLEnum(PricingType, 'PricingType')}
Expand Down Expand Up @@ -275,6 +278,7 @@ export interface GQLCustomData {

interface PaddlePricingPreviewArgs {
type?: PricingType;
locale?: string;
}

export const resolvers: IResolvers<unknown, AuthContext> = traceResolvers<
Expand Down Expand Up @@ -389,7 +393,7 @@ export const resolvers: IResolvers<unknown, AuthContext> = traceResolvers<
): Promise<BasePricingMetadata[]> => getPricingMetadata(ctx, type),
pricingPreview: async (
_,
{ type = PricingType.Plus }: PaddlePricingPreviewArgs,
{ type = PricingType.Plus, locale }: PaddlePricingPreviewArgs,
ctx,
): Promise<BasePricingPreview[]> => {
const metadata = await getPricingMetadata(ctx, type);
Expand All @@ -416,7 +420,7 @@ export const resolvers: IResolvers<unknown, AuthContext> = traceResolvers<
return {
metadata: meta,
priceId: item.price.id,
price: getProductPrice(item),
price: getProductPrice(item, locale),
currency: {
code: preview.currencyCode,
symbol: removeNumbers(item.formattedTotals.total),
Expand Down
Loading