Skip to content

Commit 6468561

Browse files
feat(Transaction): Added transactions.revise operation (#100)
1 parent 9b9902c commit 6468561

File tree

9 files changed

+89
-1
lines changed

9 files changed

+89
-1
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ 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.4.0 - 2025-01-21
16+
17+
### Added
18+
19+
- Added `transactions.revise` operation to revise a transaction and added `revisedAt` to `Transaction` entity, see [related changelog](https://developer.paddle.com/changelog/2024/revise-transaction-customer-information?utm_source=dx&utm_medium=paddle-node-sdk).
20+
21+
### Changed
22+
23+
- Dependabot updates
24+
25+
---
26+
1527
## 2.3.2 - 2025-01-06
1628

1729
### Fixed

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.3.2",
3+
"version": "2.4.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",

src/__tests__/mocks/resources/transactions.mock.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {
88
CreateTransactionRequestBody,
9+
ReviseTransactionRequestBody,
910
TransactionPreviewRequestBody,
1011
UpdateTransactionRequestBody,
1112
} from '../../../resources/index.js';
@@ -62,6 +63,22 @@ export const UpdateTransactionMock: UpdateTransactionRequestBody = {
6263
checkout: { url: 'NO_VALUE' },
6364
};
6465

66+
export const ReviseTransactionMock: ReviseTransactionRequestBody = {
67+
address: {
68+
firstLine: '3811 Ditmars Blvd',
69+
secondLine: 'Suite 435',
70+
city: 'Astoria',
71+
region: 'NY',
72+
},
73+
business: {
74+
name: 'Maryjane',
75+
taxIdentifier: 'AB0123456789',
76+
},
77+
customer: {
78+
name: 'Maryjane',
79+
},
80+
};
81+
6582
export const CreateTransactionExpectation = {
6683
status: 'draft',
6784
customer_id: 'ctm_01grnn4zta5a1mf02jjze7y2ys',
@@ -269,6 +286,7 @@ export const TransactionMock: ITransactionResponse = {
269286
created_at: '2024-10-12T07:20:50.52Z',
270287
updated_at: '2024-10-13T07:20:50.52Z',
271288
billed_at: '2024-10-12T07:20:50.52Z',
289+
revised_at: '2024-10-12T07:20:50.52Z',
272290
adjustments: [
273291
{
274292
action: 'credit',

src/__tests__/resources/transactions.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CreateTransactionMock,
1111
ListTransactionMockResponse,
1212
PreviewTransactionMock,
13+
ReviseTransactionMock,
1314
TransactionMock,
1415
TransactionMockResponse,
1516
TransactionPreviewMockResponse,
@@ -20,6 +21,7 @@ import {
2021
CreateTransactionRequestBody,
2122
GetTransactionQueryParameters,
2223
ListTransactionQueryParameters,
24+
ReviseTransactionRequestBody,
2325
TransactionsResource,
2426
UpdateTransactionRequestBody,
2527
} from '../../resources/index.js';
@@ -144,4 +146,18 @@ describe('TransactionsResource', () => {
144146
expect(paddleInstance.post).toBeCalledWith(`/transactions/preview`, PreviewTransactionMock);
145147
expect(updatedTransaction).toBeDefined();
146148
});
149+
150+
test('should be able to revise an existing transaction', async () => {
151+
const transactionId = TransactionMock.id;
152+
const transactionToBeRevised: ReviseTransactionRequestBody = ReviseTransactionMock;
153+
154+
const paddleInstance = getPaddleTestClient();
155+
paddleInstance.post = jest.fn().mockResolvedValue(TransactionMockResponse);
156+
157+
const transactionsResource = new TransactionsResource(paddleInstance);
158+
const revisedTransaction = await transactionsResource.revise(transactionId, transactionToBeRevised);
159+
160+
expect(paddleInstance.post).toBeCalledWith(`/transactions/${transactionId}/revise`, transactionToBeRevised);
161+
expect(revisedTransaction).toBeDefined();
162+
});
147163
});

src/entities/transaction/transaction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class Transaction {
5151
public readonly createdAt: string;
5252
public readonly updatedAt: string;
5353
public readonly billedAt: string | null;
54+
public readonly revisedAt: string | null;
5455
public readonly address: Address | null;
5556
public readonly adjustments: TransactionAdjustment[] | null;
5657
public readonly adjustmentsTotals: AdjustmentTotals | null;
@@ -82,6 +83,7 @@ export class Transaction {
8283
this.createdAt = transaction.created_at;
8384
this.updatedAt = transaction.updated_at;
8485
this.billedAt = transaction.billed_at ? transaction.billed_at : null;
86+
this.revisedAt = transaction.revised_at ? transaction.revised_at : null;
8587
this.address = transaction.address ? new Address(transaction.address) : null;
8688
this.adjustments = transaction.adjustments
8789
? transaction.adjustments?.map((adjustment) => new TransactionAdjustment(adjustment))

src/resources/transactions/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type GetTransactionInvoicePdfQueryParameters,
1212
type GetTransactionQueryParameters,
1313
type ListTransactionQueryParameters,
14+
type ReviseTransactionRequestBody,
1415
type TransactionPreviewRequestBody,
1516
type UpdateTransactionQueryParameters,
1617
type UpdateTransactionRequestBody,
@@ -30,6 +31,7 @@ const TransactionPaths = {
3031
update: '/transactions/{transaction_id}',
3132
getInvoicePDF: '/transactions/{transaction_id}/invoice',
3233
preview: '/transactions/preview',
34+
revise: '/transactions/{transaction_id}/revise',
3335
} as const;
3436

3537
export * from './operations/index.js';
@@ -120,4 +122,19 @@ export class TransactionsResource extends BaseResource {
120122

121123
return new TransactionPreview(data);
122124
}
125+
126+
public async revise(transactionId: string, reviseTransaction: ReviseTransactionRequestBody): Promise<Transaction> {
127+
const urlWithPathParams = new PathParameters(TransactionPaths.revise, {
128+
transaction_id: transactionId,
129+
}).deriveUrl();
130+
131+
const response = await this.client.post<
132+
ReviseTransactionRequestBody,
133+
Response<ITransactionResponse> | ErrorResponse
134+
>(urlWithPathParams, reviseTransaction);
135+
136+
const data = this.handleResponse<ITransactionResponse>(response);
137+
138+
return new Transaction(data);
139+
}
123140
}

src/resources/transactions/operations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './get-transaction-query-parameters.js';
1212
export * from './update-transaction-request-body.js';
1313
export * from './transaction-preview-request-body.js';
1414
export * from './get-transaction-invoice-pdf-query-parameters.js';
15+
export * from './revise-transaction-request-body.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+
export interface ReviseTransactionRequestBody {
8+
customer?: {
9+
name?: string;
10+
};
11+
business?: {
12+
name?: string;
13+
taxIdentifier?: string;
14+
};
15+
address?: {
16+
firstLine?: string;
17+
secondLine?: string | null;
18+
city?: string;
19+
region?: string;
20+
};
21+
}

src/types/transaction/transaction-response.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface ITransactionResponse {
5050
created_at: string;
5151
updated_at: string;
5252
billed_at?: string | null;
53+
revised_at?: string | null;
5354
address?: IAddressResponse | null;
5455
adjustments?: ITransactionAdjustmentResponse[] | null;
5556
adjustments_totals?: IAdjustmentTotalsResponse | null;

0 commit comments

Comments
 (0)