update statement download
This commit is contained in:
@@ -111,18 +111,27 @@ export class BunqExport {
|
||||
throw new Error('Export ID not set');
|
||||
}
|
||||
|
||||
// Ensure the export is complete before downloading
|
||||
const status = await this.get();
|
||||
if (status.status !== 'COMPLETED') {
|
||||
throw new Error(`Export is not ready for download. Status: ${status.status}`);
|
||||
}
|
||||
|
||||
// For PDF statements, use the /content endpoint directly
|
||||
const downloadUrl = `${this.bunqAccount.apiContext.getBaseUrl()}/v1/user/${this.bunqAccount.userId}/monetary-account/${this.monetaryAccount.id}/customer-statement/${this.id}/content`;
|
||||
|
||||
const response = await fetch(downloadUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken
|
||||
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken,
|
||||
'User-Agent': 'bunq-api-client/1.0.0',
|
||||
'Cache-Control': 'no-cache'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to download export: HTTP ${response.status}`);
|
||||
const responseText = await response.text();
|
||||
throw new Error(`Failed to download export: HTTP ${response.status} - ${responseText}`);
|
||||
}
|
||||
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
@@ -146,7 +155,7 @@ export class BunqExport {
|
||||
while (true) {
|
||||
const details = await this.get();
|
||||
|
||||
if (details.status === 'COMPLETE') {
|
||||
if (details.status === 'COMPLETED') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user