From 7b7ac3ff3059ccf4057df615e051be24e12ae988 Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Thu, 26 Jun 2025 10:12:12 +0200 Subject: [PATCH 1/6] BA-766 Update & Refactor tests --- src/PaymentMethods/BuckarooWallet/index.ts | 2 +- src/PaymentMethods/GiftCard/index.ts | 7 + tests/Models/index.ts | 63 ++-- tests/Payloads/index.ts | 162 ++++++++++ tests/PaymentMethods/AfterPay.test.ts | 88 ++--- .../PaymentMethods/AfterPayDigiAccept.test.ts | 136 ++++---- tests/PaymentMethods/Alipay.test.ts | 23 +- tests/PaymentMethods/Bancontact.test.ts | 129 ++++---- tests/PaymentMethods/BankTransfer.test.ts | 28 +- tests/PaymentMethods/Belfius.test.ts | 36 ++- tests/PaymentMethods/Billink.test.ts | 185 ++++------- tests/PaymentMethods/Blik.test.ts | 45 +-- tests/PaymentMethods/BuckarooVoucher.test.ts | 96 +++--- tests/PaymentMethods/BuckarooWallet.test.ts | 221 +++++++------ tests/PaymentMethods/CreditCard.test.ts | 145 ++++----- tests/PaymentMethods/CreditManagment.test.ts | 305 ++++++++---------- tests/PaymentMethods/EPS.test.ts | 29 +- tests/PaymentMethods/Emandate.test.ts | 70 ++-- tests/PaymentMethods/ExternalPayment.test.ts | 40 +-- tests/PaymentMethods/Giftcard.test.ts | 53 +-- tests/PaymentMethods/Ideal.test.ts | 102 +++--- tests/PaymentMethods/IdealProcessing.test.ts | 21 +- tests/PaymentMethods/IdealQR.test.ts | 20 +- tests/PaymentMethods/Idin.test.ts | 31 +- tests/PaymentMethods/In3.test.ts | 127 ++------ tests/PaymentMethods/In3Old.test.ts | 121 +++---- tests/PaymentMethods/KBC.test.ts | 34 +- tests/PaymentMethods/Klarna.test.ts | 134 ++++---- tests/PaymentMethods/Mbway.test.ts | 29 +- tests/PaymentMethods/Multibanco.test.ts | 29 +- tests/PaymentMethods/NoService.test.ts | 11 +- tests/PaymentMethods/PayPerEmail.test.ts | 12 +- tests/PaymentMethods/Payconiq.test.ts | 56 ++-- .../PaymentMethods/PaymentInitiation.test.ts | 39 +-- tests/PaymentMethods/Paypal.test.ts | 47 ++- tests/PaymentMethods/PiM.test.ts | 8 +- tests/PaymentMethods/Pos.test.ts | 8 +- tests/PaymentMethods/Przelewy24.test.ts | 37 +-- tests/PaymentMethods/Subscriptions.test.ts | 195 +++++------ tests/PaymentMethods/SurePay.test.ts | 11 +- tests/PaymentMethods/Trustly.test.ts | 28 +- 41 files changed, 1540 insertions(+), 1423 deletions(-) create mode 100644 tests/Payloads/index.ts diff --git a/src/PaymentMethods/BuckarooWallet/index.ts b/src/PaymentMethods/BuckarooWallet/index.ts index b35f39b..952c103 100644 --- a/src/PaymentMethods/BuckarooWallet/index.ts +++ b/src/PaymentMethods/BuckarooWallet/index.ts @@ -43,7 +43,7 @@ export default class BuckarooWallet extends PayablePaymentMethod { cancel(payload: IPaymentRequest & { walletMutationGuid: string }) { this.setPayPayload(payload); - this.setServiceList('Cancel', new Wallet(payload)); + this.setServiceList('CancelReservation', new Wallet(payload)); return super.transactionRequest(); } diff --git a/src/PaymentMethods/GiftCard/index.ts b/src/PaymentMethods/GiftCard/index.ts index 5082c57..196a563 100644 --- a/src/PaymentMethods/GiftCard/index.ts +++ b/src/PaymentMethods/GiftCard/index.ts @@ -15,6 +15,13 @@ export default class GiftCard extends PayablePaymentMethod { return super.pay(payload, new Pay(payload)); } + payRemainder(payload: IPay) { + if (payload.name) { + this.setServiceCode(payload.name); + } + return super.payRemainder(payload, new Pay(payload)); + } + refund(payload: IRefund) { if (payload.name) { this.setServiceCode(payload.name); diff --git a/tests/Models/index.ts b/tests/Models/index.ts index d0cc9cb..f3ba7c3 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -12,56 +12,57 @@ import { } from '../../src'; export const TestPerson: IPerson = { - birthDate: '1990-01-01', + birthDate: '01-01-1990', category: RecipientCategory.PERSON, - culture: '321', + culture: 'nl-NL', firstName: 'John', gender: 'male', initials: 'R.T', - lastName: 'Do', - lastNamePrefix: 'testlastprefix', - placeOfBirth: 't', - title: 'title', + lastName: 'Doe', + // lastNamePrefix: 'van', + placeOfBirth: 'Amsterdam', + title: 'Mr.', + customerNumber: uniqid(), }; export const TestCompany: ICompany = { category: RecipientCategory.COMPANY, - careOf: 'test', - chamberOfCommerce: 'test', - companyName: 'testCompany', - culture: 'culture', + careOf: 'Test', + chamberOfCommerce: '12345678', + companyName: 'Test Company BV', + culture: 'nl-NL', vatApplicable: false, - vatNumber: '321', + vatNumber: 'NL123456789B01', }; export const TestAddress: IAddress = { - city: 'city', + city: 'Amsterdam', country: 'NL', - houseNumber: '2313432', - houseNumberAdditional: '324', - state: 'state', - street: 'street', - zipcode: '32323', + houseNumber: '123', + houseNumberAdditional: 'A', + // state: 'Netherland', + street: 'Hoftstraat', + zipcode: '1015CJ', }; export const TestArticle: IArticle = { - description: 'test', - identifier: 'identifier', - price: 10, + description: 'Test Product', + identifier: 'ABC123', + price: 40.10, quantity: 2, type: 'PhysicalArticle', - unitCode: '23', - vatCategory: '323', - vatPercentage: 1, + unitCode: '123', + vatCategory: '1', + vatPercentage: 21, }; export const TestPhone: IPhone = { - fax: '23232', - landline: '323123', - mobile: '21312332', + // fax: '0207654321', + landline: '0201234567', + mobile: '0612345678', }; -export const TestEmail = 'test@hotmail.com'; +export const TestEmail = 'test@buckaroo.nl'; export const TestBankAccount: IBankAccount = { - accountName: 'accountName', - bic: 'bic', - iban: 'iban', + accountName: 'John Doe', + bic: 'ABNANL2A', + iban: 'NL91ABNA0417164300', }; export const TestBilling = { recipient: TestPerson, @@ -77,7 +78,7 @@ export const TestCustomer = { initials: TestPerson.initials, lastName: TestPerson.lastName, firstName: TestPerson.firstName, - birthDate: '1990-01-01', + birthDate: TestPerson.birthDate, }; export const TestIp = getIPAddress(); diff --git a/tests/Payloads/index.ts b/tests/Payloads/index.ts new file mode 100644 index 0000000..f699cd7 --- /dev/null +++ b/tests/Payloads/index.ts @@ -0,0 +1,162 @@ +import { merge } from 'lodash'; +import { + uniqid, + getIPAddress, + RecipientCategory, + IPerson, + ICompany, + IAddress, + IArticle, + IPhone, + Gender, + IRequest, +} from '../../src'; + +import { + TestPerson, + TestCompany, + TestAddress, + TestArticle, + TestPhone, + TestEmail, + TestBankAccount, + TestCustomer, + TestIp, +} from '../Models/index'; + +function removeNestedKeys(obj: T, keysToRemove: string[]): T { + const copy = JSON.parse(JSON.stringify(obj)); // deep copy + + for (const key of keysToRemove) { + delete copy[key]; + for (const k in copy) { + if (typeof copy[k] === 'object' && copy[k] !== null) { + copy[k] = removeNestedKeys(copy[k], [key]); + } + } + } + + return copy; +} + +// ------------------------ +// Component Payloads +// ------------------------ + +export function createBillingPayload(overrides: any = {}, exclude: string[] = []) { + const payload = { + recipient: TestPerson, + address: TestAddress, + phone: TestPhone, + email: TestEmail, + }; + + const clean = removeNestedKeys(payload, exclude); + return merge({}, clean, overrides); +} + +export function createShippingPayload(overrides: any = {}, exclude: string[] = []) { + const payload = { + recipient: TestPerson, + address: TestAddress, + email: 'shipping@buckaroo.nl', + }; + + const clean = removeNestedKeys(payload, exclude); + return merge({}, clean, overrides); +} + +export function createAddressPayload(overrides: any = {}, exclude: string[] = []) { + const payload = { + address: TestAddress, + }; + + const clean = removeNestedKeys(payload, exclude); + return merge({}, clean, overrides); +} + +export function createCustomerPayload(overrides: any = {}, exclude: string[] = []) { + const payload = { + customer: TestCustomer, + }; + + const clean = removeNestedKeys(payload, exclude); + return merge({}, clean, overrides); +} + +export function createArticlesPayload(overrides: Partial[] = [], exclude: string[] = []): IArticle[] { + const articles: IArticle[] = [ + TestArticle, + { + ...TestArticle, + identifier: 'DEF456', + description: 'Second Product', + price: 20.1, + quantity: 1, + }, + ]; + + const cleaned = articles.map((article) => removeNestedKeys(article, exclude)); + return merge([], cleaned, overrides); +} + +// ------------------------ +// Base Payload Generator +// ------------------------ + +export function createBasePayload( + overrides: Partial = {}, + include: { + billing?: boolean | { overrides?: any; exclude?: string[] }; + shipping?: boolean | { overrides?: any; exclude?: string[] }; + articles?: boolean | { overrides?: Partial[]; exclude?: string[] }; + } = {}, + exclude: string[] = [] +): T { + const basePayload: Partial = { + clientIP: TestIp, + invoice: uniqid(), + order: uniqid(), + currency: 'EUR', + amountDebit: 100.3, + description: 'Buckaroo Node SDK Test Transaction', + }; + + if (include.billing) { + const billingConfig = typeof include.billing === 'object' ? include.billing : {}; + basePayload.billing = createBillingPayload(billingConfig.overrides, billingConfig.exclude); + } + + if (include.shipping) { + const shippingConfig = typeof include.shipping === 'object' ? include.shipping : {}; + basePayload.shipping = createShippingPayload(shippingConfig.overrides, shippingConfig.exclude); + } + + if (include.articles) { + const articlesConfig = typeof include.articles === 'object' ? include.articles : {}; + basePayload.articles = createArticlesPayload(articlesConfig.overrides, articlesConfig.exclude); + } + + const payload = removeNestedKeys(basePayload, exclude); + return merge({}, payload, overrides) as T; +} + +export function createRefundPayload(overrides: Partial = {}, exclude: string[] = []): T { + const refundPayload: Partial = { + invoice: uniqid(), + amountCredit: 0.01, + description: 'Buckaroo Node SDK Refund Transaction Test', + }; + + const rpayload = removeNestedKeys(refundPayload, exclude); + return merge({}, rpayload, overrides) as T; +} + +export const getServiceParameter = (response: any, name: string): string => { + const param = (response.getServices()?.[0]?.parameters as { name: string; value: any }[] | undefined)?.find( + (p) => p.name === name + ); + return String(param?.value ?? ''); +}; + +export const formatDate = (date: Date) => date.toISOString().split('T')[0]; diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index ecf0ffc..cc0687e 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -1,47 +1,27 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; -import { getIPAddress, RecipientCategory, uniqid } from '../../src'; +import { createBasePayload, createRefundPayload } from '../Payloads'; +import { IRefund } from '../../src/PaymentMethods/Afterpay/Model/Refund'; -const paymentPayload: IPay = { - invoice: uniqid(), - clientIP: getIPAddress(), - amountDebit: 100, - billing: { - recipient: { - category: RecipientCategory.PERSON, - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '01-01-1990', +const payload = createBasePayload( + {}, + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], }, - email: 'test@buckaroo.nl', - phone: { - mobile: '0612345678', - landline: '0201234567', + articles: { + exclude: ['type', 'unitCode', 'vatCategory'], }, - }, - articles: [ - { - vatPercentage: 21, - price: 10, - description: 'Test', - quantity: 4, - identifier: 'test', - }, - ], -}; - + } +); const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { test('Pay', async () => { return method - .pay(paymentPayload) + .pay(payload) .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); @@ -50,7 +30,7 @@ describe('AfterPay methods', () => { test('Pay with Different Version', async () => { return method .setServiceVersion(2) - .pay(paymentPayload) + .pay(payload) .request() .then((data) => { expect(data.isSuccess()).toBeTruthy(); @@ -58,45 +38,47 @@ describe('AfterPay methods', () => { }); test('Refund', async () => { return method - .refund({ - invoice: paymentPayload.invoice, //Set invoice number of the transaction to refund - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', //Set transaction key of the transaction to refund - amountCredit: paymentPayload.amountDebit, - }) + .refund( + createRefundPayload({ + originalTransactionKey: '4D2D8ABD5EA14E908F855BC7A8B10735', + amountCredit: payload.amountDebit, + }) + ) .request() .then((data) => { - expect(data.isFailed()).toBeDefined(); + expect(data.isSuccess()).toBeTruthy(); }); }); test('Authorize', async () => { return method - .authorize(paymentPayload) + .authorize(payload) .request() .then((data) => { - expect(data.httpResponse.status).toEqual(200); + expect(data.isSuccess()).toBeTruthy(); }); - }); + }); //Add 10s timeout as third param test('CancelAuthorize', async () => { return method - .cancelAuthorize({ - invoice: paymentPayload.invoice, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - amountCredit: 100, - }) + .cancelAuthorize( + createRefundPayload({ + originalTransactionKey: '9CFEFC57074247DE92F7804246D1DD5D', + amountCredit: payload.amountDebit, + }) + ) .request() .then((data) => { - expect(data.httpResponse.status).toEqual(200); + expect(data.isSuccess()).toBeTruthy(); }); }); test('Capture', async () => { return method .capture({ - ...paymentPayload, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + ...payload, + originalTransactionKey: 'CD1493C19B69488CB88EC6576DD1E928', }) .request() .then((data) => { - expect(data.httpResponse.status).toEqual(200); + expect(data.isSuccess()).toBeTruthy(); }); }); }); diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 758196e..3fda0b5 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,97 +1,84 @@ -import { Gender, getIPAddress, RequestTypes, uniqid } from '../../src'; +import { Gender, getIPAddress, IRefundRequest, RequestTypes, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay'; +import { createBasePayload, createRefundPayload } from '../Payloads'; const method = buckarooClientTest.method('afterpaydigiaccept'); -const paymentPayload: IPay = { - amountDebit: 100, - order: uniqid(), - invoice: uniqid(), - b2b: true, - addressesDiffer: true, - customerIPAddress: getIPAddress(), - shippingCosts: 0.5, - costCentre: 'Test', - department: 'Test', - establishmentNumber: 123456, - billing: { - recipient: { - gender: Gender.FEMALE, - initials: 'AB', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - culture: 'NL', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - }, - email: 'test@buckaroo.nl', +const payload = createBasePayload( + { + addressesDiffer: true, + customerIPAddress: getIPAddress(), + shippingCosts: 0.5, + costCentre: 'Test', + department: 'Test', + establishmentNumber: 123456, }, - shipping: { - recipient: { - culture: 'NL', - gender: Gender.MALE, - initials: 'TA', - lastName: 'Acceptatie', - companyName: 'Buckaroo B.V.', - chamberOfCommerce: 'XXXXXX41', - birthDate: '1990-01-01', - vatNumber: 'NLXXXXXXXXXXB01', + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - }, - email: 'test@buckaroo.nl', - }, - articles: [ - { - identifier: uniqid(), - description: 'Blue Toy Car', - price: 10.0, - quantity: 2, - vatCategory: '1', + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], }, - { - identifier: uniqid(), - description: 'Red Toy Car', - price: 10.0, - quantity: 2, - vatCategory: '1', + articles: { + exclude: ['type', 'unitCode', 'vatCategory', 'vatPercentage'], }, - ], -}; + } +); + describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { return method - .authorize(paymentPayload) + .authorize(payload) .request() .then((data) => { - expect(data.httpResponse.status).toEqual(200); + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('CancelAuthorize', async () => { + return method + .cancelAuthorize( + createRefundPayload({ + originalTransactionKey: 'F1924C34B80D4CA6838F44D6A8A6516A', + amountCredit: payload.amountDebit, + }) + ) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Capture', async () => { + return method + .capture({ + ...payload, + originalTransactionKey: '4FFF55350BAF47F086F75CC693407823', + }) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); }); }); test('Pay', async () => { return method - .pay(paymentPayload) + .pay(payload) .request() .then((data) => { - expect(data.httpResponse.status).toEqual(200); + expect(data.isSuccess()).toBeTruthy(); + }); + }); + test('Refund', async () => { + return method + .refund( + createRefundPayload({ + originalTransactionKey: '5DA00BD4ED4B4AE8B6C0092E138D959B', + amountCredit: payload.amountDebit, + }) + ) + .request() + .then((data) => { + expect(data.isSuccess()).toBeTruthy(); }); }); test('Specification', async () => { @@ -99,6 +86,7 @@ describe('AfterPayDigiAccept methods', () => { .specification(RequestTypes.Transaction) .request() .then((data) => { + console.log(data); expect(data.httpResponse.status).toEqual(200); }); }); diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index 341306d..f233f6e 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,11 +1,11 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; - -const alipay = buckarooClientTest.method('alipay'); +import { IRefundRequest } from '../../src'; +import { createRefundPayload } from '../Payloads'; describe('Alipay methods', () => { test('Pay Simple Payload', async () => { - return alipay + return buckarooClientTest + .method('alipay') .pay({ amountDebit: 100, useMobileView: false, @@ -16,15 +16,16 @@ describe('Alipay methods', () => { }); }); test('Refund', async () => { - return alipay - .refund({ - amountCredit: 0.01, - invoice: uniqid(), - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) + return buckarooClientTest + .method('alipay') + .refund( + createRefundPayload({ + originalTransactionKey: '6CE35062C16C4F47A49314D533E9F7A3', + }) + ) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy(); + expect(data.isSuccess()).toBeTruthy(); }); }); }); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 08079ee..3c9aea7 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,85 +1,96 @@ +import { IRefundRequest, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('bancontactmrcash'); +let method = buckarooClientTest.method('bancontactmrcash'); +let transactionKey: string; -describe('BanContact methods', () => { +beforeEach(() => { + method = buckarooClientTest.method('bancontactmrcash'); +}); + +describe('Bancontact methods', () => { test('Pay Simple Payload', async () => { - return method + const response = await method .pay({ amountDebit: 100, saveToken: true, }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy(); - }); - }); - test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); - }); - test('Authenticate', async () => { - return method - .authenticate({ invoice: uniqid(), amountDebit: 100 }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeDefined(); - }); + .request(); + + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); + test('PayOneClick', async () => { - return method + const response = await method .payOneClick({ invoice: uniqid(), - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: 'FB45BE56A0584613A15DD5A453AC145F', amountDebit: 100, }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); - test('CompletePayment', async () => { - return method - .completePayment({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', + + test('Refund (uses PayOneClick transaction key)', async () => { + expect(transactionKey).toBeDefined(); + + const refundPayload = createRefundPayload({ + originalTransactionKey: transactionKey, + }); + + const response = await method.refund(refundPayload).request(); + expect(response.isSuccess()).toBeTruthy(); + }); + + test('Authenticate', async () => { + const response = await method + .authenticate({ + invoice: uniqid(), + amountDebit: 100, }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); + test('PayEncrypted', async () => { - return method + const response = await method .payEncrypted({ invoice: uniqid(), amountDebit: 100, - encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', + encryptedCardData: + '001SlXfd8MbiTd/JFwCiGVs3f6o4x6xt0aN29NzOSNZHPKlVsz/EWeQmyhb1gGZ86VY88DP7gfDV+UyjcPfpVfHZd7u+WkO71hnV2QfYILCBNqE1aiPv2GQVGdaGbuoQloKu1o3o3I1UDmVxivXTMQX76ovot89geA6hqbtakmpmvxeiwwea3l4htNoX1IlD1hfYkDDl9rzSu5ypcjvVs6aRGXK5iMHnyrmEsEnfdj/Q5XWbsD5xAm4u3y6J8d4UP7LB31VLECzZUTiJOtKKcCQlT01YThIkQlj8PWBBMtt4H52VN3IH2+wPYtR8HiOZzcA2HA7UxozogIpS53tIURj/g==', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isPendingProcessing()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); - test('PayRecurring', async () => { - return method - .payRecurring({ - invoice: uniqid(), - amountDebit: 100, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + + test('CompletePayment (uses PayEncrypted transaction key)', async () => { + expect(transactionKey).toBeDefined(); + + const response = await method + .completePayment({ + originalTransactionKey: transactionKey, + encryptedCardData: + '001SlXfd8MbiTd/JFwCiGVs3f6o4x6xt0aN29NzOSNZHPKlVsz/EWeQmyhb1gGZ86VY88DP7gfDV+UyjcPfpVfHZd7u+WkO71hnV2QfYILCBNqE1aiPv2GQVGdaGbuoQloKu1o3o3I1UDmVxivXTMQX76ovot89geA6hqbtakmpmvxeiwwea3l4htNoX1IlD1hfYkDDl9rzSu5ypcjvVs6aRGXK5iMHnyrmEsEnfdj/Q5XWbsD5xAm4u3y6J8d4UP7LB31VLECzZUTiJOtKKcCQlT01YThIkQlj8PWBBMtt4H52VN3IH2+wPYtR8HiOZzcA2HA7UxozogIpS53tIURj/g==', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isPendingProcessing()).toBeTruthy(); + }); + + test('PayRecurring', async () => { + const response = await method.payRecurring({ + invoice: uniqid(), + amountDebit: 100, + originalTransactionKey: transactionKey, + }).request(); + + expect(response.httpResponse.status).toEqual(200); }); }); diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index 5ac983e..dc58990 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,11 +1,16 @@ -import { Gender } from '../../src'; +import { Gender, IRefundRequest } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('transfer'); +let method = buckarooClientTest.method('transfer'); + +beforeEach(() => { + method = buckarooClientTest.method('transfer'); +}); describe('Transfer methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 100, customer: { @@ -17,9 +22,18 @@ describe('Transfer methods', () => { sendMail: true, dateDue: '2024-10-10', }) - .request() - .then((res) => { - expect(res.isAwaitingConsumer()).toBeDefined(); - }); + .request(); + expect(response.isAwaitingConsumer()).toBeTruthy(); + }); + + test('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '0D04AEAEE48E464597831E15BB92FBF1', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index f6c408d..21845bf 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,29 +1,31 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('belfius'); +let method = buckarooClientTest.method('belfius'); + +beforeEach(() => { + method = buckarooClientTest.method('belfius'); +}); describe('testing methods', () => { test('Pay Simple Payload', async () => { - return method + const response = await method .pay({ amountDebit: 100, }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); + test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '1B649F2796AA466F8D8AE695170CAC85', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index 2f2b600..24bedac 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,131 +1,86 @@ import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay'; import buckarooClientTest from '../BuckarooClient.test'; -import { RecipientCategory, uniqid } from '../../src'; +import { IRequest, RecipientCategory, uniqid } from '../../src'; +import { createBasePayload, createRefundPayload } from '../Payloads'; +import { IRefund } from '../../src/PaymentMethods/Billink/Models/Refund'; -const method = buckarooClientTest.method('billink'); +let payTransactionKey: string; +let authorizeTransactionKey: string; +let method = buckarooClientTest.method('billink'); +let payload: IPay; -describe('Billink methods', () => { - const invoiceId = uniqid(); +beforeEach(() => { + method = buckarooClientTest.method('billink'); + payload = createBasePayload( + { + trackandtrace: 'ABC123', + VATNumber: 'NLXXXXXXXXXXB01', + }, + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], + }, + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory'], + }, + } + ); +}); +describe('Billink methods', () => { test('Pay', async () => { - return method - .pay(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); - }); - test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method.pay(payload).request(); + + expect(response.isSuccess()).toBeTruthy(); + payTransactionKey = response.getTransactionKey(); }); test('Authorize', async () => { - return method - .authorize({ ...payload, invoice: invoiceId }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method.authorize(payload).request(); + + expect(response.isSuccess()).toBeTruthy(); + authorizeTransactionKey = response.getTransactionKey(); + }); + test('Refund', async () => { + expect(payTransactionKey).toBeDefined(); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: payTransactionKey, + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('CancelAuthorize', async () => { - return method - .cancelAuthorize({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - amountCredit: payload.amountDebit, - invoice: invoiceId, - }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + expect(authorizeTransactionKey).toBeDefined(); + + const response = await method + .cancelAuthorize( + createRefundPayload({ + originalTransactionKey: authorizeTransactionKey, + amountCredit: payload.amountDebit, + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Capture', async () => { - return method + // const authResponse = await method.authorize(payload).request(); + // expect(authResponse.isSuccess()).toBeTruthy(); + // let key = authResponse.getTransactionKey(); + // expect(key).toBeDefined(); + + // new Promise((resolve) => setTimeout(resolve, 6000)); + + const response = await method .capture({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - invoice: invoiceId, - amountDebit: payload.amountDebit, - articles: payload.articles, + ...payload, + originalTransactionKey: '1234', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); - -const payload: IPay = { - amountDebit: 100, - trackAndTrace: 'XXXXXXXXXXXXX', - vatNumber: 'NLXXXXXXXXXXB01', - billing: { - recipient: { - category: RecipientCategory.PERSON, - careOf: 'Test Acceptatie', - title: 'Female', - initials: 'TA', - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '01-01-1990', - chamberOfCommerce: 'XXXXXX41', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - landline: '0201234567', - }, - email: 'test@buckaroo.nl', - }, - shipping: { - recipient: { - category: RecipientCategory.PERSON, - careOf: 'Test Acceptatie', - title: 'Male', - initials: 'TA', - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - }, - articles: [ - { - identifier: 'Articlenumber1', - description: 'Blue Toy Car', - vatPercentage: 21, - quantity: 2, - price: 20.1, - priceExcl: 5, - }, - { - identifier: 'Articlenumber2', - description: 'Red Toy Car', - vatPercentage: 21, - quantity: 1, - price: 10.1, - priceExcl: 5, - }, - ], -}; diff --git a/tests/PaymentMethods/Blik.test.ts b/tests/PaymentMethods/Blik.test.ts index 6cbc32c..5643db3 100644 --- a/tests/PaymentMethods/Blik.test.ts +++ b/tests/PaymentMethods/Blik.test.ts @@ -1,34 +1,37 @@ +import { IRefundRequest } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; -const blik = buckarooClientTest.method('blik'); +let method = buckarooClientTest.method('blik'); + +beforeEach(() => { + method = buckarooClientTest.method('blik'); +}); describe('Testing Blik methods', () => { test('Pay', async () => { - return blik + const response = await method .pay({ currency: 'PLN', - amountDebit: 10.00, + amountDebit: 10.0, invoice: 'Blik Test Plugin Example', description: 'Blik Test Plugin Example', email: 'test@buckaroo.nl', }) - .request() - .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy(); - }); - }); - test('Refund', async () => { - return blik - .refund({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - currency: 'PLN', - amountCredit: 5.00, - invoice: 'Refund Blik Test Plugin Example', - description: 'Refund Blik Test Plugin Example', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200) - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); + //unexpected error in pay redirect link + // test('Refund', async () => { + // const response = await method + // .refund( + // createRefundPayload({ + // originalTransactionKey: 'DA18F7031E3547E898B68773E372ACB4', + // currency: 'PLN', + // }) + // ) + // .request(); + // expect(response.isSuccess()).toBeTruthy(); + // }); }); + diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 1eaa0bc..679abdf 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,63 +1,75 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('buckaroovoucher'); +let method = buckarooClientTest.method('buckaroovoucher'); +let voucherCode: string; +let transactionKey: string; +const today = new Date(); +const oneMonthFromNow = new Date(); +oneMonthFromNow.setMonth(today.getMonth() + 1); + +const formatDate = (date: Date) => date.toISOString().split('T')[0]; + +beforeEach(() => { + method = buckarooClientTest.method('buckaroovoucher'); +}); describe('testing methods', () => { - test('Pay', async () => { - return method - .pay({ - amountDebit: 100, - voucherCode: 'XXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); - }); - test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + test('CreateApplication', async () => { + const response = await method + .create({ + creationBalance: 12, + usageType: 1, + validFrom: formatDate(today), + validUntil: formatDate(oneMonthFromNow), }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); + + voucherCode = String(response.getServices()?.[0]?.parameters.find((p) => p.name === 'VoucherCode')?.value); }); test('GetBalance', async () => { return method .getBalance({ - voucherCode: 'XXXXXXX', + voucherCode: voucherCode, }) .request() .then((data) => { - expect(data.isFailed()).toBeTruthy(); + expect(data.isSuccess()).toBeTruthy(); }); }); - test('CreateApplication', async () => { - return method - .create({ - creationBalance: 12, - usageType: 1, - validFrom: '2021-01-01', - validUntil: '2024-01-01', + test('Pay', async () => { + expect(voucherCode).toBeDefined(); + + const response = await method + .pay({ + amountDebit: 1, + voucherCode: voucherCode, }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); + }); + test('Refund', async () => { + expect(transactionKey).toBeDefined(); + + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: transactionKey, + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('DeactivateVoucher', async () => { - return method + const response = await method .deactivate({ - voucherCode: 'XXXXXXX', + voucherCode: voucherCode, }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.httpResponse.status).toEqual(200); }); }); diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index cce2bf3..9bd21e8 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -1,117 +1,154 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { PaymentMethodInstance, uniqid } from '../../src'; -const method = buckarooClientTest.method('BuckarooWalletCollecting'); +let method: PaymentMethodInstance<'BuckarooWalletCollecting'>; + +let walletId: string; +let reservationId: string; +let transactionKey: string; +let walletMutationGuid: string; + +beforeEach(() => { + method = buckarooClientTest.method('BuckarooWalletCollecting'); +}); + +const getServiceParameter = (response: any, name: string): string => { + const param = (response.getServices()?.[0]?.parameters as { name: string; value: any }[] | undefined)?.find( + (p) => p.name === name + ); + return String(param?.value ?? ''); +}; + +const payload = { + walletId: uniqid(), + currency: 'EUR', + customer: { + firstName: 'Test', + lastName: 'Acceptatie', + email: 'test@buckaroo.nl', + }, + bankAccount: { + iban: 'NL13TEST0123456789', + }, +}; describe('BuckarooWallet methods', () => { - test('Pay', async () => { - return method - .pay({ - invoice: uniqid(), - amountDebit: 100, - walletId: 'XXXXXXXXXXXXXXXXXXXXX', + test('Create Wallet', async () => { + const response = await method.create(payload).request(); + + expect(response.isSuccess()).toBeTruthy(); + walletId = getServiceParameter(response, 'WalletId'); + }); + + test('Update', async () => { + const response = await method + .update({ + ...payload, + status: 'Active', }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); - test('Refund', async () => { - return method - .refund({ + + test('GetInfo', async () => { + const response = await method.getInfo({ walletId }).request(); + expect(response.isSuccess()).toBeTruthy(); + }); + + test('Deposit', async () => { + const response = await method + .deposit({ invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + walletId, + amountCredit: 50, + originalTransactionKey: '288EC0C84DF24C5C8B34723E50782BD4', }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); - test('CancelReservation', async () => { - return method - .cancel({ + + test('Reservation', async () => { + const response = await method + .reserve({ invoice: uniqid(), - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - amountDebit: 100, - walletMutationGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + walletId, + amountCredit: 40, + originalTransactionKey: '288EC0C84DF24C5C8B34723E50782BD4', }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); + walletId = getServiceParameter(response, 'WalletId'); + walletMutationGuid = getServiceParameter(response, 'WalletMutationGuid'); + reservationId = response.getTransactionKey(); }); - test('deposit', async () => { - return method - .deposit({ - invoice: uniqid(), - walletId: 'XXXXXXXXXXXXXXXXXXXXX', - amountCredit: 100, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + + test('Release', async () => { + const response = await method + .release({ + amountCredit: 40, + walletId, + originalTransactionKey: '', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); + walletId = getServiceParameter(response, 'WalletId'); }); - test('Update', async () => { - return method - .update({ - walletId: 'XXXXXXXXXXXXXXXXXXXXX', - status: 'Disabled', - email: 'test@buckaroo.nl', - customer: { - firstName: 'Test', - lastName: 'Acceptatie', - }, - bankAccount: { - iban: 'NLXXTESTXXXXXXXXXX', - }, + + test('CancelReservation', async () => { + const response = await method + .cancel({ + invoice: uniqid(), + amountDebit: 30, + walletMutationGuid: walletMutationGuid, + originalTransactionKey: '', + order: '', }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); + test('Withdrawal', async () => { - return method + const response = await method .withdrawal({ invoice: uniqid(), - walletId: 'XXXXXXXXXXXXXXXXXXXXX', - amountDebit: 100, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + walletId, + amountDebit: 10, + originalTransactionKey: reservationId, + order: '', }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); - test('Create Wallet', async () => { - return method - .create({ - walletId: 'XXXXXXXXXXXXXXXXXXXXX', - email: 'test@buckaroo.nl', - customer: { - firstName: 'Test', - lastName: 'Acceptatie', - }, - bankAccount: { - iban: 'NLXXTESTXXXXXXXXXX', - }, + + test('Pay', async () => { + const response = await method + .pay({ + invoice: uniqid(), + amountDebit: 10, + walletId, }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); - test('GetInfo', async () => { - return method - .getInfo({ - walletId: 'XXXXXXXXXXXXXXXXXXXXX', + + test('Refund', async () => { + const response = await method + .refund({ + invoice: uniqid(), + amountCredit: 0.01, + originalTransactionKey: transactionKey, }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); - }); + .request(); + + console.log(response.getStatusCode()); + expect(response.isSuccess()).toBeTruthy(); + }, 10000); }); diff --git a/tests/PaymentMethods/CreditCard.test.ts b/tests/PaymentMethods/CreditCard.test.ts index bd38a79..dec33aa 100644 --- a/tests/PaymentMethods/CreditCard.test.ts +++ b/tests/PaymentMethods/CreditCard.test.ts @@ -1,149 +1,144 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { PaymentMethodInstance, uniqid } from '../../src'; -const method = buckarooClientTest.method('visa'); +let visa: PaymentMethodInstance<'visa'>; +let mastercard: PaymentMethodInstance<'mastercard'>; +let transactionKey: string; +let authorizationKey: string; + +beforeEach(() => { + visa = buckarooClientTest.method('visa'); + mastercard = buckarooClientTest.method('mastercard'); +}); describe('testing methods', () => { test('Pay', async () => { - return method + const response = await visa .pay({ amountDebit: 100, + startRecurrent: true, }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); test('Refund', async () => { - return method + const response = await visa .refund({ invoice: uniqid(), amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: 'DFD5107223F742F5B9A0431E52C1ADA7', }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Authorize', async () => { - return method + const response = await visa .authorize({ amountDebit: 100, }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); + authorizationKey = response.getTransactionKey(); }); test('PayEncrypted', async () => { - return method + const response = await mastercard .payEncrypted({ amountDebit: 100, - name: 'Visa', - encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', + name: 'Mastercard', + encryptedCardData: + '001u8gJNwngKubFCO6FmJod6aESlIFATkKYaj47KlgBp7f3NeVxUzChg1Aug7WD2vc5wut2KU9NPLUaO0tFmzhVLZoDWn7dX4AzGxSjPrsPmDMWYcEkIwMZfcyJqoRfFkF3j15mil3muXxhR1a609NfkTo11J3ENVsvU3k60z+x0jCw6NjzbrweVQhBRkrbs7TBJkS4tR38JiDsXyH2E1JmRHE+o2P9qz4at6w3zggmwImvjt5IIjEr6g8KfsIDXfv7YjEzhJ3P+7uuGoyG2WYm/Pr0+iEmTj5Q/ijkxu1+cDqv5eiB+80KgffPItUZDrnv9sKlVBAr+f53nm1G+Sxp0Q==', }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('PayWithSecurityCode', async () => { - return method + const response = await mastercard .payWithSecurityCode({ amountDebit: 100, - encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - name: 'Visa', + originalTransactionKey: '24F4BD71AAF843089C914135101F061A', + encryptedSecurityCode: + '001F3AJT7wkJa04zE8c78P7spOAgHSKH1YKgPlOwXhW049VfIXMwZO32RYna9xZRyUCtfODIoCL8GRQoaZbStlBT4rbF5e4PPvWFSKdvua4rq+GQDNAghfa+ZQz0BzBPfjS0WBdFape9n3zH2vC/0m+wI3QZiDpYYgyWC1/Y3udJDU7JRTVMq/BDHGet+IZ2CDnkeGl813kkYymzYon/QeuQRQ0Wsec5bmVQNYGx62fz70/vLgs0ffff+6DtZtnZWfByRkTwMNebJotlOsSkbhVR5FrHpAbNPCJI+LvJcJL7Eoo+ZuX5/LWGmsT6qnR/uLiIw1DI7mTKGy6/P7IljAE+g==', + name: 'Mastercard', }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); + // "Technical failure" test('AuthorizeWithSecurityCode', async () => { - return method + const response = await mastercard .authorizeWithSecurityCode({ amountDebit: 100, - encryptedSecurityCode: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - name: 'Visa', + originalTransactionKey: '24F4BD71AAF843089C914135101F061A', + encryptedSecurityCode: + '001F3AJT7wkJa04zE8c78P7spOAgHSKH1YKgPlOwXhW049VfIXMwZO32RYna9xZRyUCtfODIoCL8GRQoaZbStlBT4rbF5e4PPvWFSKdvua4rq+GQDNAghfa+ZQz0BzBPfjS0WBdFape9n3zH2vC/0m+wI3QZiDpYYgyWC1/Y3udJDU7JRTVMq/BDHGet+IZ2CDnkeGl813kkYymzYon/QeuQRQ0Wsec5bmVQNYGx62fz70/vLgs0ffff+6DtZtnZWfByRkTwMNebJotlOsSkbhVR5FrHpAbNPCJI+LvJcJL7Eoo+ZuX5/LWGmsT6qnR/uLiIw1DI7mTKGy6/P7IljAE+g==', + name: 'Mastercard', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('AuthorizeEncrypted', async () => { - return method + const response = await mastercard .authorizeEncrypted({ amountDebit: 100, - encryptedCardData: 'XXXXXXXXXXXXXXXXXXXXXXXX', - name: 'Visa', + encryptedCardData: + '001u8gJNwngKubFCO6FmJod6aESlIFATkKYaj47KlgBp7f3NeVxUzChg1Aug7WD2vc5wut2KU9NPLUaO0tFmzhVLZoDWn7dX4AzGxSjPrsPmDMWYcEkIwMZfcyJqoRfFkF3j15mil3muXxhR1a609NfkTo11J3ENVsvU3k60z+x0jCw6NjzbrweVQhBRkrbs7TBJkS4tR38JiDsXyH2E1JmRHE+o2P9qz4at6w3zggmwImvjt5IIjEr6g8KfsIDXfv7YjEzhJ3P+7uuGoyG2WYm/Pr0+iEmTj5Q/ijkxu1+cDqv5eiB+80KgffPItUZDrnv9sKlVBAr+f53nm1G+Sxp0Q==', + name: 'Mastercard', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('CancelAuthorize', async () => { - return method + const response = await visa .cancelAuthorize({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: 'F5E4DEEF89594E85A7DC7244180FAF89', amountCredit: 100, name: 'Visa', + invoice: uniqid(), }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Capture', async () => { - return method + const response = await visa .capture({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: '5DD1E0DE29CB4E4F91B477983AB375CD', amountDebit: 100, name: 'Visa', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('PayRecurrent', async () => { - return method + const response = await visa .payRecurrent({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: 'B10DF7D5E6314A528BBA7BDF297EB21E', amountDebit: 100, name: 'Visa', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('AuthorizeWithToken', async () => { - return method + const response = await visa .authorizeWithToken({ invoice: uniqid(), amountDebit: 10, name: 'Visa', sessionId: 'hf_457vWCGGdZcWJzBY', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('PayWithToken', async () => { - return method + const response = await visa .payWithToken({ invoice: uniqid(), amountDebit: 10, name: 'Visa', sessionId: 'hf_457vWCGGdZcWJzBY', }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); -}); \ No newline at end of file +}); diff --git a/tests/PaymentMethods/CreditManagment.test.ts b/tests/PaymentMethods/CreditManagment.test.ts index 01e1a4c..dd747a4 100644 --- a/tests/PaymentMethods/CreditManagment.test.ts +++ b/tests/PaymentMethods/CreditManagment.test.ts @@ -1,118 +1,55 @@ import { IInvoice } from '../../src/PaymentMethods/CreditManagement/Models/Invoice'; -import { CreditManagementInstallmentInterval, Gender, uniqid } from '../../src'; +import { Gender, PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { getServiceParameter, formatDate } from '../Payloads'; -const creditManagement = buckarooClientTest.method('CreditManagement3'); +let method: PaymentMethodInstance<'CreditManagement3'>; +let invoiceKey: string; +let invoice: string; +beforeEach(() => { + method = buckarooClientTest.method('CreditManagement3'); +}); describe('Testing Credit Management', () => { test('CreateInvoice', async () => { - return creditManagement - .createInvoice(creditManagementTestInvoice()) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); - }); - test('CreateInvoice With Articles', async () => { - return creditManagement - .createInvoice( - creditManagementTestInvoice({ - invoice: uniqid(), - description: 'buckaroo_schema_test_PDF', - invoiceAmount: 217.8, - invoiceDate: '2022-01-01', - dueDate: '2024-01-01', - schemeKey: 'XXXXXXX', - poNumber: 'XX-XXXXX', - debtor: { - code: 'XXXXXXXX', - }, - articles: [ - { - productGroupName: 'Toys', - productGroupOrderIndex: 1, - productOrderIndex: 1, - type: 'Regular', - identifier: 'ART12', - description: 'Blue Toy Car', - quantity: 3, - unitOfMeasurement: 'piece(s)', - price: 10, - discountPercentage: 20, - totalDiscount: 6, - vatPercentage: 21, - totalVat: 0.6, - totalAmountExVat: 8.4, - totalAmount: 123, - }, - { - productGroupName: 'Toys', - productGroupOrderIndex: 1, - productOrderIndex: 2, - type: 'Regular', - identifier: 'ART12', - description: 'Blue Toy Car', - quantity: 3, - unitOfMeasurement: 'piece(s)', - price: 10, - discountPercentage: 20, - totalDiscount: 6, - vatPercentage: 21, - totalVat: 0.6, - totalAmountExVat: 8.4, - totalAmount: 123, - }, - ], - }) - ) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + const response = await method.createInvoice(creditManagementTestInvoice()).request(); + invoiceKey = getServiceParameter(response, 'InvoiceKey'); + + expect(response.isSuccess()).toBeTruthy(); }); test('Pause Invoice', async () => { - return creditManagement - .pauseInvoice({ invoice: uniqid() }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + const response = await method.pauseInvoice({ invoice: invoice }).request(); + + expect(response.isSuccess()).toBeTruthy(); }); test('UnPause Invoice', async () => { - return creditManagement - .unpauseInvoice({ invoice: uniqid() }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + const response = await method.unpauseInvoice({ invoice: invoice }).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Invoice Info', async () => { - return creditManagement + const response = await method .invoiceInfo({ - invoice: uniqid(), - invoices: [{ invoiceNumber: 'INV002' }, { invoiceNumber: 'INV003' }], + invoice: invoice, }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Debtor Info', async () => { - return creditManagement + const response = await method .debtorInfo({ debtor: { - code: 'XXXXXXXX', + code: 'johnsmith4', }, }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('AddOrUpdateProductLines', async () => { - return creditManagement + expect(invoiceKey).toBeDefined(); + + const response = await method .addOrUpdateProductLines({ - invoiceKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + invoiceKey: invoiceKey, articles: [ { type: 'Regular', @@ -136,112 +73,120 @@ describe('Testing Credit Management', () => { }, ], }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); - }); - test('resumeDebtorFile', async () => { - return creditManagement - .resumeDebtorFile({ debtorFileGuid: 'xxx' }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); - }); - test('pauseDebtorFile', async () => { - return creditManagement - .pauseDebtorFile({ debtorFileGuid: 'xxx' }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); + // No DebtorFile available for testing. + // test('resumeDebtorFile', async () => { + // return method + // .resumeDebtorFile({ debtorFileGuid: 'xxx' }) + // .request() + // .then((data) => { + // expect(data.isValidationFailure()).toBeTruthy(); + // }); + // }); + // test('pauseDebtorFile', async () => { + // return method + // .pauseDebtorFile({ debtorFileGuid: 'xxx' }) + // .request() + // .then((data) => { + // expect(data.isValidationFailure()).toBeTruthy(); + // }); + // }); test('addOrUpdateDebtor', async () => { - return creditManagement + const response = await method .addOrUpdateDebtor({ debtor: { - code: 'XXXXXXXX', + code: 'johnsmith4', }, person: { culture: 'nl-NL', lastName: 'Acceptatie', }, }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); test('CreateCombinedInvoice', async () => { - const combinedInvoice = creditManagement.createCombinedInvoice(creditManagementTestInvoice()); - return buckarooClientTest + const combinedInvoice = method.createCombinedInvoice(creditManagementTestInvoice()); + const response = await buckarooClientTest .method('sepadirectdebit') .combine(combinedInvoice.data) .pay({ - iban: 'NLXXTESTXXXXXXXXXX', - bic: 'XXXXXXXXX', - mandateReference: 'XXXXXXXXXXXXXXX', + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + mandateReference: '1DCtestreference', mandateDate: '2020-01-01', - collectDate: '2020-07-03', + collectDate: '2030-07-03', amountDebit: 100, customer: { name: 'Test Acceptatie', }, invoice: uniqid('TestInvoice'), }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); - }); - test('CreatePaymentPlan', async () => { - return creditManagement - .createPaymentPlan({ - description: 'Payment in two intstallments', - includedInvoiceKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - dossierNumber: 'XXXXXXXXXXXXXXXXXXXXXX', - installmentCount: 2, - initialAmount: 100, - startDate: '2030-01-01', - interval: CreditManagementInstallmentInterval.MONTH, - paymentPlanCostAmount: 3.5, - paymentPlanCostAmountVat: 1.2, - recipientemail: 'test@buckaroo.nl', - }) - .request() - .then((data) => { - expect(data.isValidationFailure()).toBeTruthy(); - }); + .request(); + + expect(response.isPendingProcessing()).toBeTruthy(); }); - test('pauseInvoice', async () => { - return creditManagement - .pauseInvoice({ + + test('CreateCreditNote', async () => { + const response = await method + .createCreditNote({ invoice: uniqid(), + originalInvoiceNumber: '6383cbc0498a24', + invoiceDate: formatDate(new Date()), + invoiceAmount: '0.01', + invoiceAmountVAT: '1', + sendCreditNoteMessage: 'Email', }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); + + // Payment plans are not enabled for this Buckaroo Credit Management subscription + // test('CreatePaymentPlan', async () => { + // let oneMonthFromNow = new Date(); + // oneMonthFromNow.setMonth(oneMonthFromNow.getMonth() + 1); + // const response = await method + // .createPaymentPlan({ + // description: 'Payment in two intstallments', + // includedInvoiceKey: 'EFD023706C6D4F1CAC8E461FB269E583', + // dossierNumber: 'PaymentplanJohnsmith4', + // installmentCount: 2, + // initialAmount: 5.0, + // startDate: formatDate(oneMonthFromNow), + // interval: CreditManagementInstallmentInterval.DAY, + // paymentPlanCostAmount: 0.0, + // paymentPlanCostAmountVat: 0.0, + // recipientEmail: 'test@buckaroo.nl', + // }) + // .request(); + // expect(response.isSuccess()).toBeTruthy(); + // }); + //todo: terminatePaymentPlan }); export const creditManagementTestInvoice = (append: object = {}): IInvoice => { + invoice = uniqid(); + return { - invoice: uniqid(), + invoice: invoice, + description: 'buckaroo_schema_test_PDF', applyStartRecurrent: false, invoiceAmount: 10, invoiceAmountVAT: 1, - invoiceDate: '2022-01-01', + invoiceDate: formatDate(new Date()), dueDate: '2030-01-01', - schemeKey: 'XXXXXX', + schemeKey: 'rwe1kw', + poNumber: 'PO-12345', maxStepIndex: 1, allowedServices: 'ideal,mastercard', debtor: { - code: 'XXXXXXXX', + code: 'johnsmith4', }, email: 'test@buckaroo.nl', phone: { - mobile: '0612345678', + mobile: '06198765432', }, person: { culture: 'nl-NL', @@ -249,15 +194,15 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { initials: 'JS', firstName: 'Test', lastNamePrefix: 'Jones', - lastName: 'Acceptatie', + lastName: 'Aflever', gender: Gender.MALE, }, company: { culture: 'nl-NL', name: 'Buckaroo B.V.', vatApplicable: true, - vatNumber: 'NLXXXXXXXXXXB01', - chamberOfCommerce: 'XXXXXX41', + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741', }, address: { street: 'Hoofdstraat', @@ -268,6 +213,42 @@ export const creditManagementTestInvoice = (append: object = {}): IInvoice => { state: 'Friesland', country: 'NL', }, + articles: [ + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 1, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123, + }, + { + productGroupName: 'Toys', + productGroupOrderIndex: 1, + productOrderIndex: 2, + type: 'Regular', + identifier: 'ART12', + description: 'Blue Toy Car', + quantity: 3, + unitOfMeasurement: 'piece(s)', + price: 10, + discountPercentage: 20, + totalDiscount: 6, + vatPercentage: 21, + totalVat: 0.6, + totalAmountExVat: 8.4, + totalAmount: 123, + }, + ], ...append, }; }; diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index 3dc88bf..eb7faa0 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -1,28 +1,31 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { PaymentMethodInstance, uniqid } from '../../src'; -const method = buckarooClientTest.method('eps'); +let method: PaymentMethodInstance<'eps'>; +let transactionKey: string; + +beforeEach(() => { + method = buckarooClientTest.method('eps'); +}); describe('Testing Eps methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 100, }) - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); test('Refund', async () => { - return method + const response = await method .refund({ invoice: uniqid(), amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: transactionKey, }) - .request() - .then((response) => { - expect(response.isFailed()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); + }); }); diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 855683d..6110c76 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,59 +1,51 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { ServiceCode } from '../../src'; +import { ServiceCode, uniqid } from '../../src'; const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { - return method - .issuerList() - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + const response = await method.issuerList().request(); + expect(response.isSuccess()).toBeTruthy(); }); + test('CreateMandate', async () => { - return method + const response = await method .createMandate({ - debtorReference: 'XXXXXXXXX', + emandatereason: 'Testing', + sequenceType: 0, + purchaseId: uniqid(), + debtorbankid: 'INGBNL2A', + debtorReference: 'reference', language: 'nl', continueOnIncomplete: true, - purchaseId: 'XXXXXXXXXXXXXX', - sequenceType: 0, }) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); + test('GetStatus', async () => { - return method - .status({ mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + const response = await method.status({ mandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8' }).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('ModifyMandate', async () => { - return method + const response = await method .modifyMandate({ - originalMandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalMandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8', continueOnIncomplete: true, }) - .request() - .then((response) => { - expect(response.isFailed()).toBeTruthy(); - }); - }); - test('CancelMandate', async () => { - return method - .setServiceCode('emandateb2b' as ServiceCode) - .cancelMandate({ - mandateId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - purchaseId: 'XXXXXXXXXXXXXX', - }) - .request() - .then((response) => { - expect(response.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); + // Unknown action 'CancelMandate' used on service 'emandate'. + // No valid subscription found for service 'emandateb2b'. + // test('CancelMandate', async () => { + // const response = await method + // .setServiceCode('emandateb2b' as ServiceCode) + // .cancelMandate({ + // mandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8', + // purchaseId: '6383d3e86944a0', + // }) + // .request(); + // expect(response.isSuccess()).toBeTruthy(); + // }); }); diff --git a/tests/PaymentMethods/ExternalPayment.test.ts b/tests/PaymentMethods/ExternalPayment.test.ts index 2b7a512..86d4dd7 100644 --- a/tests/PaymentMethods/ExternalPayment.test.ts +++ b/tests/PaymentMethods/ExternalPayment.test.ts @@ -1,28 +1,32 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('externalpayment'); +let method: PaymentMethodInstance<'externalpayment'>; +let transactionKey: string; + +beforeEach(() => { + method = buckarooClientTest.method('externalpayment'); +}); describe('Testing ExternalPayment methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 10, }) - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((response) => { - expect(response.isFailed()).toBeTruthy(); - }); + expect(transactionKey).toBeDefined(); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: transactionKey, + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Giftcard.test.ts b/tests/PaymentMethods/Giftcard.test.ts index 2a2382b..2543c77 100644 --- a/tests/PaymentMethods/Giftcard.test.ts +++ b/tests/PaymentMethods/Giftcard.test.ts @@ -1,41 +1,58 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { PaymentMethodInstance, uniqid } from '../../src'; -const method = buckarooClientTest.method('boekenbon'); +let method: PaymentMethodInstance<'boekenbon'>; +let transactionKey: string; +beforeEach(() => { + method = buckarooClientTest.method('boekenbon'); +}); describe('GiftCard methods', () => { test('Pay', async () => { - const responsePay = await method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 10, intersolveCardnumber: '0000000000000000001', intersolvePIN: '1000', }) .request(); - expect(responsePay.isSuccess()).toBeTruthy(); - const responseRemainderPay = await buckarooClientTest - .method('ideal') + expect(response.isSuccess()).toBeTruthy(); + transactionKey = response.getTransactionKey(); + }); + + test('Pay Reminder', async () => { + const response = await method + .pay({ + amountDebit: 50, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '1000', + }) + .request(); + expect(response.isSuccess()).toBeTruthy(); + + let relatedTransactionKey = response?.data?.relatedTransactions?.[0].relatedTransactionKey || ''; + const responseRemainderPay = await method .payRemainder({ - amountDebit: 100, - issuer: 'ABNANL2A', - invoice: responsePay.data.invoice, - originalTransactionKey: responsePay.data.relatedTransactions[0].relatedTransactionKey, + amountDebit: 40, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '1000', + originalTransactionKey: relatedTransactionKey, }) .request(); - expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); + expect(responseRemainderPay.isSuccess()).toBeTruthy(); }); + test('Refund', async () => { - return method + expect(transactionKey).toBeDefined(); + const response = await method .refund({ invoice: uniqid(), amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: transactionKey, email: 'test@buckaroo.nl', lastName: 'Acceptatie', }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index a56ac3d..8daf5a6 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -1,71 +1,77 @@ -import { getIPAddress, uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; -const ideal = buckarooClientTest.method('ideal'); +let method: PaymentMethodInstance<'ideal'>; + +beforeEach(() => { + method = buckarooClientTest.method('ideal'); +}); describe('testing Ideal methods', () => { test('Issuers', async () => { - return ideal.issuers().then((response) => { - expect(Array.isArray(response)).toBeTruthy(); - }); + const response = await method.issuers(); + expect(Array.isArray(response)).toBeTruthy(); }); test('Pay Simple Payload', async () => { - return ideal + const response = await method .pay({ amountDebit: 100, - shippingCosts: 0.01, issuer: 'ABNANL2A', continueOnIncomplete: false, - additionalParameters: { - initiated_by_magento: 1, - service_action: 'something', - }, }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); test('Refund', async () => { - return ideal - .refund({ - order: uniqid(), - invoice: uniqid(), - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - amountCredit: 0.01, - clientIP: getIPAddress(), - additionalParameters: { - initiated_by_magento: '1', - service_action: 'something', - }, - }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'D2FCFA2133F5412A8D6D376D2BFEF573', + }) + ) + .request(); + expect(response.isSuccess).toBeTruthy(); }); test('InstantRefund', async () => { - return ideal - .instantRefund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + const response = await method + .instantRefund( + createRefundPayload({ + originalTransactionKey: 'D2FCFA2133F5412A8D6D376D2BFEF573', + }) + ) + .request(); + expect(response.isSuccess).toBeTruthy(); }); test('PayFastCheckout', async () => { - return ideal + const response = await method .payFastCheckout({ invoice: uniqid(), currency: 'EUR', - amountDebit: 0.01, - shippingCosts: 0.01, + amountDebit: 10, }) - .request() - .then((data) => { - expect(data.isWaitingOnUserInput()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); + }); + test('Pay Reminder', async () => { + const response = await buckarooClientTest + .method('boekenbon') + .pay({ + amountDebit: 10, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '500', + }) + .request(); + expect(response.isSuccess()).toBeTruthy(); + + let relatedTransactionKey = response?.data?.relatedTransactions?.[0].relatedTransactionKey || ''; + const responseRemainderPay = await method + .payRemainder({ + amountDebit: 5, + originalTransactionKey: relatedTransactionKey, + issuer: 'ABNANL2A', + }) + .request(); + expect(responseRemainderPay.isWaitingOnUserInput()).toBeTruthy(); }); }); + diff --git a/tests/PaymentMethods/IdealProcessing.test.ts b/tests/PaymentMethods/IdealProcessing.test.ts index 579ca21..04953d9 100644 --- a/tests/PaymentMethods/IdealProcessing.test.ts +++ b/tests/PaymentMethods/IdealProcessing.test.ts @@ -1,26 +1,25 @@ +import { PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -const idealProcessing = buckarooClientTest.method('idealprocessing'); +let method: PaymentMethodInstance<'idealprocessing'>; + +beforeEach(() => { + method = buckarooClientTest.method('idealprocessing'); +}); describe('testing Ideal Processing methods', () => { test('Issuers', async () => { - return idealProcessing.issuers().then((response) => { + return method.issuers().then((response) => { expect(Array.isArray(response)).toBeTruthy(); }); }); test('Pay Simple Payload', async () => { - return idealProcessing + const response = await method .pay({ amountDebit: 100, issuer: 'ABNANL2A', continueOnIncomplete: false, - additionalParameters: { - initiated_by_magento: 1, - service_action: 'something', - }, }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/IdealQR.test.ts b/tests/PaymentMethods/IdealQR.test.ts index 8d88053..f912e9a 100644 --- a/tests/PaymentMethods/IdealQR.test.ts +++ b/tests/PaymentMethods/IdealQR.test.ts @@ -1,9 +1,15 @@ +import { PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('idealqr'); +let method: PaymentMethodInstance<'idealqr'>; + +beforeEach(() => { + method = buckarooClientTest.method('idealqr'); +}); + describe('Testing IdealQR methods', () => { test('Pay', async () => { - return method + const response = await method .generate({ description: 'Test purchase', returnURL: 'https://buckaroo.dev/return', @@ -19,14 +25,8 @@ describe('Testing IdealQR methods', () => { amountIsChangeable: true, expiration: '2030-09-30', isProcessing: false, - additionalParameters: { - initiated_by_magento: '1', - service_action: 'something', - }, }) - .request() - .then((response) => { - expect(response.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Idin.test.ts b/tests/PaymentMethods/Idin.test.ts index 925f1cd..42c12a1 100644 --- a/tests/PaymentMethods/Idin.test.ts +++ b/tests/PaymentMethods/Idin.test.ts @@ -1,38 +1,37 @@ +import { PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; -const method = buckarooClientTest.method('idin'); +let method: PaymentMethodInstance<'idin'>; + +beforeEach(() => { + method = buckarooClientTest.method('idin'); +}); describe('Idin methods', () => { test('Verify', async () => { - return method + const response = await method .verify({ issuer: 'BANKNL2Y', }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Identify', async () => { - return method + const response = await method .identify({ issuer: 'BANKNL2Y', }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Login', async () => { - return method + const response = await method .login({ issuer: 'BANKNL2Y', }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/In3.test.ts b/tests/PaymentMethods/In3.test.ts index 798d5b7..297fc01 100644 --- a/tests/PaymentMethods/In3.test.ts +++ b/tests/PaymentMethods/In3.test.ts @@ -1,106 +1,41 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { getIPAddress, RecipientCategory, uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import { IPay } from '../../src/PaymentMethods/In3/Models/Pay'; +import { createRefundPayload, createBasePayload } from '../Payloads'; -const in3 = buckarooClientTest.method('In3'); +let method: PaymentMethodInstance<'In3'>; +const payload = createBasePayload( + {}, + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'title'], + }, + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'title'], + }, + articles: { + exclude: ['unitCode', 'vatCategory'], + }, + } +); + +beforeEach(() => { + method = buckarooClientTest.method('In3'); +}); describe('Testing In3 methods', () => { test('Pay', async () => { - return in3 - .pay(payload) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + const response = await method.pay(payload).request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return in3 - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeFalsy(); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '4BC466160ACB460EAFB8923D1BBFE33A', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); - -const payload: IPay = { - amountDebit: 100, - description: 'in3 pay', - order: uniqid(), - invoice: uniqid(), - clientIP: getIPAddress(), - billing: { - recipient: { - category: RecipientCategory.PERSON, - initials: 'TA', - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - customerNumber: 'XXXXX', - companyName: 'Buckaroo B.V.', - chamberOfCommerce: 'XXXXXX41', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - }, - email: 'test@buckaroo.nl', - }, - shipping: { - recipient: { - category: RecipientCategory.PERSON, - careOf: 'J', - firstName: 'Test', - lastName: 'Acceptatie', - chamberOfCommerce: 'XXXXXX41', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - }, - articles: [ - { - identifier: 'Articlenumber1', - type: 'Physical', - description: 'Blue Toy Car', - category: 'test product', - vatPercentage: 21, - quantity: 2, - price: 25, - }, - { - identifier: 'Articlenumber2', - type: 'Physical', - description: 'Red Toy Car', - category: 'test product', - vatPercentage: 21, - quantity: 1, - price: 25, - }, - { - identifier: 'USPShippingID', - type: 'Physical', - description: 'UPS', - category: 'test product', - vatPercentage: 21, - quantity: 1, - price: 25, - }, - ], -}; diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index 21cc623..ffbc5e1 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -1,80 +1,59 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { Gender, getIPAddress, RecipientCategory, uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, RecipientCategory } from '../../src'; +import { createAddressPayload, createBasePayload, createCustomerPayload, createRefundPayload } from '../Payloads'; +import { IPay } from '../../src/PaymentMethods/In3Old/Models/Pay'; -const capayable = buckarooClientTest.method('capayable'); +let method: PaymentMethodInstance<'capayable'>; +const payload = createBasePayload( + { + customerType: RecipientCategory.COMPANY, + invoiceDate: '22-01-2018', + email: 'test@buckaroo.nl', + phone: { + mobile: '0612345678', + }, + company: { + companyName: 'Company B.V.', + chamberOfCommerce: '123456', + }, + ...createAddressPayload({}, ['houseNumberAdditional']), + ...createCustomerPayload({}, ['firstName']), + }, + { + billing: { + exclude: ['state', 'gender', 'lastNamePrefix', 'placeOfBirth', 'title'], + }, + shipping: { + exclude: ['state', 'gender', 'lastNamePrefix', 'placeOfBirth', 'title'], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory', 'vatPercentage'], + }, + } +); + +beforeEach(() => { + method = buckarooClientTest.method('capayable'); +}); describe('Testing capayable methods', () => { + // "Action Pay is no longer available for Capayable" test('Pay', async () => { - return capayable - .pay(paymentPayload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + const response = await method.pay(payload).request(); + expect(response.isSuccess()).toBeTruthy(); }); - test('Refund', async () => { - return capayable - .refund({ - invoice: uniqid(), - amountCredit: paymentPayload.amountDebit, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.isFailed()).toBeTruthy(); - }); + test.only('PayInInstallments', async () => { + const response = await method.payInInstallments(payload).request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); - test('PayInInstallments', async () => { - return capayable - .payInInstallments(paymentPayload) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + test.only('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'EF24A62B8D7B4F88859FBA4DF140B6C2', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); - -const paymentPayload = { - clientIP: getIPAddress(), - description: 'Test', - amountDebit: 100, - customerType: RecipientCategory.COMPANY, - invoiceDate: '22-01-2018', - customer: { - gender: Gender.FEMALE, - culture: 'nl-NL', - initials: 'TA', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - }, - company: { - companyName: 'Buckaroo B.V.', - chamberOfCommerce: 'XXXXXX41', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberSuffix: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - email: 'test@buckaroo.nl', - phone: { - mobile: '0612345678', - }, - articles: [ - { - identifier: '64381664f2f8b', - price: 10, - quantity: 1, - description: 'Blue Toy Car', - }, - ], - subtotals: [ - { - name: 'Verzendkosten', - value: 2, - }, - ], -}; diff --git a/tests/PaymentMethods/KBC.test.ts b/tests/PaymentMethods/KBC.test.ts index 7409243..8d463ca 100644 --- a/tests/PaymentMethods/KBC.test.ts +++ b/tests/PaymentMethods/KBC.test.ts @@ -1,29 +1,29 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('KBCPaymentButton'); +let method: PaymentMethodInstance<'KBCPaymentButton'>; +beforeEach(() => { + method = buckarooClientTest.method('KBCPaymentButton'); +}); describe('Testing KBC methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 100, }) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((response) => { - expect(response.isFailed()).toBeTruthy(); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'F662726FCA4C4B609A6283DB686B1312', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Klarna.test.ts b/tests/PaymentMethods/Klarna.test.ts index 00276de..8d51feb 100644 --- a/tests/PaymentMethods/Klarna.test.ts +++ b/tests/PaymentMethods/Klarna.test.ts @@ -1,87 +1,69 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Klarna/Models/Pay'; -import { RecipientCategory, uniqid } from '../../src'; +import { PaymentMethodInstance } from '../../src'; +import { createBasePayload } from '../Payloads'; + +let method: PaymentMethodInstance<'klarna'>; + +beforeEach(() => { + method = buckarooClientTest.method('klarna'); +}); -const klarna = buckarooClientTest.method('klarna'); describe('Testing Klarna methods', () => { test('Pay', async () => { - return klarna - .pay(payload) - .request() - .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy(); - }); + const response = await method.pay(getPayload()).request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('PayInInstallments', async () => { - const clonedPayload = JSON.parse(JSON.stringify(payload)); - clonedPayload.currency = 'GBP'; - clonedPayload.billing.address.country = 'GB'; - return klarna - .payInInstallments(clonedPayload) - .request() - .then((res) => { - expect(res).toBeDefined(); - }); + const response = await method.payInInstallments(getPayload('GB', 'GBP')).request(); + expect(response.isPendingProcessing()).toBeTruthy(); + }); + test('PayReminder', async () => { + const response = await buckarooClientTest + .method('boekenbon') + .pay({ + amountDebit: 10, + intersolveCardnumber: '0000000000000000001', + intersolvePIN: '500', + }) + .request(); + expect(response.isSuccess()).toBeTruthy(); + + let relatedTransactionKey = response?.data?.relatedTransactions?.[0].relatedTransactionKey || ''; + const responseRemainderPay = await method + .payRemainder({ + ...getPayload(), + amountDebit: 5, + originalTransactionKey: relatedTransactionKey, + }) + .request(); + expect(responseRemainderPay.isPendingProcessing()).toBeTruthy(); }); }); -let payload: IPay = { - amountDebit: 100, - invoice: uniqid(), - order: uniqid(), - billing: { - recipient: { - category: RecipientCategory.PERSON, - gender: 'female', - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - }, - email: 'test@buckaroo.nl', - }, - shipping: { - recipient: { - category: RecipientCategory.COMPANY, - gender: 'male', - firstName: 'Test', - lastName: 'Acceptatie', - birthDate: '1990-01-01', - }, - address: { - street: 'Hoofdstraat', - houseNumber: '80', - houseNumberAdditional: 'a', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - email: 'test@buckaroo.nl', - }, - articles: [ +function getPayload(country: string = 'NL', currency: string = 'EUR'): IPay { + const payload = createBasePayload( + { currency: currency }, { - identifier: 'Articlenumber1', - description: 'Blue Toy Car', - vatPercentage: 21, - quantity: 1, - price: 50, - }, - { - identifier: 'Articlenumber2', - description: 'Red Toy Car', - vatPercentage: 21, - quantity: 1, - price: 50, - }, - ], -}; + billing: { + exclude: ['state', 'lastNamePrefix', 'placeOfBirth', 'title', 'phone', 'initials', 'culture'], + }, + shipping: { + exclude: ['state', 'lastNamePrefix', 'placeOfBirth', 'title', 'phone', 'initials', 'culture'], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory'], + }, + } + ); + + if (payload.shipping?.address) { + payload.shipping.address.country = country; + } + + if (payload.billing?.address) { + payload.billing.address.country = country; + } + + return payload; +} diff --git a/tests/PaymentMethods/Mbway.test.ts b/tests/PaymentMethods/Mbway.test.ts index 67d87b8..3c862dd 100644 --- a/tests/PaymentMethods/Mbway.test.ts +++ b/tests/PaymentMethods/Mbway.test.ts @@ -1,15 +1,30 @@ +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; + +let method: PaymentMethodInstance<'MBWay'>; + +beforeEach(() => { + method = buckarooClientTest.method('MBWay'); +}); -const method = buckarooClientTest.method('MBWay'); describe('Mbway methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.3, }) - .request() - .then((response) => { - expect(response.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); + }); + test('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'C2D92C20BA244E02AB3CF2DE56E026F1', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts index 48ef385..df294d3 100644 --- a/tests/PaymentMethods/Multibanco.test.ts +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -1,15 +1,30 @@ +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; + +let method: PaymentMethodInstance<'multibanco'>; + +beforeEach(() => { + method = buckarooClientTest.method('multibanco'); +}); describe('Multibanco methods', () => { test('Pay', async () => { - return buckarooClientTest - .method('multibanco') + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.30, }) - .request() - .then((info) => { - expect(info.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); + }); + test('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '3BEB1B96CE7E4ECBB68EE44BDDE7FD6F', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts index 03b4adb..3536849 100644 --- a/tests/PaymentMethods/NoService.test.ts +++ b/tests/PaymentMethods/NoService.test.ts @@ -5,17 +5,16 @@ const method = buckarooClientTest.method('noservice'); describe('NoService methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 100, invoice: uniqid(), servicesSelectableByClient: 'ideal,bancontactmrcash,paypal', - servicesExcludedForClient: 'ideal', + servicesExcludedForClient: 'mbway', continueOnIncomplete: true, }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); + }); }); diff --git a/tests/PaymentMethods/PayPerEmail.test.ts b/tests/PaymentMethods/PayPerEmail.test.ts index 1ce060a..57ffd00 100644 --- a/tests/PaymentMethods/PayPerEmail.test.ts +++ b/tests/PaymentMethods/PayPerEmail.test.ts @@ -1,14 +1,14 @@ -import { Gender, uniqid } from '../../src'; +import { Gender, PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; const method = buckarooClientTest.method('payperemail'); describe('PayPerEmail methods', () => { test('paymentInvitation', async () => { - return method + const response = await method .paymentInvitation({ currency: 'EUR', - amountDebit: 100, + amountDebit: 10, order: uniqid(), invoice: uniqid(), merchantSendsEmail: false, @@ -22,9 +22,7 @@ describe('PayPerEmail methods', () => { lastName: 'Acceptatie', }, }) - .request() - .then((res) => { - expect(res.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isAwaitingConsumer()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index bdcb7a3..9467a19 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -1,41 +1,41 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; + +let method: PaymentMethodInstance<'payconiq'>; + +beforeEach(() => { + method = buckarooClientTest.method('payconiq'); +}); -const payconiq = buckarooClientTest.method('payconiq'); describe('Payconiq', () => { test('Pay', async () => { - return payconiq + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.3, order: uniqid(), }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing).toBeTruthy(); }); test('Refund', async () => { - return payconiq - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '93FA5B31D80C489BB0822A3BD8037D6E', + }) + ) + .request(); + expect(response.isSuccess).toBeTruthy(); }); test('InstantRefund', async () => { - return payconiq - .instantRefund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method + .instantRefund( + createRefundPayload({ + originalTransactionKey: '93FA5B31D80C489BB0822A3BD8037D6E', + }) + ) + .request(); + expect(response.isSuccess).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 7277611..13190df 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -1,38 +1,39 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('PayByBank'); +let method: PaymentMethodInstance<'PayByBank'>; + +beforeEach(() => { + method = buckarooClientTest.method('PayByBank'); +}); describe('PaymentInitiation methods', () => { test('Issuers', async () => { - return method.issuers().then((response) => { + await method.issuers().then((response) => { expect(Array.isArray(response)).toBeTruthy(); }); }); test('Pay', async () => { - return method + const response = await method .pay({ issuer: 'RABONL2U', - amountDebit: 100, + amountDebit: 100.3, order: uniqid(), invoice: uniqid(), countryCode: 'NL', }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '93FA5B31D80C489BB0822A3BD8037D6E', + }) + ) + .request(); + expect(response.isSuccess).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Paypal.test.ts b/tests/PaymentMethods/Paypal.test.ts index cf79f69..efe49e8 100644 --- a/tests/PaymentMethods/Paypal.test.ts +++ b/tests/PaymentMethods/Paypal.test.ts @@ -1,36 +1,35 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('paypal'); +let method: PaymentMethodInstance<'paypal'>; +beforeEach(() => { + method = buckarooClientTest.method('paypal'); +}); describe('Paypal', () => { test('Pay', async () => { - return method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.3, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'EAD916B7D6544568A02B40B88F9207F6', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('ExtraInfo', async () => { - buckarooClientTest.method('subscriptions').createCombined({}); - return method + const response = await method .extraInfo({ - amountDebit: 100, + amountDebit: 100.3, address: { street: 'Hoofdstraat', street2: 'Street 2', @@ -44,9 +43,7 @@ describe('Paypal', () => { noShipping: '0', phone: { mobile: '0612345678' }, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/PiM.test.ts b/tests/PaymentMethods/PiM.test.ts index 1ccb56f..23062d5 100644 --- a/tests/PaymentMethods/PiM.test.ts +++ b/tests/PaymentMethods/PiM.test.ts @@ -5,7 +5,7 @@ const method = buckarooClientTest.method('pim'); describe('PiM', () => { test('generate', async () => { - return method + const response = await method .generate({ amountDebit: 100, description: 'Omschrijving', @@ -24,9 +24,7 @@ describe('PiM', () => { text: 'bedankt', }, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Pos.test.ts b/tests/PaymentMethods/Pos.test.ts index bd15b06..e3d2d48 100644 --- a/tests/PaymentMethods/Pos.test.ts +++ b/tests/PaymentMethods/Pos.test.ts @@ -5,15 +5,13 @@ const method = buckarooClientTest.method('pospayment'); describe('POS methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 100, invoice: uniqid(), terminalId: '50000001', }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Przelewy24.test.ts b/tests/PaymentMethods/Przelewy24.test.ts index 303fe71..ffe66d8 100644 --- a/tests/PaymentMethods/Przelewy24.test.ts +++ b/tests/PaymentMethods/Przelewy24.test.ts @@ -1,34 +1,35 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('przelewy24'); +let method: PaymentMethodInstance<'przelewy24'>; + +beforeEach(() => { + method = buckarooClientTest.method('przelewy24'); +}); describe('Przelewy24', () => { test('Pay', async () => { - return method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.3, customer: { firstName: 'Test', lastName: 'Acceptatie', }, email: 'test@buckaroo.nl', }) - .request() - .then((res) => { - expect(res.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'C2D92C20BA244E02AB3CF2DE56E026F1', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 3d374e3..779da47 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,168 +1,181 @@ +import { uniq } from 'lodash'; +import { PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { formatDate, getServiceParameter } from '../Payloads'; -const subscription = buckarooClientTest.method('subscriptions'); +let method: PaymentMethodInstance<'subscriptions'>; +let transactionKey: string; + +beforeEach(() => { + method = buckarooClientTest.method('subscriptions'); +}); describe('Subscription methods', () => { test('Create', async () => { - return subscription + const response = await method .create({ - additionalParameters: { - signature: 'XXXXXXXX', - }, + startDate: formatDate(new Date()), ratePlans: { add: { - startDate: '2024-07-23', - ratePlanCode: 'XXXXXXXX', + startDate: formatDate(new Date()), + billingTiming: 1, + ratePlanName: 'Test Rate Plan', + ratePlanDescription: 'This is a test rate plan', + currency: 'EUR', + billingInterval: 'Weekly', + termStartDay: 1, }, }, ratePlanCharges: { add: { - ratePlanChargeCode: 'XXXXXXXX', + ratePlanChargeName: 'Rate Plan Charge', + ratePlanChargeDescription: 'This is a test rate plan charge', + unitOfMeasure: 'Quantity', + baseNumberOfUnits: 1, + partialBilling: 'Billfull', + pricePerUnit: 2, + priceIncludesVat: true, + vatPercentage: 21, + ratePlanChargeType: 'Recurring', }, }, - configurationCode: 'XXXXXXXX', - configuration: { - name: 'XXXXXXXX', - }, + configurationCode: '1jg5ke6j', debtor: { - code: 'XXXXXXXX', + code: 'johnsmith4', }, }) - .request() - .then((data) => { - expect(data.hasError()).toBeTruthy(); - }); - }); - test('Update', async () => { - return subscription - .update({ - email: 'test@buckaroo.nl', - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - configurationCode: 'XXXXXXXX', - ratePlan: { - update: { - ratePlanGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - startDate: '2022-01-01', - endDate: '2030-01-01', - }, - }, - }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + .request(); + + transactionKey = getServiceParameter(response, 'SubscriptionGuid'); + expect(response.isSuccess()).toBeTruthy(); }); + test('Combined Subscription', async () => { - subscription.createCombined({ + method.createCombined({ pushURL: 'https://buckaroo.dev/push', includeTransaction: false, transactionVatPercentage: 5, - configurationCode: 'XXXXXXXX', + configurationCode: '1jg5ke6j', email: 'test@buckaroo.nl', ratePlans: { add: { - startDate: '2033-01-01', - ratePlanCode: 'XXXXXXXX', + startDate: formatDate(new Date()), + ratePlanCode: '9863hdcj', }, }, phone: { mobile: '0612345678', }, debtor: { - code: 'XXXXXXXX', + code: 'johnsmith4', }, company: { culture: 'nl-NL', companyName: 'Buckaroo B.V.', vatApplicable: true, - vatNumber: 'NLXXXXXXXXXXB01', - chamberOfCommerce: 'XXXXXX41', + vatNumber: 'NL140619562B01', + chamberOfCommerce: '20091741', }, address: { street: 'Hoofdstraat', houseNumber: '80', + houseNumberAdditional: 'a', zipcode: '8441ER', city: 'Heerenveen', country: 'NL', }, }); - return subscription + + const response = await method .combine('ideal') .pay({ issuer: 'ABNANL2A', - amountDebit: 100, + amountDebit: 10.1, startRecurrent: true, + invoice: uniqid(), }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); + .request(); + + expect(response.isWaitingOnUserInput()).toBeTruthy(); + }); + + test('Update', async () => { + expect(transactionKey).toBeDefined(); + const response = await method + .update({ + subscriptionGuid: transactionKey, + configurationCode: '1jg5ke6j', + email: 'test@buckaroo.nl', + ratePlan: { + update: { + ratePlanGuid: '56CC308A1D694CF19F808993DD42BE7B', + endDate: '2030-01-01', + charge: { + ratePlanChargeGuid: '15C2CEEB39E34C86AAD0038ED73807B0', + baseNumberOfUnits: 1, + pricePerUnit: 5, + }, + }, + }, + }) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Update Combined Subscription', async () => { - subscription.updateCombined({ - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + method.updateCombined({ + startRecurrent: true, + subscriptionGuid: 'E29238210FE04E069FD83E16ACE50950', }); - return subscription + const response = await method .combine('ideal') .pay({ issuer: 'ABNANL2A', - amountDebit: 100, - }) - .request() - .then((data) => { - expect(data).toBeDefined(); - }); - }); - test('Stop Subscription', async () => { - return subscription - .stop({ - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 10.1, + invoice: uniqid(), }) - .request() - .then((res) => { - expect(res.httpResponse.status === 200).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Subscription Info', async () => { - return subscription + const response = await method .info({ - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + subscriptionGuid: transactionKey, }) - .request() - .then((res) => { - expect(res.httpResponse.status === 200).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Delete Subscription Config', async () => { - return subscription + const response = await method .deletePaymentConfig({ - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + subscriptionGuid: transactionKey, }) - .request() - .then((res) => { - expect(res.httpResponse.status === 200).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Subscription Pause', async () => { - return subscription + const response = await method .pause({ - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + subscriptionGuid: transactionKey, resumeDate: '2030-01-01', }) - .request() - .then((res) => { - expect(res.httpResponse.status === 200).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Subscription Resume', async () => { - return subscription + const response = await method .resume({ resumeDate: '2030-01-01', - subscriptionGuid: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + subscriptionGuid: transactionKey, + }) + .request(); + expect(response.isSuccess()).toBeTruthy(); + }); + test('Stop Subscription', async () => { + const response = await method + .stop({ + subscriptionGuid: transactionKey, }) - .request() - .then((res) => { - expect(res.httpResponse.status === 200).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/SurePay.test.ts b/tests/PaymentMethods/SurePay.test.ts index 42d4126..946d629 100644 --- a/tests/PaymentMethods/SurePay.test.ts +++ b/tests/PaymentMethods/SurePay.test.ts @@ -4,17 +4,16 @@ const method = buckarooClientTest.method('surepay'); describe('SurePay methods', () => { test('Verify', async () => { - return method + const response = await method .verify({ - amountDebit: 100, + currency: '', + amountDebit: 100.3, bankAccount: { iban: 'NLXXTESTXXXXXXXXXX', accountName: 'Test Acceptatie', }, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Trustly.test.ts b/tests/PaymentMethods/Trustly.test.ts index 158dc6a..d485ffe 100644 --- a/tests/PaymentMethods/Trustly.test.ts +++ b/tests/PaymentMethods/Trustly.test.ts @@ -1,21 +1,37 @@ +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('trustly'); +let method: PaymentMethodInstance<'trustly'>; + +beforeEach(() => { + method = buckarooClientTest.method('trustly'); +}); describe('Trustly', () => { test('Pay', async () => { - return method + const response = await method .pay({ + continueOnIncomplete: true, amountDebit: 100, customer: { firstName: 'Test', lastName: 'Acceptatie', countryCode: 'NL', + email: 'test@buckaroo.nl', }, }) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); + }); + test('Pay', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'D1A57C57FAF5430D9F98B33D871D15C0', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); From a4234e2b73f2694bb23b2769fd4b8085b74f9bb5 Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Mon, 28 Jul 2025 09:53:18 +0200 Subject: [PATCH 2/6] Update tests --- package.json | 2 + tests/PaymentMethods/KlarnaKp.test.ts | 108 ++++++++++----------- tests/PaymentMethods/Knaken.test.ts | 45 +++++---- tests/PaymentMethods/SEPA.test.ts | 94 ++++++++---------- tests/PaymentMethods/Subscriptions.test.ts | 1 - tests/PaymentMethods/WechatPay.test.ts | 38 ++++---- 6 files changed, 143 insertions(+), 145 deletions(-) diff --git a/package.json b/package.json index 216ff30..8c1de1f 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@rollup/plugin-typescript": "^11.1.5", "@types/crypto-js": "^4.1.1", "@types/jest": "^29.4.0", + "@types/lodash": "^4.17.17", "@types/node": "^18.11.18", "dotenv": "^16.0.3", "jest": "^29.4.2", @@ -49,6 +50,7 @@ "axios": "^1.6.2", "crypto-js": "^4.1.1", "ip-address": "^8.1.0", + "lodash": "^4.17.21", "xml2js": "^0.6.2" }, "repository": { diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 5184f9d..1c12c0f 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -1,72 +1,68 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { Gender, getIPAddress, uniqid } from '../../src'; +import { Gender, getIPAddress, PaymentMethodInstance, uniqid } from '../../src'; +import { createBasePayload } from '../Payloads'; +import { IReserve } from '../../src/PaymentMethods/KlarnaKP/Models/IReserve'; -const klarnaKp = buckarooClientTest.method('klarnakp'); +let method: PaymentMethodInstance<'klarnakp'>; + +beforeEach(() => { + method = buckarooClientTest.method('klarnakp'); +}); describe('KlarnaKp', () => { test('Pay', async () => { - return klarnaKp + const response = await method .pay({ - amountDebit: 100, - reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 100.3, + reservationNumber: '6c24888a-24ba-42bf-be19-7ceec6f0ee23', }) - .request() - .then((info) => { - expect(info.isFailed()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); - test('Reserve', async () => { - return klarnaKp - .reserve({ - clientIP: getIPAddress(), - invoice: uniqid(), - gender: Gender.MALE, - operatingCountry: 'NL', - pno: '01011990', - billing: { - recipient: { - firstName: 'Test', - lastName: 'Acceptatie', - }, - address: { - street: 'Hoofdstraat', - zipcode: '8441ER', - city: 'Heerenveen', - country: 'NL', - }, - phone: { - mobile: '0612345678', - }, - email: 'test@buckaroo.nl', - }, - articles: [ + test.only('Reserve', async () => { + const response = await method + .reserve( + createBasePayload( { - identifier: 'Articlenumber1', - description: 'Blue Toy Car', - vatPercentage: 21, - quantity: 2, - price: 20.1, - imageUrl: 'https://example.com/image', - productUrl: 'https://example.com/product', + clientIP: getIPAddress(), + gender: Gender.MALE, + operatingCountry: 'NL', + pno: '01011990', }, { - identifier: 'Articlenumber2', - description: 'Red Toy Car', - vatPercentage: 21, - quantity: 1, - price: 10.1, - imageUrl: 'https://example.com/image', - productUrl: 'https://example.com/product', - }, - ], - }) - .request() - .then((info) => { - expect(info.isPendingProcessing()).toBeTruthy(); - }); + billing: { + exclude: [ + 'state', + 'lastNamePrefix', + 'placeOfBirth', + 'title', + 'phone', + 'initials', + 'culture', + ], + }, + shipping: { + exclude: [ + 'state', + 'lastNamePrefix', + 'placeOfBirth', + 'title', + 'phone', + 'initials', + 'culture', + ], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory'], + }, + } + ) + ) + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Cancel', async () => { - return klarnaKp + return method .cancel({ reservationNumber: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', }) diff --git a/tests/PaymentMethods/Knaken.test.ts b/tests/PaymentMethods/Knaken.test.ts index 060f54f..09995fc 100644 --- a/tests/PaymentMethods/Knaken.test.ts +++ b/tests/PaymentMethods/Knaken.test.ts @@ -1,30 +1,39 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('knaken'); +let method: PaymentMethodInstance<'knaken'>; + +beforeEach(() => { + method = buckarooClientTest.method('knaken'); +}); describe('Knaken', () => { + // The transaction was rejected during processing by Unauthorized.. test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 0.01, - order: uniqid(), + invoice: uniqid(), + CustomerName: 'Rico', + returnURL: 'https://example.com/buckaroo/return', + returnURLCancel: 'https://example.com/buckaroo/cancel', + returnURLError: 'https://example.com/buckaroo/error', + returnURLReject: 'https://example.com/buckaroo/reject', + pushURL: 'https://example.com/buckaroo/push', + pushURLFailure: 'https://example.com/buckaroo/push-failure', }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((data) => { - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/SEPA.test.ts b/tests/PaymentMethods/SEPA.test.ts index eac5b88..dc16ac1 100644 --- a/tests/PaymentMethods/SEPA.test.ts +++ b/tests/PaymentMethods/SEPA.test.ts @@ -1,16 +1,22 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; import { IPay } from '../../src/PaymentMethods/SEPA/Models/Pay'; +import { createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('sepadirectdebit'); +let method: PaymentMethodInstance<'sepadirectdebit'>; + +beforeEach(() => { + method = buckarooClientTest.method('sepadirectdebit'); +}); const paymentPayload: IPay = { invoice: uniqid(), - amountDebit: 100, - iban: 'NLXXTESTXXXXXXXXXX', - bic: 'XXXXXXXXX', + amountDebit: 100.3, + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', + startRecurrent: true, collectdate: '2022-12-01', - mandateReference: 'XXXXXXXXXXXXXXX', + mandateReference: '1DCtestreference', mandateDate: '2022-07-03', customer: { name: 'Test Acceptatie', @@ -19,52 +25,40 @@ const paymentPayload: IPay = { describe('SEPA methods', () => { test('Pay', async () => { - return method - .pay(paymentPayload) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); - }); - test('Refund', async () => { - return method - .refund({ - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method.pay(paymentPayload).request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Authorize', async () => { - return method - .authorize(paymentPayload) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + const response = await method.authorize(paymentPayload).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('PayRecurrent', async () => { - return method + const response = await method .payRecurrent({ invoice: uniqid(), - collectDate: '2030-07-03', - amountDebit: 100, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + amountDebit: 10, + originalTransactionKey: '636BC4E3540D4B3DA1962B5BA0F680E9', }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); + }); + test('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '636BC4E3540D4B3DA1962B5BA0F680E9', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('ExtraInfo', async () => { - return method + const response = await method .extraInfo({ amountDebit: 100, invoice: uniqid(), - iban: 'NLXXTESTXXXXXXXXXX', - bic: 'XXXXXXXXX', + iban: 'NL13TEST0123456789', + bic: 'TESTNL2A', contractID: 'Test', mandateDate: '2022-07-03', customerReferencePartyName: 'Test', @@ -80,22 +74,18 @@ describe('SEPA methods', () => { country: 'NL', }, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Emandates', async () => { - return method + const response = await method .payWithEmandate({ - order: uniqid(), + order: '', invoice: uniqid(), - mandateReference: 'XXXXXXXXXXXXXXX', - amountDebit: 100, + mandateReference: '1DC326734AB3084FC7', + amountDebit: 100.3, }) - .request() - .then((info) => { - expect(info.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Subscriptions.test.ts b/tests/PaymentMethods/Subscriptions.test.ts index 779da47..b9b4677 100644 --- a/tests/PaymentMethods/Subscriptions.test.ts +++ b/tests/PaymentMethods/Subscriptions.test.ts @@ -1,4 +1,3 @@ -import { uniq } from 'lodash'; import { PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { formatDate, getServiceParameter } from '../Payloads'; diff --git a/tests/PaymentMethods/WechatPay.test.ts b/tests/PaymentMethods/WechatPay.test.ts index 32e4319..1c64b14 100644 --- a/tests/PaymentMethods/WechatPay.test.ts +++ b/tests/PaymentMethods/WechatPay.test.ts @@ -1,29 +1,31 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; +import { createRefundPayload } from '../Payloads'; + +let method: PaymentMethodInstance<'wechatpay'>; + +beforeEach(() => { + method = buckarooClientTest.method('wechatpay'); +}); -const method = buckarooClientTest.method('wechatpay'); describe('WechatPay', () => { test('Pay', async () => { - return method + const response = await method .pay({ - amountDebit: 100, + amountDebit: 100.3, locale: 'en-US', }) - .request() - .then((response) => { - expect(response.isPendingProcessing()).toBeDefined(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - }) - .request() - .then((response) => { - expect(response.httpResponse.status).toEqual(200); - }); + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: '558B0120FD64458C8ED8349FE4C0714A', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); From 2faee9d6853a78f2162f5671d5d78d95734be73c Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Tue, 29 Jul 2025 13:27:07 +0200 Subject: [PATCH 3/6] Resolve comments --- package.json | 1 - tests/BuckarooClient.test.ts | 4 + tests/PaymentMethods/AfterPay.test.ts | 88 ++++++++--------- .../PaymentMethods/AfterPayDigiAccept.test.ts | 97 ++++++++----------- tests/PaymentMethods/Alipay.test.ts | 26 ++--- tests/PaymentMethods/Bancontact.test.ts | 4 +- tests/PaymentMethods/BankTransfer.test.ts | 4 +- tests/PaymentMethods/Belfius.test.ts | 4 +- tests/PaymentMethods/Billink.test.ts | 13 +-- tests/PaymentMethods/Blik.test.ts | 29 +++--- tests/PaymentMethods/BuckarooVoucher.test.ts | 23 +++-- tests/PaymentMethods/BuckarooWallet.test.ts | 23 ++--- tests/PaymentMethods/ClickToPay.test.ts | 9 +- tests/PaymentMethods/Emandate.test.ts | 9 +- tests/PaymentMethods/Ideal.test.ts | 4 +- tests/PaymentMethods/In3Old.test.ts | 4 +- tests/PaymentMethods/KlarnaKp.test.ts | 2 +- tests/PaymentMethods/Marketplaces.test.ts | 78 +++++++-------- tests/PaymentMethods/Payconiq.test.ts | 4 +- .../PaymentMethods/PaymentInitiation.test.ts | 2 +- tests/PaymentMethods/Thunes.test.ts | 45 ++++----- 21 files changed, 223 insertions(+), 250 deletions(-) diff --git a/package.json b/package.json index 8c1de1f..37f009b 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,6 @@ "axios": "^1.6.2", "crypto-js": "^4.1.1", "ip-address": "^8.1.0", - "lodash": "^4.17.21", "xml2js": "^0.6.2" }, "repository": { diff --git a/tests/BuckarooClient.test.ts b/tests/BuckarooClient.test.ts index 4f8761e..5e4e82c 100644 --- a/tests/BuckarooClient.test.ts +++ b/tests/BuckarooClient.test.ts @@ -13,6 +13,10 @@ const BuckarooClient = Buckaroo.InitializeClient( returnURL: process.env.BPE_RETURN_URL || '', returnURLCancel: process.env.BPE_RETURN_URL_CANCEL || '', pushURL: process.env.BPE_PUSH_URL || '', + timeout: 20000, } ); + +jest.setTimeout(20000); + export default BuckarooClient; diff --git a/tests/PaymentMethods/AfterPay.test.ts b/tests/PaymentMethods/AfterPay.test.ts index cc0687e..41a5b3e 100644 --- a/tests/PaymentMethods/AfterPay.test.ts +++ b/tests/PaymentMethods/AfterPay.test.ts @@ -2,83 +2,71 @@ import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/Afterpay/Model/Pay'; import { createBasePayload, createRefundPayload } from '../Payloads'; import { IRefund } from '../../src/PaymentMethods/Afterpay/Model/Refund'; +import { PaymentMethodInstance } from '../../src'; + +let method: PaymentMethodInstance<'afterpay'>; +let payload: IPay; + +beforeEach(() => { + method = buckarooClientTest.method('afterpay'); + payload = createBasePayload( + {}, + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], + }, + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory'], + }, + } + ); +}); -const payload = createBasePayload( - {}, - { - billing: { - exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], - }, - shipping: { - exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth', 'initials', 'title'], - }, - articles: { - exclude: ['type', 'unitCode', 'vatCategory'], - }, - } -); -const method = buckarooClientTest.method('afterpay'); describe('AfterPay methods', () => { test('Pay', async () => { - return method - .pay(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + const response = await method.pay(payload).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Pay with Different Version', async () => { - return method - .setServiceVersion(2) - .pay(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + const response = await method.setServiceVersion(2).pay(payload).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Refund', async () => { - return method + const response = await method .refund( createRefundPayload({ originalTransactionKey: '4D2D8ABD5EA14E908F855BC7A8B10735', amountCredit: payload.amountDebit, }) ) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Authorize', async () => { - return method - .authorize(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); - }); //Add 10s timeout as third param + const response = await method.authorize(payload).request(); + expect(response.isSuccess()).toBeTruthy(); + }); test('CancelAuthorize', async () => { - return method + const response = await method .cancelAuthorize( createRefundPayload({ originalTransactionKey: '9CFEFC57074247DE92F7804246D1DD5D', amountCredit: payload.amountDebit, }) ) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Capture', async () => { - return method + const response = await method .capture({ ...payload, originalTransactionKey: 'CD1493C19B69488CB88EC6576DD1E928', }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/AfterPayDigiAccept.test.ts b/tests/PaymentMethods/AfterPayDigiAccept.test.ts index 3fda0b5..56faeaf 100644 --- a/tests/PaymentMethods/AfterPayDigiAccept.test.ts +++ b/tests/PaymentMethods/AfterPayDigiAccept.test.ts @@ -1,93 +1,78 @@ -import { Gender, getIPAddress, IRefundRequest, RequestTypes, uniqid } from '../../src'; +import { getIPAddress, IRefundRequest, PaymentMethodInstance, RequestTypes } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { IPay } from '../../src/PaymentMethods/AfterpayDigiAccept/Model/Pay'; import { createBasePayload, createRefundPayload } from '../Payloads'; -const method = buckarooClientTest.method('afterpaydigiaccept'); +let method: PaymentMethodInstance<'afterpaydigiaccept'>; +let payload: IPay; -const payload = createBasePayload( - { - addressesDiffer: true, - customerIPAddress: getIPAddress(), - shippingCosts: 0.5, - costCentre: 'Test', - department: 'Test', - establishmentNumber: 123456, - }, - { - billing: { - exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], +beforeEach(() => { + method = buckarooClientTest.method('afterpaydigiaccept'); + payload = createBasePayload( + { + addressesDiffer: true, + customerIPAddress: getIPAddress(), + shippingCosts: 0.5, + costCentre: 'Test', + department: 'Test', + establishmentNumber: 123456, }, - shipping: { - exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], - }, - articles: { - exclude: ['type', 'unitCode', 'vatCategory', 'vatPercentage'], - }, - } -); + { + billing: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], + }, + shipping: { + exclude: ['state', 'culture', 'gender', 'lastNamePrefix', 'placeOfBirth'], + }, + articles: { + exclude: ['type', 'unitCode', 'vatCategory', 'vatPercentage'], + }, + } + ); +}); describe('AfterPayDigiAccept methods', () => { test('Authorize', async () => { - return method - .authorize(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + const response = await method.authorize(payload).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('CancelAuthorize', async () => { - return method + const response = await method .cancelAuthorize( createRefundPayload({ originalTransactionKey: 'F1924C34B80D4CA6838F44D6A8A6516A', amountCredit: payload.amountDebit, }) ) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Capture', async () => { - return method + const response = await method .capture({ ...payload, originalTransactionKey: '4FFF55350BAF47F086F75CC693407823', }) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Pay', async () => { - return method - .pay(payload) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + const response = await method.pay(payload).request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Refund', async () => { - return method + const response = await method .refund( createRefundPayload({ originalTransactionKey: '5DA00BD4ED4B4AE8B6C0092E138D959B', amountCredit: payload.amountDebit, }) ) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('Specification', async () => { - return method - .specification(RequestTypes.Transaction) - .request() - .then((data) => { - console.log(data); - expect(data.httpResponse.status).toEqual(200); - }); + const response = await method.specification(RequestTypes.Transaction).request(); + expect(response.httpResponse.status).toEqual(200); }); }); diff --git a/tests/PaymentMethods/Alipay.test.ts b/tests/PaymentMethods/Alipay.test.ts index f233f6e..5f2083f 100644 --- a/tests/PaymentMethods/Alipay.test.ts +++ b/tests/PaymentMethods/Alipay.test.ts @@ -1,31 +1,31 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { IRefundRequest } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import { createRefundPayload } from '../Payloads'; +let method: PaymentMethodInstance<'alipay'>; + +beforeEach(() => { + method = buckarooClientTest.method('alipay'); +}); + describe('Alipay methods', () => { test('Pay Simple Payload', async () => { - return buckarooClientTest - .method('alipay') + const response = await method .pay({ amountDebit: 100, useMobileView: false, }) - .request() - .then((data) => { - expect(data.isPendingProcessing()).toBeTruthy(); - }); + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); }); test('Refund', async () => { - return buckarooClientTest - .method('alipay') + const response = await method .refund( createRefundPayload({ originalTransactionKey: '6CE35062C16C4F47A49314D533E9F7A3', }) ) - .request() - .then((data) => { - expect(data.isSuccess()).toBeTruthy(); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 3c9aea7..4688d47 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -1,8 +1,8 @@ -import { IRefundRequest, uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { createRefundPayload } from '../Payloads'; -let method = buckarooClientTest.method('bancontactmrcash'); +let method: PaymentMethodInstance<'bancontactmrcash'>; let transactionKey: string; beforeEach(() => { diff --git a/tests/PaymentMethods/BankTransfer.test.ts b/tests/PaymentMethods/BankTransfer.test.ts index dc58990..2f6ad8f 100644 --- a/tests/PaymentMethods/BankTransfer.test.ts +++ b/tests/PaymentMethods/BankTransfer.test.ts @@ -1,8 +1,8 @@ -import { Gender, IRefundRequest } from '../../src'; +import { Gender, IRefundRequest, PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { createRefundPayload } from '../Payloads'; -let method = buckarooClientTest.method('transfer'); +let method: PaymentMethodInstance<'transfer'>; beforeEach(() => { method = buckarooClientTest.method('transfer'); diff --git a/tests/PaymentMethods/Belfius.test.ts b/tests/PaymentMethods/Belfius.test.ts index 21845bf..343f863 100644 --- a/tests/PaymentMethods/Belfius.test.ts +++ b/tests/PaymentMethods/Belfius.test.ts @@ -1,8 +1,8 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { IRefundRequest } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import { createRefundPayload } from '../Payloads'; -let method = buckarooClientTest.method('belfius'); +let method: PaymentMethodInstance<'belfius'>; beforeEach(() => { method = buckarooClientTest.method('belfius'); diff --git a/tests/PaymentMethods/Billink.test.ts b/tests/PaymentMethods/Billink.test.ts index 24bedac..2038bb7 100644 --- a/tests/PaymentMethods/Billink.test.ts +++ b/tests/PaymentMethods/Billink.test.ts @@ -1,12 +1,12 @@ import { IPay } from '../../src/PaymentMethods/Billink/Models/Pay'; import buckarooClientTest from '../BuckarooClient.test'; -import { IRequest, RecipientCategory, uniqid } from '../../src'; +import { PaymentMethodInstance } from '../../src'; import { createBasePayload, createRefundPayload } from '../Payloads'; import { IRefund } from '../../src/PaymentMethods/Billink/Models/Refund'; let payTransactionKey: string; let authorizeTransactionKey: string; -let method = buckarooClientTest.method('billink'); +let method: PaymentMethodInstance<'billink'>; let payload: IPay; beforeEach(() => { @@ -68,17 +68,10 @@ describe('Billink methods', () => { expect(response.isSuccess()).toBeTruthy(); }); test('Capture', async () => { - // const authResponse = await method.authorize(payload).request(); - // expect(authResponse.isSuccess()).toBeTruthy(); - // let key = authResponse.getTransactionKey(); - // expect(key).toBeDefined(); - - // new Promise((resolve) => setTimeout(resolve, 6000)); - const response = await method .capture({ ...payload, - originalTransactionKey: '1234', + originalTransactionKey: '4DAEE00C7C03475E87FDA2DB3674992F', }) .request(); expect(response.isSuccess()).toBeTruthy(); diff --git a/tests/PaymentMethods/Blik.test.ts b/tests/PaymentMethods/Blik.test.ts index 5643db3..261677d 100644 --- a/tests/PaymentMethods/Blik.test.ts +++ b/tests/PaymentMethods/Blik.test.ts @@ -1,8 +1,8 @@ -import { IRefundRequest } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import buckarooClientTest from '../BuckarooClient.test'; import { createRefundPayload } from '../Payloads'; -let method = buckarooClientTest.method('blik'); +let method: PaymentMethodInstance<'blik'>; beforeEach(() => { method = buckarooClientTest.method('blik'); @@ -13,7 +13,7 @@ describe('Testing Blik methods', () => { const response = await method .pay({ currency: 'PLN', - amountDebit: 10.0, + amountDebit: 100.0, invoice: 'Blik Test Plugin Example', description: 'Blik Test Plugin Example', email: 'test@buckaroo.nl', @@ -21,17 +21,16 @@ describe('Testing Blik methods', () => { .request(); expect(response.isPendingProcessing()).toBeTruthy(); }); - //unexpected error in pay redirect link - // test('Refund', async () => { - // const response = await method - // .refund( - // createRefundPayload({ - // originalTransactionKey: 'DA18F7031E3547E898B68773E372ACB4', - // currency: 'PLN', - // }) - // ) - // .request(); - // expect(response.isSuccess()).toBeTruthy(); - // }); + test('Refund', async () => { + const response = await method + .refund( + createRefundPayload({ + originalTransactionKey: 'DA18F7031E3547E898B68773E372ACB4', + currency: 'PLN', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); + }); }); diff --git a/tests/PaymentMethods/BuckarooVoucher.test.ts b/tests/PaymentMethods/BuckarooVoucher.test.ts index 679abdf..c5744b0 100644 --- a/tests/PaymentMethods/BuckarooVoucher.test.ts +++ b/tests/PaymentMethods/BuckarooVoucher.test.ts @@ -1,13 +1,11 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { IRefundRequest } from '../../src'; +import { IRefundRequest, PaymentMethodInstance } from '../../src'; import { createRefundPayload } from '../Payloads'; -let method = buckarooClientTest.method('buckaroovoucher'); +let method: PaymentMethodInstance<'buckaroovoucher'>; + let voucherCode: string; let transactionKey: string; -const today = new Date(); -const oneMonthFromNow = new Date(); -oneMonthFromNow.setMonth(today.getMonth() + 1); const formatDate = (date: Date) => date.toISOString().split('T')[0]; @@ -17,6 +15,10 @@ beforeEach(() => { describe('testing methods', () => { test('CreateApplication', async () => { + const today = new Date(); + const oneMonthFromNow = new Date(); + oneMonthFromNow.setMonth(today.getMonth() + 1); + const response = await method .create({ creationBalance: 12, @@ -31,6 +33,10 @@ describe('testing methods', () => { voucherCode = String(response.getServices()?.[0]?.parameters.find((p) => p.name === 'VoucherCode')?.value); }); test('GetBalance', async () => { + if (!voucherCode) { + throw new Error('voucherCode is not set. Ensure CreateApplication test has run successfully.'); + } + return method .getBalance({ voucherCode: voucherCode, @@ -41,7 +47,9 @@ describe('testing methods', () => { }); }); test('Pay', async () => { - expect(voucherCode).toBeDefined(); + if (!voucherCode) { + throw new Error('voucherCode is not set. Ensure CreateApplication test has run successfully.'); + } const response = await method .pay({ @@ -65,6 +73,9 @@ describe('testing methods', () => { expect(response.isSuccess()).toBeTruthy(); }); test('DeactivateVoucher', async () => { + if (!voucherCode) { + throw new Error('voucherCode is not set. Ensure CreateApplication test has run successfully.'); + } const response = await method .deactivate({ voucherCode: voucherCode, diff --git a/tests/PaymentMethods/BuckarooWallet.test.ts b/tests/PaymentMethods/BuckarooWallet.test.ts index 9bd21e8..9bb0dc6 100644 --- a/tests/PaymentMethods/BuckarooWallet.test.ts +++ b/tests/PaymentMethods/BuckarooWallet.test.ts @@ -1,5 +1,6 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { PaymentMethodInstance, uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { getServiceParameter, createRefundPayload } from '../Payloads'; let method: PaymentMethodInstance<'BuckarooWalletCollecting'>; @@ -12,13 +13,6 @@ beforeEach(() => { method = buckarooClientTest.method('BuckarooWalletCollecting'); }); -const getServiceParameter = (response: any, name: string): string => { - const param = (response.getServices()?.[0]?.parameters as { name: string; value: any }[] | undefined)?.find( - (p) => p.name === name - ); - return String(param?.value ?? ''); -}; - const payload = { walletId: uniqid(), currency: 'EUR', @@ -141,14 +135,13 @@ describe('BuckarooWallet methods', () => { test('Refund', async () => { const response = await method - .refund({ - invoice: uniqid(), - amountCredit: 0.01, - originalTransactionKey: transactionKey, - }) + .refund( + createRefundPayload({ + originalTransactionKey: transactionKey, + }) + ) .request(); - console.log(response.getStatusCode()); expect(response.isSuccess()).toBeTruthy(); - }, 10000); + }); }); diff --git a/tests/PaymentMethods/ClickToPay.test.ts b/tests/PaymentMethods/ClickToPay.test.ts index 14d21cd..61db0f4 100644 --- a/tests/PaymentMethods/ClickToPay.test.ts +++ b/tests/PaymentMethods/ClickToPay.test.ts @@ -3,14 +3,13 @@ import buckarooClientTest from '../BuckarooClient.test'; const method = buckarooClientTest.method('ClickToPay'); describe('Testing ClickToPay methods', () => { test('Pay', async () => { - return method + const response = await method .pay({ amountDebit: 0.01, continueOnIncomplete: true, }) - .request() - .then((response) => { - expect(response.isWaitingOnUserInput()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); }); + diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index 6110c76..e3e9b54 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -1,7 +1,12 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { ServiceCode, uniqid } from '../../src'; +import { PaymentMethodInstance, ServiceCode, uniqid } from '../../src'; + +let method: PaymentMethodInstance<'emandate'>; + +beforeEach(() => { + method = buckarooClientTest.method('emandate'); +}); -const method = buckarooClientTest.method('emandate'); describe('Testing Emandates methods', () => { test('GetIssuerList', async () => { const response = await method.issuerList().request(); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index 8daf5a6..47c1ad5 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -30,7 +30,7 @@ describe('testing Ideal methods', () => { }) ) .request(); - expect(response.isSuccess).toBeTruthy(); + expect(response.isSuccess()).toBeTruthy(); }); test('InstantRefund', async () => { const response = await method @@ -40,7 +40,7 @@ describe('testing Ideal methods', () => { }) ) .request(); - expect(response.isSuccess).toBeTruthy(); + expect(response.isSuccess()).toBeTruthy(); }); test('PayFastCheckout', async () => { const response = await method diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index ffbc5e1..f8addaa 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -42,11 +42,11 @@ describe('Testing capayable methods', () => { const response = await method.pay(payload).request(); expect(response.isSuccess()).toBeTruthy(); }); - test.only('PayInInstallments', async () => { + test('PayInInstallments', async () => { const response = await method.payInInstallments(payload).request(); expect(response.isPendingProcessing()).toBeTruthy(); }); - test.only('Refund', async () => { + test('Refund', async () => { const response = await method .refund( createRefundPayload({ diff --git a/tests/PaymentMethods/KlarnaKp.test.ts b/tests/PaymentMethods/KlarnaKp.test.ts index 1c12c0f..4671726 100644 --- a/tests/PaymentMethods/KlarnaKp.test.ts +++ b/tests/PaymentMethods/KlarnaKp.test.ts @@ -19,7 +19,7 @@ describe('KlarnaKp', () => { .request(); expect(response.isSuccess()).toBeTruthy(); }); - test.only('Reserve', async () => { + test('Reserve', async () => { const response = await method .reserve( createBasePayload( diff --git a/tests/PaymentMethods/Marketplaces.test.ts b/tests/PaymentMethods/Marketplaces.test.ts index a6b2643..28d782a 100644 --- a/tests/PaymentMethods/Marketplaces.test.ts +++ b/tests/PaymentMethods/Marketplaces.test.ts @@ -1,82 +1,84 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { IRefundRequest, PaymentMethodInstance, uniqid } from '../../src'; +import { createRefundPayload } from '../Payloads'; -const marketplaces = buckarooClientTest.method('marketplaces'); -const ideal = buckarooClientTest.method('ideal'); +let marketplaces: PaymentMethodInstance<'marketplaces'>; +let ideal: PaymentMethodInstance<'ideal'>; + +beforeEach(() => { + marketplaces = buckarooClientTest.method('marketplaces'); + ideal = buckarooClientTest.method('ideal'); +}); describe('Testing Marketplaces methods', () => { test('Split', async () => { - const marketplacesResponse = marketplaces.split({ + const marketplacesResponse = await marketplaces.split({ description: 'INV0001', - daysUntilTransfer: 2, + daysUntilTransfer: 5, marketplace: { amount: 10, - description: '', + description: 'INV0001 Commission Marketplace', }, sellers: [ { - accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', + accountId: '789C60F316D24B088ACD471', amount: 50, - description: '', + description: 'INV001 Payout Make-Up Products BV', }, { - accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', - amount: 45, - description: '', + accountId: '369C60F316D24B088ACD238', + amount: 35, + description: 'INV0001 Payout Beauty Products BV', }, ], }); - return ideal + const response = await ideal .combine(marketplacesResponse.data) .pay({ + invoice: uniqid(), issuer: 'ABNANL2A', - amountDebit: 100, + amountDebit: 95, }) - .request() - .then((response) => { - expect(response.isValidationFailure()).toBeTruthy(); - }); + .request(); + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); - test('transfer', async () => { - return marketplaces + test.only('transfer', async () => { + const response = await marketplaces .transfer({ - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + originalTransactionKey: 'DD58418EBE124DEB9E887EC059C729D5', marketplace: { amount: 10, description: 'INV0001 Commission Marketplace', }, sellers: [ { - accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', - amount: 50, + accountId: '789C60F316D24B088ACD471', + amount: 10, description: 'INV001 Payout Make-Up Products BV', }, ], }) - .request() - .then((response) => { - expect(response.isValidationFailure()).toBeTruthy(); - }); + .request(); + + expect(response.isSuccess()).toBeTruthy(); }); test('refundSupplementary', async () => { - const marketplacesResponse = marketplaces.refundSupplementary({ + const marketplacesResponse = await marketplaces.refundSupplementary({ sellers: [ { - accountId: 'XXXXXXXXXXXXXXXXXXXXXXXX', + accountId: '789C60F316D24B088ACD471', description: 'INV001 Payout Make-Up Products BV', }, ], }); - return ideal + const response = await ideal .combine(marketplacesResponse.data) - .refund({ - invoice: uniqid(), - originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', - amountCredit: 0.01, - }) - .request() - .then((response) => { - expect(response.isValidationFailure()).toBeTruthy(); - }); + .refund( + createRefundPayload({ + originalTransactionKey: 'E933CC3B4CF9494294538935D297A03F', + }) + ) + .request(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Payconiq.test.ts b/tests/PaymentMethods/Payconiq.test.ts index 9467a19..fa63eed 100644 --- a/tests/PaymentMethods/Payconiq.test.ts +++ b/tests/PaymentMethods/Payconiq.test.ts @@ -26,7 +26,7 @@ describe('Payconiq', () => { }) ) .request(); - expect(response.isSuccess).toBeTruthy(); + expect(response.isSuccess()).toBeTruthy(); }); test('InstantRefund', async () => { const response = await method @@ -36,6 +36,6 @@ describe('Payconiq', () => { }) ) .request(); - expect(response.isSuccess).toBeTruthy(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/PaymentInitiation.test.ts b/tests/PaymentMethods/PaymentInitiation.test.ts index 13190df..d851866 100644 --- a/tests/PaymentMethods/PaymentInitiation.test.ts +++ b/tests/PaymentMethods/PaymentInitiation.test.ts @@ -34,6 +34,6 @@ describe('PaymentInitiation methods', () => { }) ) .request(); - expect(response.isSuccess).toBeTruthy(); + expect(response.isSuccess()).toBeTruthy(); }); }); diff --git a/tests/PaymentMethods/Thunes.test.ts b/tests/PaymentMethods/Thunes.test.ts index d3dc519..f11f049 100644 --- a/tests/PaymentMethods/Thunes.test.ts +++ b/tests/PaymentMethods/Thunes.test.ts @@ -1,13 +1,18 @@ import buckarooClientTest from '../BuckarooClient.test'; -import { uniqid } from '../../src'; +import { PaymentMethodInstance, uniqid } from '../../src'; -const method = buckarooClientTest.method('thunes'); +let method: PaymentMethodInstance<'thunes'>; +beforeEach(() => { + method = buckarooClientTest.method('thunes'); +}); + +// 'thunes' is not a valid service name. describe('Thunes methods', () => { - test('authorize', async () => { - return method + test.only('authorize', async () => { + const response = await method .authorize({ - amountDebit: 100, + amountDebit: 10.0, order: uniqid(), invoice: uniqid(), name: 'monizzeecovoucher', @@ -24,33 +29,23 @@ describe('Thunes methods', () => { }, ], }) - .request() - .then((res) => { - expect(res.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('capture', async () => { - return method + const response = await method .capture({ amountDebit: 100, originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((res) => { - expect(res.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('getStatus', async () => { - return method + const response = await method .getStatus({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((res) => { - expect(res.httpResponse.status).toEqual(200); - }); + .request(); + expect(response.isSuccess()).toBeTruthy(); }); test('cancel', async () => { - return method - .cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }) - .request() - .then((res) => { - expect(res.httpResponse.status).toEqual(200); - }); + const response = await method.cancel({ originalTransactionKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' }).request(); + expect(response.isSuccess()).toBeTruthy(); }); }); From ddd8d8379f76622ba1e808158f8a33a6a5ab598f Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Tue, 29 Jul 2025 14:02:44 +0200 Subject: [PATCH 4/6] Fix CancelMandate --- tests/PaymentMethods/Emandate.test.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/PaymentMethods/Emandate.test.ts b/tests/PaymentMethods/Emandate.test.ts index e3e9b54..64fcd60 100644 --- a/tests/PaymentMethods/Emandate.test.ts +++ b/tests/PaymentMethods/Emandate.test.ts @@ -29,28 +29,26 @@ describe('Testing Emandates methods', () => { }); test('GetStatus', async () => { - const response = await method.status({ mandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8' }).request(); + const response = await method.status({ mandateId: '1DC1803BA695F0747AD819C62A557BC6149' }).request(); expect(response.isSuccess()).toBeTruthy(); }); test('ModifyMandate', async () => { const response = await method .modifyMandate({ - originalMandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8', + originalMandateId: '1DC1803BA695F0747AD819C62A557BC6149', continueOnIncomplete: true, }) .request(); expect(response.isWaitingOnUserInput()).toBeTruthy(); }); - // Unknown action 'CancelMandate' used on service 'emandate'. - // No valid subscription found for service 'emandateb2b'. - // test('CancelMandate', async () => { - // const response = await method - // .setServiceCode('emandateb2b' as ServiceCode) - // .cancelMandate({ - // mandateId: '1DC7F83B7B937864FB39966B0C08A7B86D8', - // purchaseId: '6383d3e86944a0', - // }) - // .request(); - // expect(response.isSuccess()).toBeTruthy(); - // }); + test.only('CancelMandate', async () => { + const response = await method + .setServiceCode('emandateb2b' as ServiceCode) + .cancelMandate({ + mandateId: '1DCFCAE452C96D7474BB28C57068134C02F', + purchaseId: '6383d3e86944a0', + }) + .request(); + expect(response.isPendingProcessing()).toBeTruthy(); + }); }); From 097bc71d5bfa803a9d2887f7ba1d147347880993 Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Tue, 29 Jul 2025 14:04:10 +0200 Subject: [PATCH 5/6] Run prettier --- tests/Models/index.ts | 2 +- tests/PaymentMethods/Bancontact.test.ts | 14 ++++++++------ tests/PaymentMethods/Blik.test.ts | 1 - tests/PaymentMethods/ClickToPay.test.ts | 1 - tests/PaymentMethods/EPS.test.ts | 1 - tests/PaymentMethods/Ideal.test.ts | 1 - tests/PaymentMethods/Multibanco.test.ts | 2 +- tests/PaymentMethods/NoService.test.ts | 3 +-- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/Models/index.ts b/tests/Models/index.ts index f3ba7c3..78b240f 100644 --- a/tests/Models/index.ts +++ b/tests/Models/index.ts @@ -45,7 +45,7 @@ export const TestAddress: IAddress = { export const TestArticle: IArticle = { description: 'Test Product', identifier: 'ABC123', - price: 40.10, + price: 40.1, quantity: 2, type: 'PhysicalArticle', unitCode: '123', diff --git a/tests/PaymentMethods/Bancontact.test.ts b/tests/PaymentMethods/Bancontact.test.ts index 4688d47..b0eb154 100644 --- a/tests/PaymentMethods/Bancontact.test.ts +++ b/tests/PaymentMethods/Bancontact.test.ts @@ -85,12 +85,14 @@ describe('Bancontact methods', () => { }); test('PayRecurring', async () => { - const response = await method.payRecurring({ - invoice: uniqid(), - amountDebit: 100, - originalTransactionKey: transactionKey, - }).request(); + const response = await method + .payRecurring({ + invoice: uniqid(), + amountDebit: 100, + originalTransactionKey: transactionKey, + }) + .request(); - expect(response.httpResponse.status).toEqual(200); + expect(response.httpResponse.status).toEqual(200); }); }); diff --git a/tests/PaymentMethods/Blik.test.ts b/tests/PaymentMethods/Blik.test.ts index 261677d..a396bcc 100644 --- a/tests/PaymentMethods/Blik.test.ts +++ b/tests/PaymentMethods/Blik.test.ts @@ -33,4 +33,3 @@ describe('Testing Blik methods', () => { expect(response.isSuccess()).toBeTruthy(); }); }); - diff --git a/tests/PaymentMethods/ClickToPay.test.ts b/tests/PaymentMethods/ClickToPay.test.ts index 61db0f4..6442940 100644 --- a/tests/PaymentMethods/ClickToPay.test.ts +++ b/tests/PaymentMethods/ClickToPay.test.ts @@ -12,4 +12,3 @@ describe('Testing ClickToPay methods', () => { expect(response.isWaitingOnUserInput()).toBeTruthy(); }); }); - diff --git a/tests/PaymentMethods/EPS.test.ts b/tests/PaymentMethods/EPS.test.ts index eb7faa0..716ec3d 100644 --- a/tests/PaymentMethods/EPS.test.ts +++ b/tests/PaymentMethods/EPS.test.ts @@ -26,6 +26,5 @@ describe('Testing Eps methods', () => { }) .request(); expect(response.isSuccess()).toBeTruthy(); - }); }); diff --git a/tests/PaymentMethods/Ideal.test.ts b/tests/PaymentMethods/Ideal.test.ts index 47c1ad5..f72d39f 100644 --- a/tests/PaymentMethods/Ideal.test.ts +++ b/tests/PaymentMethods/Ideal.test.ts @@ -74,4 +74,3 @@ describe('testing Ideal methods', () => { expect(responseRemainderPay.isWaitingOnUserInput()).toBeTruthy(); }); }); - diff --git a/tests/PaymentMethods/Multibanco.test.ts b/tests/PaymentMethods/Multibanco.test.ts index df294d3..f6b8e13 100644 --- a/tests/PaymentMethods/Multibanco.test.ts +++ b/tests/PaymentMethods/Multibanco.test.ts @@ -12,7 +12,7 @@ describe('Multibanco methods', () => { test('Pay', async () => { const response = await method .pay({ - amountDebit: 100.30, + amountDebit: 100.3, }) .request(); expect(response.isPendingProcessing()).toBeTruthy(); diff --git a/tests/PaymentMethods/NoService.test.ts b/tests/PaymentMethods/NoService.test.ts index 3536849..46a04fb 100644 --- a/tests/PaymentMethods/NoService.test.ts +++ b/tests/PaymentMethods/NoService.test.ts @@ -14,7 +14,6 @@ describe('NoService methods', () => { continueOnIncomplete: true, }) .request(); - expect(response.isWaitingOnUserInput()).toBeTruthy(); - + expect(response.isWaitingOnUserInput()).toBeTruthy(); }); }); From 3eb1172a26f086ef42c6be243b4bdb32ef23b3aa Mon Sep 17 00:00:00 2001 From: Djellze Bllaca Date: Tue, 29 Jul 2025 14:24:46 +0200 Subject: [PATCH 6/6] Remove test for PAY since it's no longer available for Capayable --- tests/PaymentMethods/In3Old.test.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/PaymentMethods/In3Old.test.ts b/tests/PaymentMethods/In3Old.test.ts index f8addaa..4509be6 100644 --- a/tests/PaymentMethods/In3Old.test.ts +++ b/tests/PaymentMethods/In3Old.test.ts @@ -37,11 +37,6 @@ beforeEach(() => { }); describe('Testing capayable methods', () => { - // "Action Pay is no longer available for Capayable" - test('Pay', async () => { - const response = await method.pay(payload).request(); - expect(response.isSuccess()).toBeTruthy(); - }); test('PayInInstallments', async () => { const response = await method.payInInstallments(payload).request(); expect(response.isPendingProcessing()).toBeTruthy();