diff --git a/ts/bunq.classes.account.ts b/ts/bunq.classes.account.ts index a52bb74..38889aa 100644 --- a/ts/bunq.classes.account.ts +++ b/ts/bunq.classes.account.ts @@ -11,6 +11,7 @@ export interface IBunqConstructorOptions { environment: 'SANDBOX' | 'PRODUCTION'; permittedIps?: string[]; isOAuthToken?: boolean; // Set to true when using OAuth access token instead of API key + dangerousOperations?: boolean; // Set to true to enable dangerous operations like closing accounts } /** diff --git a/ts/bunq.classes.card.ts b/ts/bunq.classes.card.ts index 3d57fe5..85774e7 100644 --- a/ts/bunq.classes.card.ts +++ b/ts/bunq.classes.card.ts @@ -97,6 +97,12 @@ export class BunqCard { * Update card settings */ public async update(updates: any): Promise { + // Check if this is a dangerous operation + if ((updates.status === 'CANCELLED' || updates.status === 'BLOCKED') && + !this.bunqAccount.options.dangerousOperations) { + throw new Error('Dangerous operations are not enabled. Initialize the BunqAccount with dangerousOperations: true to allow cancelling or blocking cards.'); + } + await this.bunqAccount.apiContext.ensureValidSession(); const cardType = this.type === 'MASTERCARD' ? 'CardCredit' : 'CardDebit'; diff --git a/ts/bunq.classes.monetaryaccount.ts b/ts/bunq.classes.monetaryaccount.ts index c72b585..952818b 100644 --- a/ts/bunq.classes.monetaryaccount.ts +++ b/ts/bunq.classes.monetaryaccount.ts @@ -170,6 +170,11 @@ export class BunqMonetaryAccount { * Update account settings */ public async update(updates: any): Promise { + // Check if this is a dangerous operation + if (updates.status === 'CANCELLED' && !this.bunqAccountRef.options.dangerousOperations) { + throw new Error('Dangerous operations are not enabled. Initialize the BunqAccount with dangerousOperations: true to allow cancelling accounts.'); + } + await this.bunqAccountRef.apiContext.ensureValidSession(); const endpoint = `/v1/user/${this.bunqAccountRef.userId}/monetary-account/${this.id}`; @@ -235,6 +240,10 @@ export class BunqMonetaryAccount { * Close this monetary account */ public async close(reason: string): Promise { + if (!this.bunqAccountRef.options.dangerousOperations) { + throw new Error('Dangerous operations are not enabled. Initialize the BunqAccount with dangerousOperations: true to allow closing accounts.'); + } + await this.update({ status: 'CANCELLED', sub_status: 'REDEMPTION_VOLUNTARY',