- 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)
108 lines
3.9 KiB
JavaScript
108 lines
3.9 KiB
JavaScript
export function createPain001Message(transaction, version = '001.09') {
|
|
const messageId = `PAIN${Date.now()}`;
|
|
const now = new Date();
|
|
const groupHeader = {
|
|
messageIdentification: messageId,
|
|
creationDateTime: now,
|
|
numberOfTransactions: 1,
|
|
controlSum: transaction.amount,
|
|
initiatingParty: {
|
|
name: 'ESTRBRRJ',
|
|
postalAddress: {
|
|
country: 'BR',
|
|
},
|
|
},
|
|
};
|
|
const paymentInformation = {
|
|
paymentInformationIdentification: messageId,
|
|
paymentMethod: 'TRF',
|
|
requestedExecutionDate: transaction.createdAt || now,
|
|
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 || '',
|
|
},
|
|
creditTransferTransactionInformation: [
|
|
{
|
|
paymentIdentification: {
|
|
endToEndId: transaction.id,
|
|
instructionId: transaction.swiftReference,
|
|
},
|
|
amount: {
|
|
currency: transaction.currency,
|
|
value: transaction.amount,
|
|
},
|
|
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: 'pain.001',
|
|
version: version,
|
|
creationDateTime: now,
|
|
groupHeader,
|
|
paymentInformation: [paymentInformation],
|
|
customerCreditTransferInitiation: {
|
|
groupHeader,
|
|
paymentInformation: [paymentInformation],
|
|
},
|
|
};
|
|
}
|
|
export function validatePain001Message(message) {
|
|
const errors = [];
|
|
if (message.messageType !== 'pain.001') {
|
|
errors.push('Message type must be pain.001');
|
|
}
|
|
if (!message.customerCreditTransferInitiation) {
|
|
errors.push('Customer credit transfer initiation is required');
|
|
}
|
|
else {
|
|
if (!message.customerCreditTransferInitiation.groupHeader) {
|
|
errors.push('Group header is required');
|
|
}
|
|
if (!message.customerCreditTransferInitiation.paymentInformation ||
|
|
message.customerCreditTransferInitiation.paymentInformation.length === 0) {
|
|
errors.push('At least one payment information is required');
|
|
}
|
|
}
|
|
return {
|
|
valid: errors.length === 0,
|
|
errors,
|
|
};
|
|
}
|
|
//# sourceMappingURL=pain001.js.map
|