Skip to content

[Feature]: Supported currencies const list #215

Description

@nbolton

Tell us about your feature request

It would be useful to know the currently supported currencies so we don't have to maintain our own hard-coded list which gets out of sync with your internal list inside the SDK.

What problem are you looking to solve?

We allow the customer to change the currency for price preview, as some customers want to pay in currencies other than the default one for their country (e.g. Chinese customers travelling to Hong Kong).

The currencies are shown in a drop down, and maintaining our own list is fragile as it requires us to manually audit the Paddle docs/SDK for new currencies (e.g. v3.6.1 released last week added CLP and PEN).

Additional context

My workaround is to parse the contents of node_modules/@paddle/paddle-node-sdk/dist/types/enums/shared/currency-code.d.ts and write our own file with a list, and make that an automatic part of our toolchain:

  const sdkEntry = require.resolve("@paddle/paddle-node-sdk");
  const dtsPath = sdkEntry.replace(/dist\/.*/, "dist/types/enums/shared/currency-code.d.ts");
  const outputPath = resolve(context.root, options.outputPath);

  const source = readFileSync(dtsPath, "utf-8");
  const codes = Array.from(source.matchAll(/'([A-Z]{3})'/g), (m) => m[1]);

  if (codes.length === 0) {
    throw new Error("No currency codes found in Paddle SDK type definition");
  }

  const output = `// Auto-generated from @paddle/paddle-node-sdk CurrencyCode type.
import type { CurrencyCode } from "@paddle/paddle-node-sdk";

export const paddleCurrencies: CurrencyCode[] = [
${codes.map((code) => `  "${code}",`).join("\n")}
];
`;

  writeFileSync(outputPath, output);
  console.log(`Generated ${codes.length} currency codes to ${outputPath}`);

How important is this suggestion to you?

Nice to have

It's an easy fix when new currencies get added, as you get compile error so you simply need to add the missing entries... a list from the SDK would simply be a developer convenience (we wouldn't need to maintain our own list).

Just a thought, if CurrencyCode was an enum, developers could iterate over it with Object.values(CurrencyCode) as they survive compilation as runtime objects but I imagine you'll want to keep the type because of many SDK-related reasons.

Edit: Feel free to close this if it's a silly idea.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions