diff --git a/apps/api-e2e/src/api/account-links.spec.ts b/apps/api-e2e/src/api/account-links.spec.ts new file mode 100644 index 0000000..024ae54 --- /dev/null +++ b/apps/api-e2e/src/api/account-links.spec.ts @@ -0,0 +1,40 @@ +import { CreatePayableAccount, CreatePlatform, Platform } from '../support/Api'; + +/** + * Stripe lets a request for an account link leave out where the seller is + * sent back to. The link is made all the same. + */ +describe('An account link', () => { + let platform: Platform; + let account: string; + + beforeAll(async () => { + platform = await CreatePlatform('Account links E2E'); + account = await CreatePayableAccount(platform.api); + }); + + it('is created without a refresh or a return URL', async () => { + const { data: link } = await platform.api.post('/account_links', { + account, + type: 'account_onboarding', + }); + + expect(link.object).toBe('account_link'); + expect(link.url).toContain('/onboard?token='); + }); + + it('is refused when a URL it is given is not one', async () => { + await expect( + platform.api.post('/account_links', { + account, + type: 'account_onboarding', + return_url: 'not a url', + }) + ).rejects.toMatchObject({ + response: { + status: 400, + data: { error: { type: 'invalid_request_error' } }, + }, + }); + }); +}); diff --git a/apps/api/src/__tests__/AccountLink.spec.ts b/apps/api/src/__tests__/AccountLink.spec.ts index 62e3cc8..84d2367 100644 --- a/apps/api/src/__tests__/AccountLink.spec.ts +++ b/apps/api/src/__tests__/AccountLink.spec.ts @@ -57,6 +57,22 @@ describe('AccountLinkModule', () => { }); }); + describe('CreateAccountLinkRecord without its URLs', () => { + it('should store none, as Stripe lets a request leave them out', () => { + const record = module.CreateAccountLinkRecord( + 'acct_z_1', + 'account_onboarding' + ); + + expect(record).toMatchObject({ + account: 'acct_z_1', + refresh_url: null, + return_url: null, + }); + expect(record.url).toContain('/onboard?token='); + }); + }); + describe('CreateAccountLink', () => { it('should persist the record and return the public response', async () => { const link = await module.CreateAccountLink( diff --git a/apps/api/src/modules/AccountLink.ts b/apps/api/src/modules/AccountLink.ts index 17fc49b..314cb34 100644 --- a/apps/api/src/modules/AccountLink.ts +++ b/apps/api/src/modules/AccountLink.ts @@ -45,15 +45,15 @@ export class AccountLinkModule { * * @param account - The identifier of the account to create an account link for * @param type - The type of account link (account_onboarding or account_update) - * @param refreshUrl - URL to redirect to if link is expired/invalid - * @param returnUrl - URL to redirect to upon leaving or completing the flow + * @param refreshUrl - URL to redirect to if link is expired/invalid, if any + * @param returnUrl - URL to redirect to upon leaving or completing the flow, if any * @returns The AccountLink API response (Stripe-compatible) */ async CreateAccountLink( account: string, type: AccountLinkType, - refreshUrl: string, - returnUrl: string + refreshUrl?: string, + returnUrl?: string ): Promise { const record = this.CreateAccountLinkRecord( account, @@ -72,8 +72,8 @@ export class AccountLinkModule { CreateAccountLinkRecord( account: string, type: AccountLinkType, - refreshUrl: string, - returnUrl: string + refreshUrl?: string, + returnUrl?: string ): AccountLinkRecord { const { dashboardUrl } = GetAppConfig(); const timestamp = Now(); @@ -90,8 +90,8 @@ export class AccountLinkModule { token: token, account: account, type: type, - refresh_url: refreshUrl, - return_url: returnUrl, + refresh_url: refreshUrl ?? null, + return_url: returnUrl ?? null, consumed: false, }; diff --git a/apps/api/src/routes/exchange.routes.ts b/apps/api/src/routes/exchange.routes.ts index 3c8e0ae..a26dff4 100644 --- a/apps/api/src/routes/exchange.routes.ts +++ b/apps/api/src/routes/exchange.routes.ts @@ -141,8 +141,8 @@ router.post( if (linkType === 'account_link') { const accountLink = link as AccountLinkRecord; context.link_type = accountLink.type; - context.return_url = accountLink.return_url; - context.refresh_url = accountLink.refresh_url; + context.return_url = accountLink.return_url ?? undefined; + context.refresh_url = accountLink.refresh_url ?? undefined; } res.json({ token: sessionToken, context }); diff --git a/apps/docs/src/app/pages/docs/data/generated/account-links.ts b/apps/docs/src/app/pages/docs/data/generated/account-links.ts index 85f33ac..9f87b32 100644 --- a/apps/docs/src/app/pages/docs/data/generated/account-links.ts +++ b/apps/docs/src/app/pages/docs/data/generated/account-links.ts @@ -115,14 +115,12 @@ export const ACCOUNT_LINKS_PAGES: DocPage[] = [ type: 'string', description: "The URL the user will be redirected to if the account link is expired, has been previously visited, or is otherwise invalid. It should generate a new account link with the same parameters and redirect the user to that link's URL.", - required: true, }, { name: 'return_url', type: 'string', description: 'The URL that the user will be redirected to upon leaving or completing the linked flow.', - required: true, }, { name: 'type', diff --git a/libs/openapi/openapi.json b/libs/openapi/openapi.json index a9cd27c..9e775ca 100644 --- a/libs/openapi/openapi.json +++ b/libs/openapi/openapi.json @@ -459,14 +459,14 @@ "description": "The identifier of the account to create an account link for." }, "refresh_url": { + "description": "The URL the user will be redirected to if the account link is expired, has been previously visited, or is otherwise invalid. It should generate a new account link with the same parameters and redirect the user to that link's URL.", "type": "string", - "format": "uri", - "description": "The URL the user will be redirected to if the account link is expired, has been previously visited, or is otherwise invalid. It should generate a new account link with the same parameters and redirect the user to that link's URL." + "format": "uri" }, "return_url": { + "description": "The URL that the user will be redirected to upon leaving or completing the linked flow.", "type": "string", - "format": "uri", - "description": "The URL that the user will be redirected to upon leaving or completing the linked flow." + "format": "uri" }, "type": { "type": "string", @@ -478,7 +478,7 @@ } } }, - "required": ["account", "type", "refresh_url", "return_url"] + "required": ["account", "type"] }, "example": { "account": "acct_z_1Nv0FGQ9RKHgCVdK", diff --git a/libs/shared-schemas/src/lib/AccountLinkSchema.ts b/libs/shared-schemas/src/lib/AccountLinkSchema.ts index a790f95..0482cbc 100644 --- a/libs/shared-schemas/src/lib/AccountLinkSchema.ts +++ b/libs/shared-schemas/src/lib/AccountLinkSchema.ts @@ -23,12 +23,14 @@ export const CreateAccountLinkSchema = z.object({ refresh_url: z .string() .url('Refresh URL must be a valid URL') + .optional() .describe( "The URL the user will be redirected to if the account link is expired, has been previously visited, or is otherwise invalid. It should generate a new account link with the same parameters and redirect the user to that link's URL." ), return_url: z .string() .url('Return URL must be a valid URL') + .optional() .describe( 'The URL that the user will be redirected to upon leaving or completing the linked flow.' ), diff --git a/libs/shared-types/src/lib/AccountLink.ts b/libs/shared-types/src/lib/AccountLink.ts index 192b530..1708842 100644 --- a/libs/shared-types/src/lib/AccountLink.ts +++ b/libs/shared-types/src/lib/AccountLink.ts @@ -60,11 +60,11 @@ export interface AccountLinkRecord extends AccountLink { /** The type of account link */ type: AccountLinkType; - /** URL to redirect to if link is expired or invalid */ - refresh_url: string; + /** URL to redirect to if link is expired or invalid, if one was given */ + refresh_url: string | null; - /** URL to redirect to when user completes or leaves the flow */ - return_url: string; + /** URL to redirect to when user completes or leaves the flow, if one was given */ + return_url: string | null; /** Whether this link has been used */ consumed: boolean; diff --git a/sdks/node/src/generated/Inputs.ts b/sdks/node/src/generated/Inputs.ts index 5e8409c..adb3302 100644 --- a/sdks/node/src/generated/Inputs.ts +++ b/sdks/node/src/generated/Inputs.ts @@ -195,8 +195,8 @@ export type CreateAccountInput = { export type CreateAccountLinkInput = { account: string; type: 'account_onboarding' | 'account_update'; - refresh_url: string; - return_url: string; + refresh_url?: string | undefined; + return_url?: string | undefined; }; export type CreateChargeInput = { diff --git a/sdks/php/lib/Service/AccountLinkService.php b/sdks/php/lib/Service/AccountLinkService.php index db7621e..91b55d1 100644 --- a/sdks/php/lib/Service/AccountLinkService.php +++ b/sdks/php/lib/Service/AccountLinkService.php @@ -16,7 +16,7 @@ class AccountLinkService extends AbstractService * platform can redirect their user to in order to take them through the * onboarding flow. Account links expire after 1 hour. * - * @param null|array{account: string, refresh_url: string, return_url: string, type: string} $params + * @param null|array{account: string, refresh_url?: string, return_url?: string, type: string} $params * @param null|RequestOptionsArray|\Zoneless\Util\RequestOptions $opts * * @return \Zoneless\AccountLink diff --git a/sdks/python/zoneless/params/_account_link_create_params.py b/sdks/python/zoneless/params/_account_link_create_params.py index cbc901a..ff1416c 100644 --- a/sdks/python/zoneless/params/_account_link_create_params.py +++ b/sdks/python/zoneless/params/_account_link_create_params.py @@ -10,11 +10,11 @@ class AccountLinkCreateParams(TypedDict): """ The identifier of the account to create an account link for. """ - refresh_url: str + refresh_url: NotRequired[str] """ The URL the user will be redirected to if the account link is expired, has been previously visited, or is otherwise invalid. It should generate a new account link with the same parameters and redirect the user to that link's URL. """ - return_url: str + return_url: NotRequired[str] """ The URL that the user will be redirected to upon leaving or completing the linked flow. """