/// <summary> /// Generate the XML structure /// </summary> /// <returns></returns> protected override XmlDocument GenerateXml() { CheckMandatoryData(); var xml = new XmlDocument(); xml.AppendChild(xml.CreateXmlDeclaration("1.0", Encoding.UTF8.BodyName, "yes")); var el = (XmlElement)xml.AppendChild(xml.CreateElement("Document")); el.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); el.SetAttribute("xmlns", "urn:iso:std:iso:20022:tech:xsd:" + SepaSchemaUtils.SepaSchemaToString(schema)); el.NewElement("CstmrCdtTrfInitn"); // Part 1: Group Header var grpHdr = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("GrpHdr"); grpHdr.NewElement("MsgId", MessageIdentification); grpHdr.NewElement("CreDtTm", StringUtils.FormatDateTime(CreationDate)); grpHdr.NewElement("NbOfTxs", numberOfTransactions); grpHdr.NewElement("CtrlSum", StringUtils.FormatAmount(headerControlSum)); if (!String.IsNullOrEmpty(InitiatingPartyName) || InitiatingPartyId != null) { var initgPty = grpHdr.NewElement("InitgPty"); if (!String.IsNullOrEmpty(InitiatingPartyName)) { initgPty.NewElement("Nm", InitiatingPartyName); } if (InitiatingPartyId != null) { initgPty. NewElement("Id").NewElement("OrgId"). NewElement("Othr").NewElement("Id", InitiatingPartyId); } } // Part 2: Payment Information var pmtInf = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("PmtInf"); pmtInf.NewElement("PmtInfId", PaymentInfoId ?? MessageIdentification); pmtInf.NewElement("PmtMtd", Constant.CreditTransfertPaymentMethod); pmtInf.NewElement("NbOfTxs", numberOfTransactions); pmtInf.NewElement("CtrlSum", StringUtils.FormatAmount(paymentControlSum)); if (IsInternational) { pmtInf.NewElement("PmtTpInf").NewElement("InstrPrty", "NORM"); } else { pmtInf.NewElement("PmtTpInf").NewElement("SvcLvl").NewElement("Cd", "SEPA"); } if (LocalInstrumentCode != null) { XmlUtils.GetFirstElement(pmtInf, "PmtTpInf").NewElement("LclInstr") .NewElement("Cd", LocalInstrumentCode); } if (CategoryPurposeCode != null) { XmlUtils.GetFirstElement(pmtInf, "PmtTpInf"). NewElement("CtgyPurp"). NewElement("Cd", CategoryPurposeCode); } pmtInf.NewElement("ReqdExctnDt", StringUtils.FormatDate(RequestedExecutionDate)); var dbtr = pmtInf.NewElement("Dbtr"); dbtr.NewElement("Nm", Debtor.Name); if (Debtor.Address != null) { XmlUtils.AddPostalAddressElements(dbtr, Debtor.Address); } if (InitiatingPartyId != null) { XmlUtils.GetFirstElement(pmtInf, "Dbtr"). NewElement("Id").NewElement("OrgId"). NewElement("Othr").NewElement("Id", InitiatingPartyId); } var dbtrAcct = pmtInf.NewElement("DbtrAcct"); var dbtrAcctId = dbtrAcct.NewElement("Id"); if (!String.IsNullOrEmpty(Debtor.Iban)) { dbtrAcctId.NewElement("IBAN", Debtor.Iban); } else if (!String.IsNullOrEmpty(Debtor.Other)) { dbtrAcctId.NewElement("Othr").NewElement("Id", Debtor.Other); } else { throw new Exception("Need either IBAN or Other>Id for DbtrAcct."); } dbtrAcct.NewElement("Ccy", DebtorAccountCurrency); var finInstnId = pmtInf.NewElement("DbtrAgt").NewElement("FinInstnId"); finInstnId.NewElement("BIC", Debtor.Bic); if (Debtor.AgentAddress != null) { XmlUtils.AddPostalAddressElements(finInstnId, Debtor.AgentAddress); } if (IsInternational) { pmtInf.NewElement("ChrgBr", SepaChargeBearerUtils.SepaChargeBearerToString(ChargeBearer)); } else { pmtInf.NewElement("ChrgBr", "SLEV"); } // Part 3: Credit Transfer Transaction Information foreach (var transfer in transactions) { GenerateTransaction(pmtInf, transfer); } return(xml); }
/// <summary> /// Generate the XML structure /// </summary> /// <returns></returns> protected override XmlDocument GenerateXml() { CheckMandatoryData(); var xml = new XmlDocument(); xml.AppendChild(xml.CreateXmlDeclaration("1.0", Encoding.UTF8.BodyName, "yes")); var el = (XmlElement)xml.AppendChild(xml.CreateElement("Document")); el.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); el.SetAttribute("xmlns", "urn:iso:std:iso:20022:tech:xsd:" + SepaSchemaUtils.SepaSchemaToString(schema)); el.NewElement("CstmrCdtTrfInitn"); // Part 1: Group Header var grpHdr = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("GrpHdr"); grpHdr.NewElement("MsgId", MessageIdentification); grpHdr.NewElement("CreDtTm", StringUtils.FormatDateTime(CreationDate)); grpHdr.NewElement("NbOfTxs", numberOfTransactions); grpHdr.NewElement("CtrlSum", StringUtils.FormatAmount(headerControlSum)); if (InitiatingParty != null) { var initgPty = grpHdr.NewElement("InitgPty"); if (!string.IsNullOrWhiteSpace(InitiatingParty.Name)) { initgPty.NewElement("Nm", InitiatingParty.Name); } if (InitiatingParty.Identification != null) { var othr = initgPty.NewElement("Id"). NewElement("OrgId"). NewElement("Othr"); othr.NewElement("Id", InitiatingParty.Identification.Id); othr.NewElement("Issr", InitiatingParty.Identification.Issuer); } } if (ForwardingAgent != null) { var fwdgAgt = grpHdr.NewElement("FwdgAgt"); if (ForwardingAgent.FinancialInstitutionId != null) { var finInstnId = fwdgAgt.NewElement("FinInstnId"); finInstnId.NewElement("BIC", ForwardingAgent.FinancialInstitutionId.BIC); finInstnId.NewElement("Nm", ForwardingAgent.FinancialInstitutionId.Name); } if (ForwardingAgent.BranchId != null) { fwdgAgt.NewElement("BrnchId") .NewElement("Id", ForwardingAgent.BranchId.Id); } } // Part 2: Payment Information var pmtInf = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("PmtInf"); pmtInf.NewElement("PmtInfId", PaymentInfoId ?? MessageIdentification); pmtInf.NewElement("PmtMtd", Constant.CreditTransfertPaymentMethod); if (BatchBooking.HasValue) { pmtInf.NewElement("BtchBookg", SepaBatchBookingUtils.SepaBatchBookingToString(BatchBooking.Value)); } pmtInf.NewElement("NbOfTxs", numberOfTransactions); pmtInf.NewElement("CtrlSum", StringUtils.FormatAmount(paymentControlSum)); var pmtTpInf = pmtInf.NewElement("PmtTpInf"); if (IsInternational) { pmtTpInf.NewElement("InstrPrty", "NORM"); } else { pmtTpInf.NewElement("SvcLvl").NewElement("Cd", "SEPA"); } if (LocalInstrument != null) { var lclInstr = pmtTpInf.NewElement("LclInstr"); if (!string.IsNullOrWhiteSpace(LocalInstrument.Code)) { lclInstr.NewElement("Cd", LocalInstrument.Code); } if (!string.IsNullOrWhiteSpace(LocalInstrument.Proprietary)) { lclInstr.NewElement("Prtry", LocalInstrument.Proprietary); } } if (CategoryPurpose != null) { var ctgyPurp = pmtTpInf.NewElement("CtgyPurp"); if (!string.IsNullOrWhiteSpace(CategoryPurpose.Code)) { ctgyPurp.NewElement("Cd", CategoryPurpose.Code); } if (!string.IsNullOrWhiteSpace(CategoryPurpose.Proprietary)) { ctgyPurp.NewElement("Prtry", CategoryPurpose.Proprietary); } } pmtInf.NewElement("ReqdExctnDt", StringUtils.FormatDate(RequestedExecutionDate)); var dbtr = pmtInf.NewElement("Dbtr"); dbtr.NewElement("Nm", Debtor.Name); if (Debtor.Identification != null && !string.IsNullOrWhiteSpace(Debtor.Identification.Id)) { dbtr.NewElement("Id"). NewElement("OrgId"). NewElement("Othr"). NewElement("Id", Debtor.Identification.Id); } var dbtrAcct = pmtInf.NewElement("DbtrAcct"); dbtrAcct.NewElement("Id").NewElement("IBAN", Debtor.Iban); dbtrAcct.NewElement("Ccy", DebtorAccountCurrency); var dbtrAgt = pmtInf.NewElement("DbtrAgt"); dbtrAgt.NewElement("FinInstnId").NewElement("BIC", Debtor.Bic); if (ChargeBearer.HasValue) { pmtInf.NewElement("ChrgBr", SepaChargeBearerUtils.SepaChargeBearerToString(ChargeBearer.Value)); } // Part 3: Credit Transfer Transaction Information foreach (var transfer in transactions) { GenerateTransaction(pmtInf, transfer); } return(xml); }
public void ShouldRetrieveStringFromChargeBearer() { Assert.AreEqual("CRED", SepaChargeBearerUtils.SepaChargeBearerToString(SepaChargeBearer.CRED)); Assert.AreEqual("DEBT", SepaChargeBearerUtils.SepaChargeBearerToString(SepaChargeBearer.DEBT)); Assert.AreEqual("SHAR", SepaChargeBearerUtils.SepaChargeBearerToString(SepaChargeBearer.SHAR)); }
/// <summary> /// Generate the XML structure /// </summary> /// <returns></returns> protected override XmlDocument GenerateXml(XmlDocument xml = null) { CheckMandatoryData(); if (xml == null) { xml = new XmlDocument(); xml.AppendChild(xml.CreateXmlDeclaration("1.0", Encoding.UTF8.BodyName, "yes")); var el = (XmlElement)xml.AppendChild(xml.CreateElement("Document")); el.SetAttribute("xmlns", "urn:iso:std:iso:20022:tech:xsd:scthr:" + SepaSchemaUtils.SepaSchemaToString(schema)); el.NewElement("CstmrCdtTrfInitn"); // Part 1: Group Header var grpHdr = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("GrpHdr"); grpHdr.NewElement("MsgId", MessageIdentification); grpHdr.NewElement("CreDtTm", StringUtils.FormatDateTime(CreationDate)); grpHdr.NewElement("NbOfTxs", numberOfTransactions); grpHdr.NewElement("CtrlSum", StringUtils.FormatAmount(headerControlSum)); if (!String.IsNullOrEmpty(InitiatingPartyName) || InitiatingPartyId != null) { var initgPty = grpHdr.NewElement("InitgPty"); if (!String.IsNullOrEmpty(InitiatingPartyName)) { initgPty.NewElement("Nm", InitiatingPartyName); } if (InitiatingPartyId != null) { initgPty .NewElement("Id").NewElement("OrgId") .NewElement("Othr").NewElement("Id", InitiatingPartyId); } } } else { var nbOfTxs = xml.SelectSingleNode("//NbOfTxs"); var ctrlSum = xml.SelectSingleNode("//CtrlSum"); nbOfTxs.InnerText = (StringUtils.GetAmountFromString(nbOfTxs.InnerText) + numberOfTransactions).ToString(); ctrlSum.InnerText = StringUtils.FormatAmount(StringUtils.GetAmountFromString(ctrlSum.InnerText) + headerControlSum); } // Part 2: Payment Information var pmtInf = XmlUtils.GetFirstElement(xml, "CstmrCdtTrfInitn").NewElement("PmtInf"); pmtInf.NewElement("PmtInfId", PaymentInfoId ?? MessageIdentification); pmtInf.NewElement("PmtMtd", Constant.CreditTransfertPaymentMethod); pmtInf.NewElement("NbOfTxs", numberOfTransactions); pmtInf.NewElement("CtrlSum", StringUtils.FormatAmount(paymentControlSum)); if (IsInternational) { pmtInf.NewElement("PmtTpInf").NewElement("InstrPrty", "NORM"); } else { pmtInf.NewElement("PmtTpInf").NewElement("SvcLvl").NewElement("Cd", "SEPA"); } if (CategoryPurposeCode != null) { pmtInf.GetLastElement("PmtTpInf"). NewElement("CtgyPurp"). NewElement("Cd", CategoryPurposeCode); } pmtInf.NewElement("ReqdExctnDt", StringUtils.FormatDate(RequestedExecutionDate)); pmtInf.NewElement("Dbtr").NewElement("Nm", Debtor.Name); if (Debtor.Address != null) { AddPostalAddressElements(pmtInf, "Dbtr", Debtor.Address); } if (InitiatingPartyId != null) { pmtInf.GetLastElement("Dbtr"). NewElement("Id").NewElement("OrgId"). NewElement("Othr").NewElement("Id", InitiatingPartyId); } var dbtrAcct = pmtInf.NewElement("DbtrAcct"); dbtrAcct.NewElement("Id").NewElement("IBAN", Debtor.Iban); dbtrAcct.NewElement("Ccy", DebtorAccountCurrency); pmtInf.NewElement("DbtrAgt").NewElement("FinInstnId").NewElement("BIC", Debtor.Bic); if (Debtor.AgentAddress != null) { AddPostalAddressElements(pmtInf, "FinInstnId", Debtor.AgentAddress); } if (IsInternational) { pmtInf.NewElement("ChrgBr", SepaChargeBearerUtils.SepaChargeBearerToString(ChargeBearer)); } else { pmtInf.NewElement("ChrgBr", "SLEV"); } // Part 3: Credit Transfer Transaction Information foreach (var transfer in transactions) { GenerateTransaction(pmtInf, transfer); } return(xml); }