Пример #1
0
        private void AddNewCreditTransferTransactionInformation(PaymentInstructionInformation3CH pmtInf, CreditTransferTransactionInformation10CH cdtTrfTxInf)
        {
            var pmtInfCdtTrfTxInf = pmtInf.CdtTrfTxInf;

            Array.Resize(ref pmtInfCdtTrfTxInf, pmtInfCdtTrfTxInf.Length + 1);
            pmtInfCdtTrfTxInf[pmtInfCdtTrfTxInf.Length - 1] = cdtTrfTxInf;
            pmtInf.CdtTrfTxInf = pmtInfCdtTrfTxInf;
        }
Пример #2
0
        public PaymentInstructionInformation3CH AddPaymentInfo(DateTime requiredExecutionDate)
        {
            if (requiredExecutionDate.Date < DateTime.Now.Date)
            {
                throw new ArgumentException("ExecutionDate cannot be in the past");
            }

            // Level B
            PaymentInstructionInformation3CH pmtInf = new PaymentInstructionInformation3CH();

            pmtInf.PmtInfId  = $"PmtInfId-{pmtInfList.Count + 1}"; // Index 2.1
            pmtInf.PmtMtd    = PaymentMethod3Code.TRA;             // Index 2.2
            pmtInf.BtchBookg = true;                               // Index 2.3

            pmtInf.ReqdExctnDt = requiredExecutionDate;            // Index 2.17
            pmtInf.Dbtr        = dbtr;

            dbtr.Nm = initialization.SenderPartyName;

            pmtInf.DbtrAcct = dbtrAcct;
            dbtrAcct.Id     = dbtrAcctId;
            dbtrAcctId.Item = initialization.SenderIban; // Index 2.20 / Id / IBAN  Bezugs-Konto

            pmtInf.DbtrAgt = dbtrAgt;

            // Add BIC only if is set to guarantee the compatibility to the old version
            if (!string.IsNullOrEmpty(initialization.SenderBic)) // Index 2.21
            {
                finInstnIdDbtr.BIC = initialization.SenderBic;
            }

            dbtrAgt.FinInstnId = finInstnIdDbtr;


            // Level C
            pmtInf.CdtTrfTxInf = new CreditTransferTransactionInformation10CH[0]; // Index 2.27

            pmtInfList.Add(pmtInf);

            return(pmtInf);
        }
Пример #3
0
        /// <summary>
        /// Adds a new transaction to the document
        /// </summary>
        /// <param name="receiver">Object with all the required information about the receiver of the new transaction</param>
        /// <param name="transaction">Object with all the required information about the transaction itself</param>
        public void AddTransaction(PaymentInstructionInformation3CH pmtInf, Receiver receiver, TransactionBase transaction)
        {
            CreditTransferTransactionInformation10CH cdtTrfTxInf = new CreditTransferTransactionInformation10CH(); // Index 2.27

            PaymentIdentification1 pmtId = new PaymentIdentification1();                                           // Index 2.28

            cdtTrfTxInf.PmtId = pmtId;
            pmtId.InstrId     = "1-" + pmtInf.CdtTrfTxInf.Length;    // Index 2.29
            pmtId.EndToEndId  = transaction.ReferenceIdentification; // Index 2.30

            AmountType3Choice amt = new AmountType3Choice();         // Index 2.42

            cdtTrfTxInf.Amt = amt;

            ActiveOrHistoricCurrencyAndAmount currencyAndAmount = new ActiveOrHistoricCurrencyAndAmount(); // Index 2.43

            amt.Item = currencyAndAmount;
            currencyAndAmount.Ccy   = transaction.CurrencyCode;
            currencyAndAmount.Value = transaction.Amount;

            PartyIdentification32CH_Name cdtr = new PartyIdentification32CH_Name(); // Index 2.79

            cdtTrfTxInf.Cdtr = cdtr;

            cdtr.Nm = receiver.Name;                           // Index 2.79 / Name
            PostalAddress6CH pstlAdr = new PostalAddress6CH(); // Index 2.79 / Postal Address

            cdtr.PstlAdr = pstlAdr;


            pstlAdr.StrtNm = receiver.StreetName; // Index 2.79 / Street Name

            if (!string.IsNullOrWhiteSpace(receiver.StreetNumber))
            {
                pstlAdr.StrtNm = receiver.StreetName + " " + receiver.StreetNumber; // Index 2.79 / Building Number
            }

            pstlAdr.PstCd = receiver.Zip;                                // Index 2.79 / Post Code
            pstlAdr.TwnNm = receiver.City;                               // Index 2.79 / Town Name
            pstlAdr.Ctry  = receiver.CountryCode;                        // Index 2.79 / Country

            CashAccount16CH_Id cdtrAcct = new CashAccount16CH_Id();      // Index 2.80

            cdtrAcct.Id          = new AccountIdentification4ChoiceCH(); // Index 2.80 / Identification
            cdtTrfTxInf.CdtrAcct = cdtrAcct;

            if (transaction.GetType() == typeof(TransactionIBANandQRR))
            {
                TransactionIBANandQRR transactionIbaNandQrr = ((TransactionIBANandQRR)transaction);

                cdtrAcct.Id.Item = transactionIbaNandQrr.ReceiverIban; // Index 2.80 / Id / IBAN  Ziel-Konto

                if (!string.IsNullOrWhiteSpace(transactionIbaNandQrr.ReceiverBIC))
                {
                    BranchAndFinancialInstitutionIdentification4CH cdtrAgt = new BranchAndFinancialInstitutionIdentification4CH(); // Index 2.77
                    cdtTrfTxInf.CdtrAgt = cdtrAgt;

                    FinancialInstitutionIdentification7CH finInstnIdCdtr = new FinancialInstitutionIdentification7CH(); // Index 2.77 / Financial Institution Identification
                    cdtrAgt.FinInstnId = finInstnIdCdtr;
                    finInstnIdCdtr.BIC = transactionIbaNandQrr.ReceiverBIC;                                             // Index 2.21
                }

                // QRR
                if (!string.IsNullOrWhiteSpace(transactionIbaNandQrr.QRReferenceNumber))
                {
                    var rmtInf = new RemittanceInformation5CH(); // Index 2.126
                    cdtTrfTxInf.RmtInf = rmtInf;
                    rmtInf.Strd        = new StructuredRemittanceInformation7
                    {
                        CdtrRefInf = new CreditorReferenceInformation2
                        {
                            Ref = transactionIbaNandQrr.QRReferenceNumber,
                            Tp  = new CreditorReferenceType2
                            {
                                CdOrPrtry = new CreditorReferenceType1Choice
                                {
                                    Item = "QRR"
                                }
                            }
                        }
                    };
                }
            }
            else if (transaction.GetType() == typeof(TransactionESR))
            {
                TransactionESR transactionESR = ((TransactionESR)transaction);

                PaymentTypeInformation19CH pmtTpInf = new PaymentTypeInformation19CH(); // Index 2.31
                cdtTrfTxInf.PmtTpInf = pmtTpInf;
                cdtTrfTxInf.PmtTpInf = new PaymentTypeInformation19CH                   // Index 2.31
                {
                    LclInstrm = new LocalInstrument2Choice                              // Index 2.36
                    {
                        ItemElementName = ItemChoiceType5.Prtry,                        // Index 2.38
                        Item            = transactionESR.PaymentType
                    }
                };

                cdtrAcct.Id.Item = new GenericAccountIdentification1CH() // Index 2.80
                {
                    Id = transactionESR.ReceiverAccount
                };

                var rmtInf = new RemittanceInformation5CH(); // Index 2.98
                cdtTrfTxInf.RmtInf = rmtInf;
                rmtInf.Strd        = new StructuredRemittanceInformation7
                {
                    CdtrRefInf = new CreditorReferenceInformation2
                    {
                        Ref = transactionESR.ESRReferenceNumber
                    }
                };
            }
            else if (transaction.GetType() == typeof(TransactionES))
            {
                TransactionES transactionES = ((TransactionES)transaction);

                PaymentTypeInformation19CH pmtTpInf = new PaymentTypeInformation19CH(); // Index 2.31
                cdtTrfTxInf.PmtTpInf = pmtTpInf;
                cdtTrfTxInf.PmtTpInf = new PaymentTypeInformation19CH                   // Index 2.31
                {
                    LclInstrm = new LocalInstrument2Choice                              // Index 2.36
                    {
                        ItemElementName = ItemChoiceType5.Prtry,                        // Index 2.38
                        Item            = transactionES.PaymentType
                    }
                };

                cdtrAcct.Id.Item = new GenericAccountIdentification1CH() // Index 2.80
                {
                    Id = transactionES.ReceiverAccount
                };
            }

            AddNewCreditTransferTransactionInformation(pmtInf, cdtTrfTxInf);
        }