Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 KB | None | 0 0
  1. package com.kreditpilot.service;
  2.  
  3. import com.kreditpilot.PushException;
  4. import com.kreditpilot.connection.ConnectionInterface;
  5. import com.kreditpilot.exception.CommonPushReportException;
  6. import com.kreditpilot.objects.BareBillAdditPar;
  7. import com.kreditpilot.objects.HttpSendObject;
  8. import com.kreditpilot.objects.SendObj;
  9. import com.kreditpilot.service.osmp.OSMPUtils;
  10. import com.kreditpilot.service.w1.Pay;
  11. import com.kreditpilot.transaction.TransactionContext;
  12. import com.kreditpilot.util.GetAccompanyData;
  13. import org.jdom.Document;
  14. import org.jdom.Element;
  15.  
  16. import java.math.BigDecimal;
  17. import java.sql.SQLException;
  18. import java.text.ParseException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.Map;
  21.  
  22. import static com.kreditpilot.service.osmp.OSMPUtils.*;
  23.  
  24. /**
  25. * Created with IntelliJ IDEA.
  26. * User: rainbow
  27. * Date: 09.04.13
  28. * Time: 13:27
  29. */
  30.  
  31. public class PushForShopOSMPTerminalWoPass extends AbstractXmlBodyHttpPushPerform {
  32.  
  33. // private String login;
  34. // private String password;
  35. // private String terminalId;
  36. // private String currency;
  37. private long remoteServiceId;
  38. private long timeout;
  39. private int retryCount;
  40.  
  41. @Override
  42. protected String getDefaultEncoding() {
  43. return ENCODING;
  44. }
  45.  
  46. @Override
  47. public void init() throws PushException {
  48.  
  49. addStep(String.valueOf(AUTH));
  50. addStep(String.valueOf(CONFIRM));
  51.  
  52. // final Map<ConnectionInterface.ConnectionParameters,Object> params = getConnectData().getConnParams();
  53.  
  54. // login = (String) params.get(ConnectionInterface.ConnectionParameters.AUTH_LOGIN);
  55. // password = (String) params.get(ConnectionInterface.ConnectionParameters.AUTH_PASSWD);
  56. // if (login == null || login.trim().isEmpty() || password == null || password.trim().isEmpty()) {
  57. // throw new PushException("Invalid login/password: login = " + login + " password = " + password);
  58. // }
  59. //
  60. // terminalId = (String) params.get(ConnectionInterface.ConnectionParameters.DIGSIGN_KEY_FILE);
  61. // if (terminalId == null || terminalId.trim().isEmpty()) {
  62. // throw new PushException("Invalid terminal id: terminalId = " + terminalId);
  63. // }
  64. //
  65. // currency = (String) params.get(ConnectionInterface.ConnectionParameters.DIGSIGN_KEY_PASSWD);
  66. //
  67. // try {
  68. // remoteServiceId = GetAccompanyData.getRemoteServiceId(getSQLConnection(), getDataBase().getShopId());
  69. // } catch (SQLException e) {
  70. // log.error(e, e);
  71. // throw new PushException("Error getting remoteServiceId");
  72. // }
  73. //
  74. // timeout = params.get(ConnectionInterface.ConnectionParameters.TIMEOUT) != null ? ((BigDecimal) params.get(ConnectionInterface.ConnectionParameters.TIMEOUT)).longValueExact() : DEFAULT_RETRY_TIMEOUT;
  75. }
  76.  
  77. @Override
  78. public SendObj getRequest() throws CommonPushReportException {
  79. int step = Integer.parseInt(getStepOfWork());
  80.  
  81. String body;
  82. BareBillAdditPar bb = getCastedBareBill();
  83. String account = getPhoneNumber();
  84. String amount = String.valueOf(bb.getBillSum());
  85. String pushId = bb.getBillNumber();
  86.  
  87. switch (step){
  88. case AUTH:
  89. body = "?command=check&txn_id=" + pushId + "&account=" + account + "&sum=" + amount;
  90. break;
  91. case CONFIRM:
  92. SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
  93. String tdate = df.format(bb.getBillDate());
  94. body = "?command=pay&txn_id=" + pushId + "&account=" + account + "&sum=" + amount + "&txn_date=" + tdate;
  95. break;
  96. default:
  97. throw new CommonPushReportException("Unknown step " + step);
  98. }
  99. //command=check&txn_id=22255568264&account=569&sum=1.45
  100. //?command=pay&txn_id=2222345670&txn_date=20161018164336&account=569&sum=1.45
  101. return sendObj;
  102. }
  103.  
  104. @Override
  105. public int parse(Document doc) throws PushException {
  106.  
  107. int step = Integer.parseInt(getStepOfWork());
  108. String commandElementName = step == AUTH ? "authorizePayment" : "confirmPayment";
  109.  
  110. int result;
  111. int status;
  112. String uid;
  113. int returnCode = -1;
  114.  
  115. Element commandElement = doc.getRootElement().getChild("providers").getChild(commandElementName);
  116.  
  117. if (commandElement != null) {
  118.  
  119. Element payment = commandElement.getChild("payment");
  120.  
  121. if (payment != null) {
  122.  
  123. status = Integer.parseInt(payment.getAttributeValue("status"));
  124. result = Integer.parseInt(payment.getAttributeValue("result"));
  125. uid = payment.getAttributeValue("uid");
  126.  
  127. switch (step) {
  128.  
  129. case AUTH:
  130.  
  131. if (status == 0) {
  132. // ошибка проведения
  133. returnCode = result;
  134. } else {
  135.  
  136. // авторизован или проводится
  137. returnCode = 0;
  138.  
  139. if (status == 3) {
  140. // авторизован
  141. getDataBase().setBillingTransactId(uid);
  142. setNextStepOfWork();
  143. } else {
  144. // проводится
  145. if (retryCount < MAX_ATTEMPTS) {
  146. retryCount++;
  147. try {
  148. Thread.sleep(timeout);
  149. } catch (InterruptedException e) {
  150. e.printStackTrace();
  151. }
  152. } else {
  153. returnCode = TransactionContext.NOT_DEFINED;
  154. }
  155. }
  156. }
  157.  
  158. break;
  159.  
  160. case CONFIRM:
  161.  
  162. if (status == 0) {
  163. // ошибка проведения
  164. returnCode = result;
  165. } else {
  166.  
  167. // проведен или проводится
  168. returnCode = 0;
  169.  
  170. if (status == 2) {
  171. // проведен
  172. setNextStepOfWork();
  173. } else {
  174. // проводится
  175. if (retryCount < MAX_ATTEMPTS) {
  176. retryCount++;
  177. try {
  178. Thread.sleep(timeout);
  179. } catch (InterruptedException e) {
  180. e.printStackTrace();
  181. }
  182. } else {
  183. returnCode = TransactionContext.NOT_DEFINED;
  184. }
  185. }
  186. }
  187.  
  188. break;
  189. }
  190.  
  191. return returnCode;
  192. } else {
  193. result = Integer.parseInt(commandElement.getAttributeValue("result"));
  194. return result;
  195. }
  196.  
  197. } else {
  198.  
  199. throw new PushException("Unknown provider reply");
  200. }
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement