Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kreditpilot.service;
- import com.kreditpilot.PushException;
- import com.kreditpilot.connection.ConnectionInterface;
- import com.kreditpilot.exception.CommonPushReportException;
- import com.kreditpilot.objects.BareBillAdditPar;
- import com.kreditpilot.objects.HttpSendObject;
- import com.kreditpilot.objects.SendObj;
- import com.kreditpilot.service.osmp.OSMPUtils;
- import com.kreditpilot.service.w1.Pay;
- import com.kreditpilot.transaction.TransactionContext;
- import com.kreditpilot.util.GetAccompanyData;
- import org.jdom.Document;
- import org.jdom.Element;
- import java.math.BigDecimal;
- import java.sql.SQLException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Map;
- import static com.kreditpilot.service.osmp.OSMPUtils.*;
- /**
- * Created with IntelliJ IDEA.
- * User: rainbow
- * Date: 09.04.13
- * Time: 13:27
- */
- public class PushForShopOSMPTerminalWoPass extends AbstractXmlBodyHttpPushPerform {
- // private String login;
- // private String password;
- // private String terminalId;
- // private String currency;
- private long remoteServiceId;
- private long timeout;
- private int retryCount;
- @Override
- protected String getDefaultEncoding() {
- return ENCODING;
- }
- @Override
- public void init() throws PushException {
- addStep(String.valueOf(AUTH));
- addStep(String.valueOf(CONFIRM));
- // final Map<ConnectionInterface.ConnectionParameters,Object> params = getConnectData().getConnParams();
- // login = (String) params.get(ConnectionInterface.ConnectionParameters.AUTH_LOGIN);
- // password = (String) params.get(ConnectionInterface.ConnectionParameters.AUTH_PASSWD);
- // if (login == null || login.trim().isEmpty() || password == null || password.trim().isEmpty()) {
- // throw new PushException("Invalid login/password: login = " + login + " password = " + password);
- // }
- //
- // terminalId = (String) params.get(ConnectionInterface.ConnectionParameters.DIGSIGN_KEY_FILE);
- // if (terminalId == null || terminalId.trim().isEmpty()) {
- // throw new PushException("Invalid terminal id: terminalId = " + terminalId);
- // }
- //
- // currency = (String) params.get(ConnectionInterface.ConnectionParameters.DIGSIGN_KEY_PASSWD);
- //
- // try {
- // remoteServiceId = GetAccompanyData.getRemoteServiceId(getSQLConnection(), getDataBase().getShopId());
- // } catch (SQLException e) {
- // log.error(e, e);
- // throw new PushException("Error getting remoteServiceId");
- // }
- //
- // timeout = params.get(ConnectionInterface.ConnectionParameters.TIMEOUT) != null ? ((BigDecimal) params.get(ConnectionInterface.ConnectionParameters.TIMEOUT)).longValueExact() : DEFAULT_RETRY_TIMEOUT;
- }
- @Override
- public SendObj getRequest() throws CommonPushReportException {
- int step = Integer.parseInt(getStepOfWork());
- String body;
- BareBillAdditPar bb = getCastedBareBill();
- String account = getPhoneNumber();
- String amount = String.valueOf(bb.getBillSum());
- String pushId = bb.getBillNumber();
- switch (step){
- case AUTH:
- body = "?command=check&txn_id=" + pushId + "&account=" + account + "&sum=" + amount;
- break;
- case CONFIRM:
- SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
- String tdate = df.format(bb.getBillDate());
- body = "?command=pay&txn_id=" + pushId + "&account=" + account + "&sum=" + amount + "&txn_date=" + tdate;
- break;
- default:
- throw new CommonPushReportException("Unknown step " + step);
- }
- //command=check&txn_id=22255568264&account=569&sum=1.45
- //?command=pay&txn_id=2222345670&txn_date=20161018164336&account=569&sum=1.45
- return sendObj;
- }
- @Override
- public int parse(Document doc) throws PushException {
- int step = Integer.parseInt(getStepOfWork());
- String commandElementName = step == AUTH ? "authorizePayment" : "confirmPayment";
- int result;
- int status;
- String uid;
- int returnCode = -1;
- Element commandElement = doc.getRootElement().getChild("providers").getChild(commandElementName);
- if (commandElement != null) {
- Element payment = commandElement.getChild("payment");
- if (payment != null) {
- status = Integer.parseInt(payment.getAttributeValue("status"));
- result = Integer.parseInt(payment.getAttributeValue("result"));
- uid = payment.getAttributeValue("uid");
- switch (step) {
- case AUTH:
- if (status == 0) {
- // ошибка проведения
- returnCode = result;
- } else {
- // авторизован или проводится
- returnCode = 0;
- if (status == 3) {
- // авторизован
- getDataBase().setBillingTransactId(uid);
- setNextStepOfWork();
- } else {
- // проводится
- if (retryCount < MAX_ATTEMPTS) {
- retryCount++;
- try {
- Thread.sleep(timeout);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else {
- returnCode = TransactionContext.NOT_DEFINED;
- }
- }
- }
- break;
- case CONFIRM:
- if (status == 0) {
- // ошибка проведения
- returnCode = result;
- } else {
- // проведен или проводится
- returnCode = 0;
- if (status == 2) {
- // проведен
- setNextStepOfWork();
- } else {
- // проводится
- if (retryCount < MAX_ATTEMPTS) {
- retryCount++;
- try {
- Thread.sleep(timeout);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else {
- returnCode = TransactionContext.NOT_DEFINED;
- }
- }
- }
- break;
- }
- return returnCode;
- } else {
- result = Integer.parseInt(commandElement.getAttributeValue("result"));
- return result;
- }
- } else {
- throw new PushException("Unknown provider reply");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement