|
|
@@ -1,22 +1,28 @@
|
|
|
package com.poteviohealth.ym.ipos.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.poteviohealth.cgp.common.filter.TokenContext;
|
|
|
-import com.poteviohealth.cgp.common.integrated.StringParams;
|
|
|
+import com.poteviohealth.cgp.common.integrated.order.OrderFeignClient;
|
|
|
+import com.poteviohealth.cgp.common.integrated.order.model.PayInfoAppOutDTO;
|
|
|
+import com.poteviohealth.cgp.common.integrated.order.model.PayReceive;
|
|
|
+import com.poteviohealth.cgp.common.integrated.order.model.RefundReceive;
|
|
|
import com.poteviohealth.cgp.common.model.VaultsResponse;
|
|
|
+import com.poteviohealth.cgp.common.utils.DateUtils;
|
|
|
import com.poteviohealth.ym.ipos.model.payment.*;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.back.BindPosBack;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.back.PayBack;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.back.PayQueryBack;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.detail.PayParams;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.detail.PayQueryDetail;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.detail.StoreInfo;
|
|
|
-import com.poteviohealth.ym.ipos.model.payment.detail.Wxapp;
|
|
|
+import com.poteviohealth.ym.ipos.model.payment.back.*;
|
|
|
+import com.poteviohealth.ym.ipos.model.payment.detail.*;
|
|
|
import com.poteviohealth.ym.ipos.model.payment.dto.BindDto;
|
|
|
+import com.poteviohealth.ym.ipos.service.IPaymentRecordsService;
|
|
|
import com.poteviohealth.ym.ipos.service.IPaymentService;
|
|
|
import com.poteviohealth.ym.ipos.utils.YmUtil;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* 支付
|
|
|
* @author Qin
|
|
|
@@ -25,6 +31,21 @@ import org.springframework.stereotype.Service;
|
|
|
@Log4j2
|
|
|
public class PaymentServiceImpl implements IPaymentService {
|
|
|
|
|
|
+ @Value("${pay.field.ip}")
|
|
|
+ private String ip;
|
|
|
+
|
|
|
+ @Value("${pay.field.notifyUrl}")
|
|
|
+ private String notifyUrl;
|
|
|
+
|
|
|
+ @Value("${pay.field.code}")
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IPaymentRecordsService paymentRecordsService;
|
|
|
+ @Resource
|
|
|
+ private OrderFeignClient orderFeignClient;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public VaultsResponse bindPos(BindDto dto) {
|
|
|
BindPos pos = new BindPos();
|
|
|
@@ -55,12 +76,13 @@ public class PaymentServiceImpl implements IPaymentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VaultsResponse<PayQueryBack> barcodeQuery(String paySn) {
|
|
|
+ public VaultsResponse<PayQueryBack> barcodeQuery(String transactionId) {
|
|
|
+
|
|
|
PayQuery payQuery = new PayQuery();
|
|
|
payQuery.setPos_id(TokenContext.curePosId());
|
|
|
payQuery.setStore_id(TokenContext.cureStoreId());
|
|
|
PayQueryDetail detail = new PayQueryDetail();
|
|
|
- detail.setOrg_pos_seq(paySn);
|
|
|
+ detail.setOrg_pos_seq(transactionId);
|
|
|
payQuery.setBarcode_query_request(detail);
|
|
|
PayQueryBack back = null;
|
|
|
try {
|
|
|
@@ -78,24 +100,132 @@ public class PaymentServiceImpl implements IPaymentService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VaultsResponse barcodeReverse(PayReverse payReverse) {
|
|
|
- return null;
|
|
|
+ public VaultsResponse barcodeReverse(RefundReceive refundReceive) {
|
|
|
+ PayReverse payReverse = new PayReverse();
|
|
|
+ payReverse.setPos_id(code);
|
|
|
+ payReverse.setStore_id(refundReceive.getOperatorId().toString());
|
|
|
+ payReverse.setPos_seq(refundReceive.getRefundId().toString());
|
|
|
+ PayReverseDetail detail = new PayReverseDetail();
|
|
|
+ detail.setTx_amt(refundReceive.getPrice().toString());
|
|
|
+ detail.setOrg_pos_seq(refundReceive.getPayId().toString());
|
|
|
+ payReverse.setBarcode_reverse_request(detail);
|
|
|
+ PayReverseBack back = null;
|
|
|
+ try {
|
|
|
+ back = (PayReverseBack) YmUtil.resultBack(payReverse,new PayReverseBack());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return VaultsResponse.failed(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(YmUtil.SUCCESS.equals(back.getResult().getId())){
|
|
|
+ return VaultsResponse.success();
|
|
|
+ }else if(YmUtil.FAIL.equals(back.getResult().getId())){
|
|
|
+ return this.barcodeRefundQuery(refundReceive.getRefundId().toString(),refundReceive.getOperatorId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return VaultsResponse.failed(back.getResult().getComment());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VaultsResponse barcodeRefundQuery(PayRefundQuery payRefundQuery) {
|
|
|
- return null;
|
|
|
+ public VaultsResponse barcodeRefundQuery(String transactionId,String operatorId) {
|
|
|
+ PayRefundQuery payRefundQuery = new PayRefundQuery();
|
|
|
+ payRefundQuery.setPos_id(code);
|
|
|
+ payRefundQuery.setStore_id(operatorId);
|
|
|
+ PayQueryDetail detail = new PayQueryDetail();
|
|
|
+ detail.setOrg_pos_seq(transactionId);
|
|
|
+ payRefundQuery.setBarcode_refundquery_request(detail);
|
|
|
+
|
|
|
+ PayRefundQueryBack back = null;
|
|
|
+ try {
|
|
|
+ back = (PayRefundQueryBack) YmUtil.resultBack(payRefundQuery,new PayRefundQueryBack());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return VaultsResponse.failed(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(YmUtil.SUCCESS.equals(back.getResult().getId())){
|
|
|
+ return VaultsResponse.success();
|
|
|
+ }else if(YmUtil.FAIL.equals(back.getResult().getId())){
|
|
|
+ return VaultsResponse.success("退款处理中...");
|
|
|
+ }
|
|
|
+
|
|
|
+ return VaultsResponse.failed(back.getResult().getComment());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public VaultsResponse<PayBack> unifiedOrder(StringParams params) {
|
|
|
+ public VaultsResponse<PayInfoAppOutDTO> unifiedOrder(PaymentRecords records) {
|
|
|
+ PayInfoAppOutDTO dto = new PayInfoAppOutDTO();
|
|
|
+ PayOrder payOrder = new PayOrder();
|
|
|
+ payOrder.setPos_seq(records.getPayId().toString());
|
|
|
+ payOrder.setPos_id(code);
|
|
|
+ payOrder.setStore_id(records.getOperatorId().toString());
|
|
|
+ payOrder.setDevice_ip(ip);
|
|
|
+ PayDetail detail = new PayDetail();
|
|
|
+ detail.setBuyer_id(records.getOpenid());
|
|
|
+ detail.setTx_amt(records.getTxAmt());
|
|
|
+ detail.setNotify_url(notifyUrl);
|
|
|
+ ExtendParams extendParams = new ExtendParams();
|
|
|
+ extendParams.setPlan_split_date(DateFormatUtils.format(DateUtils.caculDays(new Date(),17),"yyyyMMdd"));
|
|
|
+ detail.setExtend_params(extendParams);
|
|
|
+ payOrder.setUnifiedorder_request(detail);
|
|
|
+ PayBack back = null;
|
|
|
+ try {
|
|
|
+ back = (PayBack) YmUtil.resultBack(payOrder,new PayBack());
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return VaultsResponse.failed(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(YmUtil.FAIL.equals(back.getResult().getId())){
|
|
|
+ dto.setTimeStamp(back.getTime_stamp());
|
|
|
+ dto.setNonceStr(back.getNonce_str());
|
|
|
+ dto.setPackages(back.getPay_id());
|
|
|
+ dto.setSignType(back.getSign_type());
|
|
|
+ dto.setPaySign(back.getPay_sign());
|
|
|
+ dto.setPaySn(records.getPaySn());
|
|
|
+ return VaultsResponse.success(dto);
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ return VaultsResponse.failed(back.getResult().getComment());
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void payNotification(PayNotification payNotification) {
|
|
|
+ public String payNotification(PayNotification payNotification) {
|
|
|
|
|
|
+ QueryWrapper<PaymentRecords> queryMapper = new QueryWrapper<>();
|
|
|
+ queryMapper.eq("pay_id",payNotification.getPos_seq());
|
|
|
+ try {
|
|
|
+ PaymentRecords pr = paymentRecordsService.getOne(queryMapper);
|
|
|
+ if(pr.getStatus() == -1){
|
|
|
+ pr.setStatus(Integer.parseInt(payNotification.getStatus()));
|
|
|
+ pr.setEndTime(payNotification.getEnd_time());
|
|
|
+ pr.setSource(payNotification.getSource());
|
|
|
+ pr.setPosId(payNotification.getPos_id());
|
|
|
+ pr.setPayType(payNotification.getPay_type());
|
|
|
+ pr.setTransType(payNotification.getTrans_type());
|
|
|
+ pr.setTradeNo(payNotification.getTrade_no());
|
|
|
+
|
|
|
+ PayReceive payReceive = new PayReceive();
|
|
|
+ payReceive.setPayId(pr.getPayId());
|
|
|
+ payReceive.setPaySn(pr.getPaySn());
|
|
|
+ payReceive.setOperatorId(pr.getOperatorId());
|
|
|
+ payReceive.setTradeNo(payNotification.getPos_seq());
|
|
|
+ VaultsResponse vaultsResponse = orderFeignClient.changeOrderPay(payReceive);
|
|
|
+ if(vaultsResponse.validate()){
|
|
|
+ paymentRecordsService.updateById(pr);
|
|
|
+ }else {
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ log.info("重复推送支付成功消息---"+pr.getPaySn());
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+ return "success";
|
|
|
}
|
|
|
}
|