Development of a module for creating financial messages for AWS KBR / AWS KBR-SPFS

Hello, Habr!



This is my first small article about a small development of a financial program, please do not judge strictly.



Since not all state-owned companies have implemented the exchange of financial messages through the financial messaging system of the Central Bank of the Russian Federation, I wanted to disassemble and create a small working prototype myself.



The Bank of Russia Financial Messaging System (SPFS) is an alternative channel for the transmission of electronic messages on financial transactions. SPFS guarantees uninterrupted transmission of financial messages within the country.



Credit institutions and their clients - legal entities are connected to the SPFS as soon as they are technically ready and contractual relations with the Bank of Russia are established. Procedural aspects are determined by a separate normative act of the Bank of Russia.



To develop a network interaction scheme, you must be guided by the following documents:



  1. CBRF.61209-049301 "Information Security Guidelines";
  2. CBRF.61209-049201 “Automated workstation for a client of the Bank of Russia. User's manual";
  3. CBRF.61209-049202 “Automated workstation for a Bank of Russia client. Administrator's Guide ";
  4. VAMB.00106-019301 "SCAD" Signature "version 5." Signature-client "version 5. Information security administrator's guide".


To send financial messages to the SPFS circuit, there is a software AWK KBR / AWP KBR-N / AWP KBR SPFS.



AWP KBR / AWP KBR SPFS is a specialized software for employees of banks or large government organizations for preparing and sending financial messages to the payment circuit of the central bank. This software allows you to electronically sign financial documents, check and decrypt electronic messages received from the Bank of Russia. In its work AWP KBR / AWP KBR SPFS uses the format of financial documents of UEFBS. The types of messages are both payment messages and informational (creating a test message, requesting technical information, etc.).



For processing, the e-mail must be converted to UEFBS on the AWS KBR or converted to the client's ABS and sent to the AWS KBR.



image



When working in manual mode, e-mails are placed in the AWS KBD directory c: // uarm3 / exg / cli. The built-in component "Incoming control" analyzes the incoming ES. If the message has successfully passed the validation, then it goes to the "entered" tab, if the message has not been validated, then it goes to the "Rejected" tab. When working in automatic mode, the message goes to the output folder.



image



As part of the development, the following functionality was implemented:



  1. creation of financial messages in the UEFBS ED101 format;
  2. creation of financial messages in the UEFBS ED501 format;
  3. creation of financial messages in SWIFT MT101 format;
  4. storing financial messages in MS SQL database;
  5. unloading of payment orders in pdf format;
  6. processing of received incoming messages;


To save payment orders, it is necessary to develop a configuration menu (select a server, database, username, password).



image



I will set the global database connection settings in the app.config file. Access to the global settings will occur through the ConfigurationManager and call the ReadSetting function, updating through the AddUpdateAppSettings function.



The message counter (ed501, ed101) during the operating day (current day) will also be set through the global settings:



add key="currentday" value="20200416"
add key="EDNo" value="2″ 
add key="MessageName» value="10836708462"
add key="MessageIDED501" value="2"
add key="MessageIDED501_full" value="10836708462_pain_MSG_20200416_00000002"


If the current operating day has changed, then the counter is reset and the first ES is assigned number 1. The



connection to the database will be carried out via a TCP connection and port 1433. To work with MS SQL, I will use Microsoft SQL Server Management studio 2018.



image



To display the created and received e-mails for the current day / all days, you need to create a display form (DataGrid).



image



Form 1 will be generated in the Form1.cs class. To save a payment order in a specialized format, it is necessary to develop global save settings. The save settings will be generated in the settings.cs class.



image



To create a payment order (form 0401060 in accordance with Appendix 2 of the Regulation of the Bank of Russia dated June 19, 2012 No. 383-P "On the rules for transferring funds" (as amended by Bank of Russia Instructions dated July 15, 2013 No. 3025-U, dated April 29, 2014 No. 3248-U, dated 05/19/2015 No. 3641-U, dated 06.11.2015 No. 3844-U, dated 05.07.2017 No. 4449-U and dated 11.10.2018 No. 4930-U)) it is necessary to develop a special user interface and a mechanism for automatic generation some fields.



The user interface of Form # 0401060 is shown below:



image



This form is the main functionality of the system, after creating a payment order, its details can be transferred to the database, generated a PDF document, sent to print, saved in the appropriate format (ed101, ed501, MT101). The form is generated in the Form2.cs class and using the pp.cs class to create a new instance of the CreatePP class, the field values ​​will be filled through the get and set access modifier. For each PP field, the corresponding name is P1-P110 with the public access modifier and the p1-110 variables with the private access modifier.



