Skip to content

Commit 40df963

Browse files
committed
fix: resolve CheckoutSessions Invalid URL error
Fix URL construction creating double slashes in CheckoutSessions endpoints. Updated basePath handling to prevent malformed URLs like https://api.pay.magpie.im//cs_123.
1 parent 2b6a7d3 commit 40df963

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/resources/base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ export abstract class BaseResource {
4343
* @protected
4444
*/
4545
protected buildPath(id?: string): string {
46-
return id ? `${this.basePath}/${id}` : this.basePath;
46+
if (!id) {
47+
return this.basePath;
48+
}
49+
50+
// Handle empty basePath (used for resources with custom base URLs)
51+
if (this.basePath === '') {
52+
return id;
53+
}
54+
55+
return `${this.basePath}/${id}`;
4756
}
4857

4958
/**

src/resources/sessions.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('CheckoutSessionsResource', () => {
2323

2424
expect(magpie.LAST_REQUEST).toMatchObject({
2525
method: 'POST',
26-
url: expect.stringContaining('/'),
26+
url: expect.stringContaining(''),
2727
data: sessionData
2828
});
2929
});
@@ -86,7 +86,7 @@ describe('CheckoutSessionsResource', () => {
8686

8787
expect(magpie.LAST_REQUEST).toMatchObject({
8888
method: 'GET',
89-
url: expect.stringContaining(`/${sessionId}`)
89+
url: expect.stringContaining(sessionId)
9090
});
9191
});
9292

@@ -116,7 +116,7 @@ describe('CheckoutSessionsResource', () => {
116116

117117
expect(magpie.LAST_REQUEST).toMatchObject({
118118
method: 'POST',
119-
url: expect.stringContaining(`/${sessionId}/capture`),
119+
url: expect.stringContaining(`${sessionId}/capture`),
120120
data: captureData
121121
});
122122
});
@@ -154,7 +154,7 @@ describe('CheckoutSessionsResource', () => {
154154

155155
expect(magpie.LAST_REQUEST).toMatchObject({
156156
method: 'POST',
157-
url: expect.stringContaining(`/${sessionId}/expire`)
157+
url: expect.stringContaining(`${sessionId}/expire`)
158158
});
159159
});
160160

src/resources/sessions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class CheckoutSessionsResource extends BaseResource {
4444
*/
4545
constructor(client: BaseClient) {
4646
// Use different base URL for checkout sessions
47-
super(client, '/', 'https://api.pay.magpie.im');
47+
super(client, '', 'https://api.pay.magpie.im');
4848
}
4949

5050
/**

0 commit comments

Comments
 (0)