Skip to content

Commit c5c372c

Browse files
TimmyGuyjanpaepke
authored andcommitted
Add update and delete methods for payment links
Introduce `update` and `delete` functionality to the `PaymentLinksBinder`. The `update` method allows modifying payment link details, while the `delete` method enables removal of payment links. Also, extend `parameters.ts` to include `UpdateParameters` for supporting these changes.
1 parent 4d3e88b commit c5c372c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/binders/paymentLinks/PaymentLinksBinder.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import assertWellFormedId from '../../plumbing/assertWellFormedId';
66
import renege from '../../plumbing/renege';
77
import type Callback from '../../types/Callback';
88
import Binder from '../Binder';
9-
import { type CreateParameters, type GetParameters, type IterateParameters, type PageParameters } from './parameters';
9+
import {
10+
type CreateParameters,
11+
type GetParameters,
12+
type IterateParameters,
13+
type PageParameters,
14+
type UpdateParameters,
15+
} from './parameters';
1016

1117
const pathSegment = 'payment-links';
1218

@@ -68,4 +74,30 @@ export default class PaymentsLinksBinder extends Binder<PaymentLinkData, Payment
6874
const { valuesPerMinute, ...query } = parameters ?? {};
6975
return this.networkClient.iterate<PaymentLinkData, PaymentLink>(pathSegment, 'payment_links', query, valuesPerMinute);
7076
}
77+
78+
/**
79+
* Update a payment link object by its token.
80+
*
81+
* @see https://docs.mollie.com/reference/update-payment-link
82+
*/
83+
public update(id: string, parameters: Partial<UpdateParameters>): Promise<PaymentLink>;
84+
public update(id: string, parameters: Partial<UpdateParameters>, callback: Callback<PaymentLink>): void;
85+
public update(id: string, parameters: Partial<UpdateParameters>) {
86+
if (renege(this, this.update, ...arguments)) return;
87+
assertWellFormedId(id, 'payment-link');
88+
return this.networkClient.patch<PaymentLinkData, PaymentLink>(`${pathSegment}/${id}`, parameters);
89+
}
90+
91+
/**
92+
* Delete a payment link object by its token.
93+
*
94+
* @see https://docs.mollie.com/reference/delete-payment-link
95+
*/
96+
public delete(id: string): Promise<true>;
97+
public delete(id: string, callback: Callback<true>): void;
98+
public delete(id: string) {
99+
if (renege(this, this.delete, ...arguments)) return;
100+
assertWellFormedId(id, 'payment-link');
101+
return this.networkClient.delete<PaymentLinkData, true>(`${pathSegment}/${id}`);
102+
}
71103
}

src/binders/paymentLinks/parameters.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ export type PageParameters = PaginationParameters & {
1616
testmode?: boolean;
1717
};
1818

19+
export type UpdateParameters = Pick<PaymentLinkData, 'description' | 'minimumAmount' | 'archived' | 'allowedMethods' | 'applicationFee'> &
20+
PickOptional<PaymentLinkData, 'profileId'> & {
21+
testmode?: boolean;
22+
};
23+
1924
export type IterateParameters = Omit<PageParameters, 'limit'> & ThrottlingParameter;

0 commit comments

Comments
 (0)