The code snippet is shown below:



private string p1;
private string p0;
private int p2;
private int p3;
private string p4;
private string p5;
public string P0
        {
            get { return p0; }
            set { p0 = value; }
        }
        public int P20
        {
            get { return p20; }
            set { p20 = value; }
        }
        public string Status
        {
            get { return status; }
            set { status = «»; }
        }
        public string P1
        {
           get { return p1; }
            set { p1 = « »; }
        }
       public string Date_pp()
        {
            DateTime dt = DateTime.Now;
            string curDate = dt.ToShortDateString();
            return curDate;
        }


If not all the fields were filled in during saving, the program will highlight the empty fields in red.



A snippet of code for checking the field:



if (textBox10.Text == «»)
{
textBox10.BackColor = Color.Fuchsia;
}


image



After calling the "create_pdf" function, a pdf document with filled fields will be generated.



image



In the "create_pdf" function, the field values ​​will be passed as parameters, using fields. SetField these values ​​will be inserted into the PDF document.



The code snippet is shown below:



public string Pdf(string p0, string p4, string p6, string p60, string p102, int p7, string p8, string p9, string p10, string p11, string p12, int p101, string p13, string p14, string p15, string p17, string p18, string p61, string p103, string p16, int p21, string p24, string p5, string p22, string p104, string p105, string p106, string p107, string p108, string p109, string p110)
        {  string pathsafe = settings.safepathpdf + p4 + «_» + p0 + «.pdf»;
            string pathsafetemplatefont = settings.safepath + «\\Template\\Tahoma.ttf»;
            BaseFont baseFont = BaseFont.CreateFont(pathsafetemplatefont, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            PdfReader template = new PdfReader(settings.safepathetemplate);
            PdfStamper stamper = new PdfStamper(template, new FileStream(pathsafe, FileMode.Create));
            AcroFields fields = stamper.AcroFields;
            fields.AddSubstitutionFont(baseFont);
            fields.SetField(«p4», p4);
            fields.SetField(«p3», p0);
            fields.SetField(«p6», p6);


Most of the fields are automated and do not require user input.



The amount spent on drink is automatically generated (according to the requirements of the Central Bank), the payer bank, payer, recipient, recipient bank is pulled up. TIN, KPP are put down by the name of the organization; by the name of the bank, BIK, correspondent account is put down.



image



Forming document ED101



image



Forming document ED501



image



We send the generated message through AWS CBD / AWP CBD SPFS to the payment circuit of the Central Bank of the Russian Federation.



After sending the ES ED101 / ED501, I received a response receipt from the Central Bank of the Russian Federation about the following status:



<?xml version=»1.0″ encoding=»utf-8″?><soapenv:Envelope xmlns:soapenv=»http://www.w3.org/2003/05/soap-envelope»><soapenv:Header><props:MessageInfo xmlns:props=»urn:cbr-ru:msg:props:v1.3″><props:To>uic:452500055555</props:To><props:From>uic:KBRGATE</props:From><props:MessageID>KBRGATE_guid:786df05a239943f3bc9eca41a6fc430a</props:MessageID><props:CorrelationMessageID>guid:786df05a239943f3bc9eca41a6fc430a</props:CorrelationMessageID><props:MessageType>3</props:MessageType><props:Priority>5</props:Priority><props:CreateTime>2019-08-06T07:46:04Z</props:CreateTime><props:SendTime>2019-08-06T07:46:04Z</props:SendTime></props:MessageInfo><props:AcknowledgementInfo xmlns:props=»urn:cbr-ru:msg:props:v1.3″><props:AcknowledgementType>2</props:AcknowledgementType><props:ResultCode>0000</props:ResultCode><props:ResultText>    :uic:777777700011.    :  : ED997_06104603.dat.    :   : uic:452500055555,   : uic:777777700011.   : 2019-08-06 07:46:04</props:ResultText>

</props:AcknowledgementInfo></soapenv:Header><soapenv:Body></soapenv:Body></soapenv:Envelope>


The fields have the following decryption:



CorrelationMessageID - the original message generated by the AWS KBR;

ResultCode - status code (000 - successful, 001 - unsuccessful),

ResultText - ES status itself (successfully received by TS, processed, executed).



Link to development https://businessarchitecture.ru/test-spfs/ .



All Articles