Skip to content

Commit a3a192d

Browse files
Dan Billsondavidgrayston-paddle
andauthored
Customer Portal Sessions (#74)
* feat: add customer portal session resource * chore: remove unused mock Co-authored-by: davidgrayston-paddle <david.grayston@paddle.com> * test: add url assertion --------- Co-authored-by: davidgrayston-paddle <david.grayston@paddle.com>
1 parent af27a2f commit a3a192d

File tree

21 files changed

+273
-1
lines changed

21 files changed

+273
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ When we make [non-breaking changes](https://developer.paddle.com/api-reference/a
1212

1313
This means when upgrading minor versions of the SDK, you may notice type errors. You can safely ignore these or fix by adding additional type guards.
1414

15+
## 2.1.0 - 2024-11-21
16+
17+
### Added
18+
19+
- Added `customerPortalSessions` resources
20+
1521
## 2.0.0 - 2024-11-20
1622

1723
> **Breaking changes:** This version includes major improvements that introduce breaking changes. These are called out below.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@paddle/paddle-node-sdk",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "A Node.js SDK that you can use to integrate Paddle Billing with applications written in server-side JavaScript.",
55
"main": "dist/cjs/index.cjs.node.js",
66
"module": "dist/esm/index.esm.node.js",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { ICustomerPortalSessionResponse } from '../../../types/index.js';
8+
import { Response, ResponsePaginated } from '../../../internal/index.js';
9+
10+
export const CustomerPortalSessionMock: ICustomerPortalSessionResponse = {
11+
id: 'cpls_01h4ge9r64c22exjsx0fy8b48b',
12+
customer_id: 'ctm_123',
13+
urls: {
14+
general: {
15+
overview:
16+
'https://customer-portal.paddle.com/cpl_01j7zbyqs3vah3aafp4jf62qaw?action=overview&token=pga_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjdG1fMDFncm5uNHp0YTVhMW1mMDJqanplN3kyeXMiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3Mjc2NzkyMzh9._oO12IejzdKmyKTwb7BLjmiILkx4_cSyGjXraOBUI_g',
17+
},
18+
subscriptions: [
19+
{
20+
id: 'sub_123',
21+
cancel_subscription:
22+
'https://customer-portal.paddle.com/cpl_01j7zbyqs3vah3aafp4jf62qaw?action=cancel_subscription&subscription_id=sub_01h04vsc0qhwtsbsxh3422wjs4&token=pga_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjdG1fMDFncm5uNHp0YTVhMW1mMDJqanplN3kyeXMiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3Mjc2NzkyMzh9._oO12IejzdKmyKTwb7BLjmiILkx4_cSyGjXraOBUI_g',
23+
update_subscription_payment_method:
24+
'https://customer-portal.paddle.com/cpl_01j7zbyqs3vah3aafp4jf62qaw?action=update_subscription_payment_method&subscription_id=sub_01h04vsc0qhwtsbsxh3422wjs4&token=pga_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjdG1fMDFncm5uNHp0YTVhMW1mMDJqanplN3kyeXMiLCJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE3Mjc2NzkyMzh9._oO12IejzdKmyKTwb7BLjmiILkx4_cSyGjXraOBUI_g',
25+
},
26+
],
27+
},
28+
created_at: '2024-10-25T06:53:58Z',
29+
};
30+
31+
export const CustomerPortalSessionMockResponse: Response<ICustomerPortalSessionResponse> = {
32+
data: CustomerPortalSessionMock,
33+
meta: {
34+
request_id: '',
35+
},
36+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { CustomerPortalSessionsResource } from '../../resources/index.js';
8+
import { getPaddleTestClient } from '../helpers/test-client.js';
9+
import {
10+
CustomerPortalSessionMockResponse,
11+
CustomerPortalSessionMock,
12+
} from '../mocks/resources/customer-portal-sessions.mock.js';
13+
14+
describe('CustomerPortalSessionsResource', () => {
15+
test('should create a new customer portal session', async () => {
16+
const customerId = CustomerPortalSessionMock.customer_id;
17+
const subscriptionIds = ['sub_123'];
18+
const paddleInstance = getPaddleTestClient();
19+
paddleInstance.post = jest.fn().mockResolvedValue(CustomerPortalSessionMockResponse);
20+
21+
const customerPortalSessionsResource = new CustomerPortalSessionsResource(paddleInstance);
22+
const createdCustomerPortalSession = await customerPortalSessionsResource.create(customerId, subscriptionIds);
23+
24+
expect(paddleInstance.post).toBeCalledWith(`/customers/${customerId}/portal-sessions`, {
25+
subscriptionIds,
26+
});
27+
expect(createdCustomerPortalSession).toBeDefined();
28+
expect(createdCustomerPortalSession.id).toBeDefined();
29+
expect(createdCustomerPortalSession.customerId).toBe(customerId);
30+
expect(createdCustomerPortalSession.urls.subscriptions[0].id).toBe(subscriptionIds[0]);
31+
});
32+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { type ICustomerPortalSessionResponse } from '../../types/index.js';
8+
import { Urls } from './urls.js';
9+
10+
export class CustomerPortalSession {
11+
public readonly id: string;
12+
public readonly customerId: string | null;
13+
public readonly urls: Urls;
14+
public readonly createdAt: string;
15+
16+
constructor(customerPortalSessionResponse: ICustomerPortalSessionResponse) {
17+
this.id = customerPortalSessionResponse.id;
18+
this.customerId = customerPortalSessionResponse.customer_id;
19+
this.urls = new Urls(customerPortalSessionResponse.urls);
20+
this.createdAt = customerPortalSessionResponse.created_at;
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { type ICustomerPortalSubscriptionUrl } from '../../types/index.js';
8+
9+
export class CustomerPortalSubscriptionUrl {
10+
public readonly id: string;
11+
public readonly cancelSubscription: string;
12+
public readonly updateSubscriptionPaymentMethod: string;
13+
14+
constructor(customerPortalSubscriptionUrlResponse: ICustomerPortalSubscriptionUrl) {
15+
this.id = customerPortalSubscriptionUrlResponse.id;
16+
this.cancelSubscription = customerPortalSubscriptionUrlResponse.cancel_subscription;
17+
this.updateSubscriptionPaymentMethod = customerPortalSubscriptionUrlResponse.update_subscription_payment_method;
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { type IGeneralResponse } from '../../types/index.js';
8+
9+
export class General {
10+
public readonly overview: string;
11+
12+
constructor(generalResponse: IGeneralResponse) {
13+
this.overview = generalResponse.overview;
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export * from './customer-portal-subscription-url.js';
8+
export * from './customer-portal-session.js';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { type IUrlsResponse } from '../../types/index.js';
8+
import { General } from './general.js';
9+
import { CustomerPortalSubscriptionUrl } from './customer-portal-subscription-url.js';
10+
11+
export class Urls {
12+
public readonly general: General;
13+
public readonly subscriptions: CustomerPortalSubscriptionUrl[];
14+
15+
constructor(urlsResponse: IUrlsResponse) {
16+
this.general = new General(urlsResponse.general);
17+
this.subscriptions = urlsResponse.subscriptions?.map(
18+
(subscription) => new CustomerPortalSubscriptionUrl(subscription) ?? [],
19+
);
20+
}
21+
}

src/entities/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from './price/index.js';
1010
export * from './transaction/index.js';
1111
export * from './adjustment/index.js';
1212
export * from './customer/index.js';
13+
export * from './customer-portal-session/index.js';
1314
export * from './business/index.js';
1415
export * from './subscription/index.js';
1516
export * from './address/index.js';

0 commit comments

Comments
 (0)