Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 40 additions & 0 deletions apps/api-e2e/src/api/account-links.spec.ts
Original file line number Diff line number Diff line change
@@ -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' } },
},
});
});
});
16 changes: 16 additions & 0 deletions apps/api/src/__tests__/AccountLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions apps/api/src/modules/AccountLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountLink> {
const record = this.CreateAccountLinkRecord(
account,
Expand All @@ -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();
Expand All @@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/exchange.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
2 changes: 0 additions & 2 deletions apps/docs/src/app/pages/docs/data/generated/account-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions libs/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -478,7 +478,7 @@
}
}
},
"required": ["account", "type", "refresh_url", "return_url"]
"required": ["account", "type"]
},
"example": {
"account": "acct_z_1Nv0FGQ9RKHgCVdK",
Expand Down
2 changes: 2 additions & 0 deletions libs/shared-schemas/src/lib/AccountLinkSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
),
Expand Down
8 changes: 4 additions & 4 deletions libs/shared-types/src/lib/AccountLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sdks/node/src/generated/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion sdks/php/lib/Service/AccountLinkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdks/python/zoneless/params/_account_link_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down