Exemplo n.º 1
0
  private void fillUnifiedPayerIds(ExchangeContext ctx, DataRequest dataRequest) {
    if (ctx.getVariable("payerIdBlock") == null) return;
    Long countPayers = (Long) ctx.getVariable("payerIdBlock");
    if (countPayers > 0) {
      DataRequest.Payers payers = new DataRequest.Payers();
      dataRequest.setPayers(payers);

      for (int idx = 0; idx < countPayers; idx++) {
        payers.getPayerIdentifier().add(buildUnifiedPayerID(ctx, "_" + (idx + 1)));
      }
    }
  }
Exemplo n.º 2
0
  private void fillApplicationIds(ExchangeContext ctx, DataRequest dataRequest) {
    if (ctx.getVariable("ApplicationIdBlock") == null) return;
    Long countApplicationIds = (Long) ctx.getVariable("ApplicationIdBlock");
    if (countApplicationIds > 0) {
      DataRequest.ApplicationIDs applicationIDs = new DataRequest.ApplicationIDs();
      dataRequest.setApplicationIDs(applicationIDs);

      for (int idx = 0; idx < countApplicationIds; idx++) {
        Object supplierBillID = ctx.getVariable("ApplicationId_" + (idx + 1));
        if (supplierBillID != null) applicationIDs.getApplicationID().add((String) supplierBillID);
      }
    }
  }
Exemplo n.º 3
0
  private String buildSystemIdentifierForImportPaymentOperation(ExchangeContext ctx) {
    String bik = getStringFromContext(ctx, "paymentBIK", "");
    Long branchId = (Long) ctx.getVariable("paymentBankBranch");
    Date paymentDate = (Date) ctx.getVariable("paymentDate");
    if (ctx.getVariable("paymentId") == null) {
      throw new RuntimeException(
          "Уникальный номер платежа внутри отделения в теч. дня должен быть заполнен");
    }
    Long paymentId = (Long) ctx.getVariable("paymentId");

    String branchPart = leftPad(branchId.toString(), 6, '0');
    String datePaymentPart = new SimpleDateFormat("yyMMdd").format(paymentDate);
    String paymentIdPart = leftPad(paymentId.toString(), 10, '0');
    return "1" + bik + branchPart + datePaymentPart + paymentIdPart;
  }
Exemplo n.º 4
0
  public ClientRequest createClientRequest(ExchangeContext ctx) {
    final String originRequestId = (String) ctx.getVariable("smevOriginRequestId");

    final Packet packet = new Packet();
    packet.recipient = new InfoSystem("RKZN35001", "Казначейство России");
    InfoSystem pnzr8201 =
        new InfoSystem(
            "8201",
            "Комплексная система предоставления государственных и муниципальных услуг Пензенской области");
    packet.sender = packet.originator = pnzr8201;

    packet.typeCode = Packet.Type.EXECUTION;

    packet.date = new Date();
    packet.exchangeType = "6"; // 1 - Запрос на оказание услуги

    packet.originRequestIdRef = originRequestId;
    packet.testMsg = (String) ctx.getVariable("smevTest");

    final ClientRequest request = new ClientRequest();

    BigInteger caseNumber = generateCaseNumber();
    packet.caseNumber = caseNumber.toString();
    ctx.setVariable(SMEV_INITIAL_REG_NUMBER, caseNumber);
    ctx.setVariable(SMEV_INITIAL_REG_DATE, new Date());
    request.packet = packet;
    request.action = new QName("http://roskazna.ru/SmevUnifoService/", "UnifoTransferMsg");
    packet.status = Packet.Status.REQUEST;
    try {
      String typeOperation = getStringFromContext(ctx, "operationType", "");
      if (IMPORT_CHARGE_OPERATION.equals(typeOperation)) {
        request.appData = createAppDataForImportChargeOperation(ctx);
      } else if (EXPORT_OPERATION.equals(typeOperation)) {
        request.appData = createAppDataForExportOperation(ctx);
      } else if (IMPORT_PAYMENT_OPERATION.equals(typeOperation)) {
        request.appData = createAppDataForImportPaymentOperation(ctx);
      } else if (DO_ACKNOWLEDGMENT_OPERATION.equals(typeOperation)) {
        request.appData = createAcknowledgmentRequest(ctx);
      } else {
        throw new IllegalArgumentException("Тип операции не верен");
      }
    } catch (Exception e) {
      logger.log(Level.SEVERE, e.getMessage(), e);
      throw new RuntimeException(e.getMessage(), e);
    }

    return request;
  }
Exemplo n.º 5
0
 private PostBlock createPostBlock(ExchangeContext ctx, String postBlockSenderIdentifier) {
   final PostBlock postBlock = new PostBlock();
   String postBlockID =
       ctx.getVariable("postBlockId") == null
           ? UUID.randomUUID().toString()
           : (String) ctx.getVariable("postBlockId");
   ctx.setVariable("postBlockId", postBlockID);
   postBlock.setID(postBlockID); // идентификатор запроса
   postBlock.setSenderIdentifier(postBlockSenderIdentifier);
   Date postBlockTimeStamp =
       ctx.getVariable("postBlockTimeStamp") != null
           ? (Date) ctx.getVariable("postBlockTimeStamp")
           : new Date();
   postBlock.setTimeStamp(
       XmlTypes.dateTimeAndZeroMilliseconds(
           formatDate(postBlockTimeStamp, "dd.MM.yyyy HH:mm:ss"))); // дата составления запроса
   return postBlock;
 }
Exemplo n.º 6
0
 private void fillPaymentAdditionalData(PaymentInfoType paymentInfo, ExchangeContext ctx) {
   Long valuesCount = (Long) ctx.getVariable("payeeAddDataBlock");
   for (long idx = 0; idx < valuesCount; idx++) {
     PaymentType.AdditionalData additionalData = new PaymentType.AdditionalData();
     additionalData.setName(getStringFromContext(ctx, "payeeAddDataKey_" + (idx + 1), ""));
     additionalData.setValue(getStringFromContext(ctx, "payeeAddDataValue_" + (idx + 1), ""));
     paymentInfo.getAdditionalData().add(additionalData);
   }
 }
Exemplo n.º 7
0
 private void processInternalErrorService(ExchangeContext context, String errorCode) {
   if ("EBPP5000".equals(errorCode)) {
     int countRetries =
         context.getVariableNames().contains("countRetries")
             ? (Integer) context.getVariable("countRetries")
             : 0;
     countRetries++;
     context.setVariable("countRetries", countRetries);
     context.setVariable("smevTimeOut", calcTimeOut(countRetries));
     context.setVariable("smevPool", countRetries < 5);
   }
 }
Exemplo n.º 8
0
  String createAppDataForExportOperation(ExchangeContext ctx) {
    ExportData exportData = new ExportData();
    DataRequest dataRequest = new DataRequest();
    Date startDate = (Date) ctx.getVariable("startDate");
    if (startDate != null) {
      dataRequest.setStartDate(
          XmlTypes.dateTimeAndZeroMilliseconds(formatDate(startDate, "dd.MM.yyyy HH:mm:ss")));
    }

    Date endDate = (Date) ctx.getVariable("endDate");
    if (endDate != null) {
      dataRequest.setEndDate(
          XmlTypes.dateTimeAndZeroMilliseconds(formatDate(endDate, "dd.MM.yyyy HH:mm:ss")));
    }
    exportData.setDataRequest(dataRequest);
    dataRequest.setKind((String) ctx.getVariable("exportRequestType"));
    String postBlockSenderIdentifier = (String) ctx.getVariable("postBlockSenderIdentifier");
    final PostBlock postBlock = createPostBlock(ctx, postBlockSenderIdentifier);
    dataRequest.setPostBlock(postBlock);
    fillSupplierBillIds(ctx, dataRequest);
    fillApplicationIds(ctx, dataRequest);
    fillUnifiedPayerIds(ctx, dataRequest);
    return new XmlTypes(ExportData.class).toXml(exportData);
  }
Exemplo n.º 9
0
 private String createAcknowledgmentRequest(ExchangeContext ctx) {
   final DoAcknowledgmentRequestType acknowledgmentRequest = new DoAcknowledgmentRequestType();
   String postBlockSenderIdentifier = getStringFromContext(ctx, "postBlockSenderIdentifier", "");
   final PostBlock postBlock = createPostBlock(ctx, postBlockSenderIdentifier);
   acknowledgmentRequest.setPostBlock(postBlock);
   acknowledgmentRequest.setSupplierBillID(getStringFromContext(ctx, "SupplierBillID", ""));
   long countPayments = (Long) ctx.getVariable("paymentBlock");
   if (countPayments > 0l) {
     acknowledgmentRequest.setPayments(new DoAcknowledgmentRequestType.Payments());
     for (long paymentIdx = 0; paymentIdx < countPayments; paymentIdx++) {
       String paymentId = getStringFromContext(ctx, "paymentSystemId_" + (paymentIdx + 1), "");
       acknowledgmentRequest.getPayments().getPaymentSystemIdentifier().add(paymentId);
     }
   }
   return new XmlTypes(DoAcknowledgmentRequestType.class).toXml(acknowledgmentRequest);
 }
Exemplo n.º 10
0
 private String getStringFromContext(ExchangeContext ctx, String varName, String defaultString) {
   return ctx.getVariable(varName) == null ? defaultString : (String) ctx.getVariable(varName);
 }
Exemplo n.º 11
0
  String createAppDataForImportChargeOperation(ExchangeContext ctx) throws Exception {
    ImportData importData = new ImportData();
    final ImportRequest importRequest = new ImportRequest();
    String postBlockSenderIdentifier = (String) ctx.getVariable("postBlockSenderIdentifier");
    final PostBlock postBlock = createPostBlock(ctx, postBlockSenderIdentifier);
    importRequest.setPostBlock(postBlock);
    final ChargeType charge = new ChargeType();
    importRequest.setCharge(charge);

    String ordinalNumber = (String) ctx.getVariable("ordinalNumber");
    if (ordinalNumber == null || "".equals(ordinalNumber)) {
      ordinalNumber = formatDate(new Date(), "ddMMyyHHmmss");
    }

    String supplierBillID =
        UINGenerator.generateChargeUIN(postBlockSenderIdentifier, ordinalNumber);
    ctx.setVariable("supplierBillID", supplierBillID);
    charge.setSupplierBillID(supplierBillID); // Уникальный идентификатор счёта в ИСП
    charge.setBillDate(
        XmlTypes.date(
            formatDate(
                (Date) ctx.getVariable("chargeBillDate"), "dd.MM.yyyy"))); // Дата выставления счёта

    final Organization supplierOrgInfo = new Organization();
    supplierOrgInfo.setName((String) ctx.getVariable("supplierOrgInfoName"));
    supplierOrgInfo.setINN((String) ctx.getVariable("supplierOrgInfoINN"));
    supplierOrgInfo.setKPP((String) ctx.getVariable("supplierOrgInfoKPP"));
    final Account account = new Account();
    account.setAccount((String) ctx.getVariable("accountAccount"));
    account.setKind((String) ctx.getVariable("accountKind"));
    final Bank bank = new Bank();
    bank.setBIK((String) ctx.getVariable("bankBIK"));
    bank.setName((String) ctx.getVariable("bankName"));
    account.setBank(bank);
    supplierOrgInfo.setAccount(account);
    charge.setSupplierOrgInfo(supplierOrgInfo);
    charge.setBillFor((String) ctx.getVariable("chargeBillFor"));
    charge.setTotalAmount(toLong((String) ctx.getVariable("chargeTotalAmount")));
    charge.setChangeStatus(
        (String)
            ctx.getVariable(
                "chargeChangeStatus")); /* Статус счёта 1 - новый  2 - изменение  3 - аннулирование */
    charge.setTreasureBranch(
        (String)
            ctx.getVariable(
                "chargeTreasureBranch")); // Орган ФК, на счёт которого должны поступать средства
                                          // плательщика
    charge.setKBK((String) ctx.getVariable("chargeKBK"));
    charge.setOKATO((String) ctx.getVariable("chargeOKATO"));

    final BudgetIndex budgetIndex = new BudgetIndex();
    budgetIndex.setStatus((String) ctx.getVariable("budgetIndexStatus")); // Статус плательщика
    budgetIndex.setPaymentType((String) ctx.getVariable("budgetPaymentType")); // тип платежа
    budgetIndex.setPurpose(
        (String) ctx.getVariable("budgetPurpose")); // основание платежа 2 символа максимум
    budgetIndex.setTaxPeriod(
        (String) ctx.getVariable("budgetTaxPeriod")); // налоговый период до 10 символов
    budgetIndex.setTaxDocNumber(
        (String) ctx.getVariable("budgetTaxDocNumber")); // Показатель номера документа
    budgetIndex.setTaxDocDate(
        (String) ctx.getVariable("budgetTaxDocDate")); // Показатель даты документа
    charge.setBudgetIndex(budgetIndex);
    if ("".equals(getStringFromContext(ctx, "chargeApplicationID", ""))) {
      String applicationID = String.valueOf(System.currentTimeMillis());
      ctx.setVariable("chargeApplicationID", applicationID);
      charge.setApplicationID(applicationID);
    } else {
      charge.setApplicationID((String) ctx.getVariable("chargeApplicationID"));
    }

    String unifiedPayerIdentifier = buildUnifiedPayerID(ctx, "");
    ctx.setVariable("unifiedPayerIdentifier", unifiedPayerIdentifier);
    charge.setUnifiedPayerIdentifier(unifiedPayerIdentifier); //  единый идентификатор плательщика
    importData.setImportRequest(importRequest);
    String importDataStr = new XmlTypes(ImportData.class).toXml(importData);
    return cryptoProvider.signElement(importDataStr, "Charge", null, true, true, false);
  }
Exemplo n.º 12
0
  private String createAppDataForImportPaymentOperation(ExchangeContext ctx) throws Exception {
    ImportData importData = new ImportData();
    final ImportRequest importRequest = new ImportRequest();
    importData.setImportRequest(importRequest);
    String postBlockSenderIdentifier = (String) ctx.getVariable("postBlockSenderIdentifier");
    final PostBlock postBlock = createPostBlock(ctx, postBlockSenderIdentifier);
    importRequest.setPostBlock(postBlock);
    PaymentInfoType paymentInfo = new PaymentInfoType();
    importRequest.setFinalPayment(paymentInfo);

    paymentInfo.setNarrative(getStringFromContext(ctx, "paymentNarrative", ""));
    paymentInfo.setSupplierBillID(getStringFromContext(ctx, "paymentSupplierBillID", ""));
    paymentInfo.setAmount(toLong((String) ctx.getVariable("paymentAmount")));
    paymentInfo.setPaymentDate(
        XmlTypes.date(formatDate((Date) ctx.getVariable("paymentDate"), "dd.MM.yyyy")));
    paymentInfo.setChangeStatus(getStringFromContext(ctx, "paymentChangeStatus", "1"));
    paymentInfo.setPayeeINN(getStringFromContext(ctx, "paymentPayeeINN", ""));
    paymentInfo.setPayeeKPP(getStringFromContext(ctx, "paymentPayeeKPP", ""));
    paymentInfo.setKBK(getStringFromContext(ctx, "paymentKBK", ""));
    paymentInfo.setOKATO(getStringFromContext(ctx, "paymentOKATO", ""));
    paymentInfo.setPayerPA(getStringFromContext(ctx, "paymentPA", ""));

    Account payeeBankAcc = new Account();
    paymentInfo.setPayeeBankAcc(payeeBankAcc);
    payeeBankAcc.setAccount(getStringFromContext(ctx, "paymentPayeeAccount", ""));
    payeeBankAcc.setKind(getStringFromContext(ctx, "paymentPayeeBankAccKind", "!"));
    Bank payeeBank = new Bank();
    payeeBankAcc.setBank(payeeBank);
    payeeBank.setName(getStringFromContext(ctx, "paymentPayeeBankName", ""));
    payeeBank.setCorrespondentBankAccount(
        getStringFromContext(ctx, "paymentCorrespondentBankAccount", ""));
    payeeBank.setBIK(getStringFromContext(ctx, "paymentPayeeBankBIK", ""));

    PaymentIdentificationDataType paymentIdentificationData = new PaymentIdentificationDataType();
    paymentInfo.setPaymentIdentificationData(paymentIdentificationData);
    Bank bank = new Bank();
    paymentIdentificationData.setBank(bank);
    bank.setBIK(getStringFromContext(ctx, "paymentBIK", ""));
    bank.setName(getStringFromContext(ctx, "paymentBankName", ""));
    paymentIdentificationData.setSystemIdentifier(
        buildSystemIdentifierForImportPaymentOperation(ctx));

    fillPaymentAdditionalData(paymentInfo, ctx);
    final BudgetIndex budgetIndex = new BudgetIndex();
    paymentInfo.setBudgetIndex(budgetIndex);
    budgetIndex.setStatus(getStringFromContext(ctx, "Status", "0")); // Статус плательщика
    budgetIndex.setPaymentType(getStringFromContext(ctx, "PaymentType", "0")); // тип платежа
    budgetIndex.setPurpose(
        getStringFromContext(ctx, "Purpose", "0")); // основание платежа 2 символа максимум
    budgetIndex.setTaxPeriod(
        getStringFromContext(ctx, "TaxPeriod", "0")); // налоговый период до 10 символов
    budgetIndex.setTaxDocNumber(
        getStringFromContext(ctx, "TaxDocNumber", "0")); // Показатель номера документа
    budgetIndex.setTaxDocDate(
        getStringFromContext(ctx, "TaxDocDate", "0")); // Показатель даты документа

    paymentInfo.setPayerIdentifier(buildUnifiedPayerID(ctx, ""));

    String importDataStr = new XmlTypes(ImportData.class).toXml(importData);
    return cryptoProvider.signElement(importDataStr, "FinalPayment", null, true, true, false);
  }