BREAKING CHANGE(core): Major restructuring and feature enhancements: added batch payments and scheduled payments with builder patterns, improved webhook management, migrated package naming to @apiclient.xyz/bunq, and updated documentation and tests.
This commit is contained in:
@@ -52,41 +52,43 @@ tap.test('should create test setup with multiple accounts', async () => {
|
||||
});
|
||||
|
||||
tap.test('should create and execute a payment draft', async () => {
|
||||
const draft = new bunq.BunqDraftPayment(testBunqAccount);
|
||||
const draft = new bunq.BunqDraftPayment(testBunqAccount, primaryAccount);
|
||||
|
||||
// Create a draft payment
|
||||
const draftId = await draft.create(primaryAccount, {
|
||||
amount: {
|
||||
currency: 'EUR',
|
||||
value: '5.00'
|
||||
},
|
||||
counterparty_alias: {
|
||||
type: 'IBAN',
|
||||
value: 'NL91ABNA0417164300',
|
||||
name: 'Draft Test Recipient'
|
||||
},
|
||||
description: 'Test draft payment'
|
||||
const draftId = await draft.create({
|
||||
numberOfRequiredAccepts: 1,
|
||||
entries: [{
|
||||
amount: {
|
||||
currency: 'EUR',
|
||||
value: '5.00'
|
||||
},
|
||||
counterparty_alias: {
|
||||
type: 'IBAN',
|
||||
value: 'NL91ABNA0417164300',
|
||||
name: 'Draft Test Recipient'
|
||||
},
|
||||
description: 'Test draft payment entry'
|
||||
}]
|
||||
});
|
||||
|
||||
expect(draftId).toBeTypeofNumber();
|
||||
console.log(`Created draft payment with ID: ${draftId}`);
|
||||
|
||||
// List drafts
|
||||
const drafts = await draft.list(primaryAccount);
|
||||
const drafts = await bunq.BunqDraftPayment.list(testBunqAccount, primaryAccount.id);
|
||||
expect(drafts).toBeArray();
|
||||
expect(drafts.length).toBeGreaterThan(0);
|
||||
|
||||
const createdDraft = drafts.find(d => d.id === draftId);
|
||||
const createdDraft = drafts.find((d: any) => d.DraftPayment?.id === draftId);
|
||||
expect(createdDraft).toBeDefined();
|
||||
expect(createdDraft?.amount.value).toBe('5.00');
|
||||
|
||||
// Update the draft
|
||||
await draft.update(primaryAccount, draftId, {
|
||||
await draft.update(draftId, {
|
||||
description: 'Updated draft payment description'
|
||||
});
|
||||
|
||||
// Get updated draft
|
||||
const updatedDraft = await draft.get(primaryAccount, draftId);
|
||||
const updatedDraft = await draft.get(draftId);
|
||||
expect(updatedDraft.description).toBe('Updated draft payment description');
|
||||
|
||||
console.log('Draft payment updated successfully');
|
||||
@@ -224,33 +226,33 @@ tap.test('should test scheduled payments', async () => {
|
||||
});
|
||||
|
||||
tap.test('should test payment requests', async () => {
|
||||
const paymentRequest = new bunq.BunqRequestInquiry(testBunqAccount);
|
||||
const paymentRequest = new bunq.BunqRequestInquiry(testBunqAccount, primaryAccount);
|
||||
|
||||
// Create a payment request
|
||||
try {
|
||||
const requestId = await paymentRequest.create(primaryAccount, {
|
||||
amount: {
|
||||
const requestId = await paymentRequest.create({
|
||||
amountInquired: {
|
||||
currency: 'EUR',
|
||||
value: '15.00'
|
||||
},
|
||||
counterparty_alias: {
|
||||
counterpartyAlias: {
|
||||
type: 'EMAIL',
|
||||
value: 'requester@example.com',
|
||||
name: 'Request Sender'
|
||||
},
|
||||
description: 'Payment request test',
|
||||
allow_bunqme: true
|
||||
allowBunqme: true
|
||||
});
|
||||
|
||||
expect(requestId).toBeTypeofNumber();
|
||||
console.log(`Created payment request with ID: ${requestId}`);
|
||||
|
||||
// List requests
|
||||
const requests = await paymentRequest.list(primaryAccount);
|
||||
const requests = await bunq.BunqRequestInquiry.list(testBunqAccount, primaryAccount.id);
|
||||
expect(requests).toBeArray();
|
||||
|
||||
// Cancel the request
|
||||
await paymentRequest.update(primaryAccount, requestId, {
|
||||
await paymentRequest.update(requestId, {
|
||||
status: 'CANCELLED'
|
||||
});
|
||||
console.log('Payment request cancelled successfully');
|
||||
@@ -260,19 +262,19 @@ tap.test('should test payment requests', async () => {
|
||||
});
|
||||
|
||||
tap.test('should test payment response (accepting a request)', async () => {
|
||||
const paymentResponse = new bunq.BunqRequestResponse(testBunqAccount);
|
||||
const paymentResponse = new bunq.BunqRequestResponse(testBunqAccount, primaryAccount);
|
||||
|
||||
// First create a request to respond to
|
||||
const paymentRequest = new bunq.BunqRequestInquiry(testBunqAccount);
|
||||
const paymentRequest = new bunq.BunqRequestInquiry(testBunqAccount, primaryAccount);
|
||||
|
||||
try {
|
||||
// Create a self-request (from same account) for testing
|
||||
const requestId = await paymentRequest.create(primaryAccount, {
|
||||
amount: {
|
||||
const requestId = await paymentRequest.create({
|
||||
amountInquired: {
|
||||
currency: 'EUR',
|
||||
value: '5.00'
|
||||
},
|
||||
counterparty_alias: {
|
||||
counterpartyAlias: {
|
||||
type: 'IBAN',
|
||||
value: primaryAccount.iban,
|
||||
name: primaryAccount.displayName
|
||||
@@ -283,7 +285,7 @@ tap.test('should test payment response (accepting a request)', async () => {
|
||||
console.log(`Created self-request with ID: ${requestId}`);
|
||||
|
||||
// Accept the request
|
||||
const responseId = await paymentResponse.accept(primaryAccount, requestId);
|
||||
const responseId = await paymentResponse.accept(requestId);
|
||||
expect(responseId).toBeTypeofNumber();
|
||||
console.log(`Accepted request with response ID: ${responseId}`);
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user