Skip to content

Framework adapters: create customer portal by external customer ID #7914

@mruijzendaal

Description

@mruijzendaal

Feature request

Is your feature request related to a problem?

The current recommended way to easily create customer portals with framework adapters is as follows.

// /api/portal/+server.ts
import { CustomerPortal } from "@polar-sh/sveltekit";

export const GET = CustomerPortal({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
  getCustomerId: (event) => "", // Function to resolve a Polar Customer ID
  returnUrl: "https://myapp.com", // An optional URL which renders a back-button in the Customer Portal
  server: "sandbox", // Use sandbox if you're testing Polar - omit the parameter or pass 'production' otherwise
});

The snippet above is for SvelteKit, but NextJS and others look similar. We are leaning into Polar's ability to call APIs with the Polar external customer IDs (i.e. our internal ID) rather than the customer ID (i.e. Polar's internal ID). As such, the current implementation of CustomerPortal with getCustomerId is inconvenient.

Describe the solution you'd like

We'd like to be able to do the following:

// /api/portal/+server.ts
import { CustomerPortal } from "@polar-sh/sveltekit";

export const GET = CustomerPortal({
  accessToken: process.env.POLAR_ACCESS_TOKEN,
-  getCustomerId: (event) => "", // Function to resolve a Polar Customer ID
+  getExternalCustomerId: (event) => "", // Function to resolve a Polar External Customer ID
  returnUrl: "https://myapp.com", // An optional URL which renders a back-button in the Customer Portal
  server: "sandbox", // Use sandbox if you're testing Polar - omit the parameter or pass 'production' otherwise
});

Describe alternatives you've considered

We can ofcourse just call polar.getExternal() inside getCustomerId. We believe this to be unnecessary because the Polar SDK is capable of dealing with external IDs just as well. Therefore CustomerPortal could be tweaked to allow a getExternalCustomerId argument.

Additional context

We'll submit a pull request for a SvelteKit implementation in a few minutes. This is already working for us internally, but I'm sure it would benefit from a technical review. Similar changes could be made for the other supported frameworks, but these are outside my use case and expertise for now.

Thanks for considering!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions