Skip to content

Commit 3fb01a4

Browse files
committed
Add update and delete methods to PaymentLinksBinder
Introduces `update` and `delete` methods for managing payment links, aligning with Mollie's API capabilities. Additionally, extends `CreateParameters` and introduces `UpdateParameters` to support new fields like `minimumAmount`, `archived`, and `allowedMethods`. Updates `PaymentLinkData` to include reusable and archived properties.
1 parent 0fce467 commit 3fb01a4

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type PaymentLinkData } from '../../data/paymentLinks/data';
22
import { type IdempotencyParameter, type PaginationParameters, type ThrottlingParameter } from '../../types/parameters';
33

4-
export type CreateParameters = Pick<PaymentLinkData, 'description' | 'amount' | 'redirectUrl' | 'webhookUrl' | 'expiresAt'> & {
4+
export type CreateParameters = Pick<PaymentLinkData, 'description' | 'amount' | 'minimumAmount' | 'redirectUrl' | 'webhookUrl' | 'reusable' | 'expiresAt' | 'allowedMethods'> & {
55
profileId?: string;
66
testmode?: boolean;
77
} & IdempotencyParameter;
@@ -15,4 +15,9 @@ export type PageParameters = PaginationParameters & {
1515
testmode?: boolean;
1616
};
1717

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

src/data/paymentLinks/data.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Amount, type ApiMode, type Links, type Url } from '../global';
1+
import { type Amount, type ApiMode, type Links, PaymentMethod, type Url } from '../global';
22
import type Model from '../Model';
33

44
export interface PaymentLinkData extends Model<'payment-link'> {
@@ -28,7 +28,19 @@ export interface PaymentLinkData extends Model<'payment-link'> {
2828
*
2929
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=amount#response
3030
*/
31-
amount: Amount;
31+
amount?: Amount;
32+
/**
33+
* The minimum amount of the payment link. This property is only allowed when there is no amount provided.
34+
*
35+
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=minimumAmount#response
36+
*/
37+
minimumAmount?: Amount;
38+
/**
39+
* Whether the payment link is archived
40+
*
41+
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=archived#response
42+
*/
43+
archived: boolean;
3244
/**
3345
* The URL your customer will be redirected to after completing the payment process.
3446
*
@@ -41,6 +53,13 @@ export interface PaymentLinkData extends Model<'payment-link'> {
4153
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=redirectUrl#response
4254
*/
4355
webhookUrl?: string;
56+
/**
57+
* Indicates whether the payment link is reusable. If this field is set to true, customers can make multiple payments using the same link.
58+
*
59+
* @default false
60+
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=reusable#response
61+
*/
62+
reusable?: boolean;
4463
/**
4564
* The payment link's date and time of creation, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
4665
*
@@ -65,5 +84,11 @@ export interface PaymentLinkData extends Model<'payment-link'> {
6584
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=expiresAt#response
6685
*/
6786
expiresAt?: string;
87+
/**
88+
* The expiry date and time of the payment link, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.
89+
*
90+
* @see https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link?path=allowedMethods#response
91+
*/
92+
allowedMethods?: PaymentMethod[];
6893
_links: Links & { paymentLink: Url };
6994
}

0 commit comments

Comments
 (0)