Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentMethods/BuckarooWallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions src/PaymentMethods/GiftCard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/BuckarooClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
63 changes: 32 additions & 31 deletions tests/Models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.1,
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,
Expand All @@ -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();
162 changes: 162 additions & 0 deletions tests/Payloads/index.ts
Original file line number Diff line number Diff line change
@@ -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<T extends object>(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<IArticle>[] = [], 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<T extends IRequest>(
overrides: Partial<T> = {},
include: {
billing?: boolean | { overrides?: any; exclude?: string[] };
shipping?: boolean | { overrides?: any; exclude?: string[] };
articles?: boolean | { overrides?: Partial<IArticle>[]; exclude?: string[] };
} = {},
exclude: string[] = []
): T {
const basePayload: Partial<IRequest> = {
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<T extends object>(overrides: Partial<T> = {}, exclude: string[] = []): T {
const refundPayload: Partial<IRequest> = {
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];
Loading