- Add missing pacs008.ts, pacs009.ts, pain001.ts files - Add missing config.ts, threshold.ts, documentation.ts files - Fix property access errors (orderingCustomerTaxId -> orderingCustomer.taxId) - Add contractActive property to FXContractCheckResult type - Fix undefined handling in validateBrazilianTaxId calls - Update web app tsconfig to exclude dist folders - Remove tsc from web build (Vite handles TypeScript)
119 lines
4.2 KiB
JavaScript
119 lines
4.2 KiB
JavaScript
export function createPacs008Message(transaction, version = '001.08') {
|
|
const messageId = `MSG${Date.now()}`;
|
|
const now = new Date();
|
|
const groupHeader = {
|
|
messageIdentification: messageId,
|
|
creationDateTime: now,
|
|
numberOfTransactions: 1,
|
|
controlSum: transaction.amount,
|
|
initiatingParty: {
|
|
name: 'ESTRBRRJ',
|
|
postalAddress: {
|
|
country: 'BR',
|
|
},
|
|
},
|
|
};
|
|
const creditTransferTransaction = {
|
|
paymentIdentification: {
|
|
endToEndId: transaction.id,
|
|
instructionId: transaction.swiftReference,
|
|
},
|
|
amount: {
|
|
currency: transaction.currency,
|
|
value: transaction.amount,
|
|
},
|
|
debtor: {
|
|
name: transaction.orderingCustomer.name,
|
|
postalAddress: {
|
|
streetName: transaction.orderingCustomer.address,
|
|
townName: transaction.orderingCustomer.city,
|
|
country: transaction.orderingCustomer.country,
|
|
},
|
|
identification: transaction.orderingCustomer.taxId
|
|
? {
|
|
privateIdentification: transaction.orderingCustomer.taxId,
|
|
}
|
|
: undefined,
|
|
},
|
|
debtorAccount: {
|
|
identification: transaction.orderingCustomer.accountNumber || '',
|
|
},
|
|
creditor: {
|
|
name: transaction.beneficiary.name,
|
|
postalAddress: {
|
|
streetName: transaction.beneficiary.address,
|
|
townName: transaction.beneficiary.city,
|
|
country: transaction.beneficiary.country,
|
|
},
|
|
identification: transaction.beneficiary.taxId
|
|
? {
|
|
privateIdentification: transaction.beneficiary.taxId,
|
|
}
|
|
: undefined,
|
|
},
|
|
creditorAccount: {
|
|
identification: transaction.beneficiary.accountNumber || '',
|
|
iban: transaction.beneficiary.iban,
|
|
currency: transaction.currency,
|
|
},
|
|
remittanceInformation: transaction.purposeOfPayment
|
|
? {
|
|
unstructured: transaction.purposeOfPayment,
|
|
}
|
|
: undefined,
|
|
purpose: transaction.purposeOfPayment,
|
|
};
|
|
return {
|
|
messageId,
|
|
messageType: 'pacs.008',
|
|
version: version,
|
|
creationDateTime: now,
|
|
groupHeader,
|
|
paymentInformation: [],
|
|
creditTransferTransaction: [creditTransferTransaction],
|
|
};
|
|
}
|
|
export function validatePacs008Message(message) {
|
|
const errors = [];
|
|
if (!message.messageId) {
|
|
errors.push('Message ID is required');
|
|
}
|
|
if (!message.groupHeader) {
|
|
errors.push('Group header is required');
|
|
}
|
|
else {
|
|
if (!message.groupHeader.messageIdentification) {
|
|
errors.push('Group header message identification is required');
|
|
}
|
|
if (!message.groupHeader.creationDateTime) {
|
|
errors.push('Group header creation date time is required');
|
|
}
|
|
}
|
|
if (!message.creditTransferTransaction || message.creditTransferTransaction.length === 0) {
|
|
errors.push('At least one credit transfer transaction is required');
|
|
}
|
|
else {
|
|
message.creditTransferTransaction.forEach((txn, index) => {
|
|
if (!txn.paymentIdentification?.endToEndId) {
|
|
errors.push(`Transaction ${index}: End-to-end ID is required`);
|
|
}
|
|
if (!txn.amount || !txn.amount.currency || !txn.amount.value) {
|
|
errors.push(`Transaction ${index}: Amount with currency and value is required`);
|
|
}
|
|
if (!txn.debtor?.name) {
|
|
errors.push(`Transaction ${index}: Debtor name is required`);
|
|
}
|
|
if (!txn.creditor?.name) {
|
|
errors.push(`Transaction ${index}: Creditor name is required`);
|
|
}
|
|
if (!txn.creditorAccount?.identification) {
|
|
errors.push(`Transaction ${index}: Creditor account identification is required`);
|
|
}
|
|
});
|
|
}
|
|
return {
|
|
valid: errors.length === 0,
|
|
errors,
|
|
};
|
|
}
|
|
//# sourceMappingURL=pacs008.js.map
|