1. 迁移三方 PayClient 的代码

pull/4/MERGE
YunaiV 2020-11-28 23:32:51 +08:00
parent 0a14b530b6
commit d1b6118052
17 changed files with 94 additions and 356 deletions

View File

@ -59,6 +59,14 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 云服务相关 -->
<dependency>
<groupId>Pingplusplus</groupId>
<artifactId>pingpp-java</artifactId>
<version>2.2.4</version>
<type>jar</type>
</dependency>
<!-- Test 相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -105,4 +113,15 @@
</plugins>
</build>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
</project>

View File

@ -0,0 +1 @@
package cn.iocoder.mall.payservice.client;

View File

@ -1,13 +1,18 @@
package cn.iocoder.mall.pay.biz.client;
package cn.iocoder.mall.payservice.client.thirdpay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.pay.biz.dataobject.PayRefundDO;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionDO;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionExtensionDO;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayRefundSuccessRespDTO;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayTransactionSuccessRespDTO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.refund.PayRefundDO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionExtensionDO;
import java.util.Map;
public abstract class AbstractPaySDK {
/**
* Client
*/
public abstract class AbstractThirdPayClient {
/**
*
@ -28,7 +33,7 @@ public abstract class AbstractPaySDK {
* @return
*/
// TODO 芋艿,理论来说不会出现解析失败的情况,先返回这个参数列。等后面封装支付宝和微信支付的时候,在看看。
public abstract CommonResult<TransactionSuccessBO> parseTransactionSuccessParams(String params);
public abstract CommonResult<ThirdPayTransactionSuccessRespDTO> parseTransactionSuccessParams(String params);
/**
* 退
@ -49,6 +54,6 @@ public abstract class AbstractPaySDK {
* @return
*/
// TODO 芋艿,理论来说不会出现解析失败的情况,先返回这个参数列。等后面封装支付宝和微信支付的时候,在看看。
public abstract CommonResult<RefundSuccessBO> parseRefundSuccessParams(String params);
public abstract CommonResult<ThirdPayRefundSuccessRespDTO> parseRefundSuccessParams(String params);
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.mall.payservice.client.thirdpay;
import cn.iocoder.mall.payservice.enums.PayChannelEnum;
import java.util.HashMap;
import java.util.Map;
public class PaySDKFactory {
private static Map<Integer, AbstractThirdPayClient> CLIENTS = new HashMap<>();
static {
CLIENTS.put(PayChannelEnum.PINGXX.getId(), new PingxxThirdPayClient());
}
public static AbstractThirdPayClient getSDK(Integer payChannel) {
AbstractThirdPayClient client = CLIENTS.get(payChannel);
if (client == null) {
throw new NullPointerException("找不到合适的 ThirdPayClient " + payChannel);
}
return client;
}
}

View File

@ -1,9 +1,11 @@
package cn.iocoder.mall.pay.biz.client;
package cn.iocoder.mall.payservice.client.thirdpay;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.pay.biz.dataobject.PayRefundDO;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionDO;
import cn.iocoder.mall.pay.biz.dataobject.PayTransactionExtensionDO;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayRefundSuccessRespDTO;
import cn.iocoder.mall.payservice.client.thirdpay.dto.ThirdPayTransactionSuccessRespDTO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.refund.PayRefundDO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionDO;
import cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction.PayTransactionExtensionDO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.ImmutableMap;
@ -17,7 +19,7 @@ import java.util.HashMap;
import java.util.Map;
// TODO 代码略乱,后面重构下
public class PingxxPaySDK extends AbstractPaySDK {
public class PingxxThirdPayClient extends AbstractThirdPayClient {
static {
Pingpp.privateKeyPath = "/Users/yunai/Downloads/pingxx.pem";
@ -65,14 +67,14 @@ public class PingxxPaySDK extends AbstractPaySDK {
}
@Override
public CommonResult<TransactionSuccessBO> parseTransactionSuccessParams(String params) {
public CommonResult<ThirdPayTransactionSuccessRespDTO> parseTransactionSuccessParams(String params) {
JSONObject paramsObj = JSON.parseObject(params);
JSONObject chargeObj = paramsObj.getJSONObject("data").getJSONObject("object");
TransactionSuccessBO transactionPaySuccessBO = new TransactionSuccessBO()
ThirdPayTransactionSuccessRespDTO successRespDTO = new ThirdPayTransactionSuccessRespDTO()
.setTransactionCode(chargeObj.getString("order_no"))
.setPaymentTime(new Date(chargeObj.getLong("time_paid") * 1000))
.setTradeNo(chargeObj.getString("transaction_no"));
return CommonResult.success(transactionPaySuccessBO);
return CommonResult.success(successRespDTO);
}
@Override
@ -99,16 +101,16 @@ public class PingxxPaySDK extends AbstractPaySDK {
// {"id":"evt_400190427005305341228202","created":1556297585,"livemode":false,"type":"refund.succeeded","data":{"object":{"id":"re_HO0m9GOGOi50KCmX104ufHe1","object":"refund","order_no":"HO0m9GOGOi50KCmX104ufHe1","amount":1,"created":1556297585,"succeed":true,"status":"succeeded","time_succeed":1556297585,"description":"测试下退款","failure_code":null,"failure_msg":null,"metadata":{},"charge":"ch_y1iXjLnDS4G4OO4uT4a5C4W1","charge_order_no":"20190427004410165545","transaction_no":"201904270053053608824","extra":{}}},"object":"event","request":"iar_Oa188KCiHC40iLibbHX5WrHC","pending_webhooks":0}
@Override
public CommonResult<RefundSuccessBO> parseRefundSuccessParams(String params) {
public CommonResult<ThirdPayRefundSuccessRespDTO> parseRefundSuccessParams(String params) {
JSONObject paramsObj = JSON.parseObject(params);
JSONObject chargeObj = paramsObj.getJSONObject("data").getJSONObject("object");
RefundSuccessBO refundSuccessBO = new RefundSuccessBO()
ThirdPayRefundSuccessRespDTO successRespDTO = new ThirdPayRefundSuccessRespDTO()
.setRefundCode(chargeObj.getJSONObject("metadata").getString("refundCode"))
.setRefundTime(new Date(chargeObj.getLong("time_succeed") * 1000))
.setTradeNo(chargeObj.getString("transaction_no"))
// TODO 芋艿,需要测试下,退款失败
.setSuccess(chargeObj.containsValue("failure_code") || chargeObj.containsValue("failure_msg"));
return CommonResult.success(refundSuccessBO);
return CommonResult.success(successRespDTO);
}
private Map<String, Object> createRefundRequest(PayRefundDO refund, String chargeId, String orderDescription, Integer price) {
@ -123,7 +125,7 @@ public class PingxxPaySDK extends AbstractPaySDK {
}
public static void main(String[] args) {
if (false) { // 测试支付请求
if (true) { // 测试支付请求
PayTransactionDO transaction = new PayTransactionDO();
transaction.setOrderSubject("测试商品");
transaction.setOrderDescription("测试描述");
@ -133,14 +135,14 @@ public class PingxxPaySDK extends AbstractPaySDK {
extension.setTransactionCode(System.currentTimeMillis() + "");
extension.setCreateIp("127.0.0.1");
new PingxxPaySDK().submitTransaction(transaction, extension, null);
new PingxxThirdPayClient().submitTransaction(transaction, extension, null);
}
if (true) { // 测试退款请求
if (false) { // 测试退款请求
PayRefundDO refund = new PayRefundDO().setPrice(9999999).setOrderDescription("测试描述");
PayTransactionExtensionDO transactionExtension = new PayTransactionExtensionDO()
.setExtensionData("{\"id\":\"evt_400190423100354205607502\",\"created\":1555985033,\"livemode\":false,\"type\":\"charge.succeeded\",\"data\":{\"object\":{\"id\":\"ch_DCGyXTmDGuHKb1C0yTzjPOGC\",\"object\":\"charge\",\"created\":1555985032,\"livemode\":false,\"paid\":true,\"refunded\":false,\"reversed\":false,\"app\":\"app_aTyfXDjrvzDSbLuz\",\"channel\":\"wx_pub\",\"order_no\":\"20190423100352158401\",\"client_ip\":\"114.87.158.59\",\"amount\":10,\"amount_settle\":10,\"currency\":\"cny\",\"subject\":\"kafka 实战\",\"body\":\"测试描述\",\"extra\":{\"open_id\":\"just_for_test\",\"bank_type\":\"your bank type\"},\"time_paid\":1555985033,\"time_expire\":1555992232,\"time_settle\":null,\"transaction_no\":\"1244341374201904238178164740\",\"refunds\":{\"object\":\"list\",\"url\":\"/v1/charges/ch_DCGyXTmDGuHKb1C0yTzjPOGC/refunds\",\"has_more\":false,\"data\":[]},\"amount_refunded\":0,\"failure_code\":null,\"failure_msg\":null,\"metadata\":{},\"credential\":{},\"description\":\"测试备注\"}},\"object\":\"event\",\"request\":\"iar_4e9mPODW5ujPqLen5OOmvL8S\",\"pending_webhooks\":0}");
new PingxxPaySDK().submitRefund(refund, transactionExtension, null);
new PingxxThirdPayClient().submitRefund(refund, transactionExtension, null);
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.pay.biz.client;
package cn.iocoder.mall.payservice.client.thirdpay.dto;
import lombok.Data;
import lombok.experimental.Accessors;
@ -6,11 +6,11 @@ import lombok.experimental.Accessors;
import java.util.Date;
/**
* 退
* 退 Response DTO
*/
@Data
@Accessors(chain = true)
public class RefundSuccessBO {
public class ThirdPayRefundSuccessRespDTO {
/**
*

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.pay.biz.client;
package cn.iocoder.mall.payservice.client.thirdpay.dto;
import lombok.Data;
import lombok.experimental.Accessors;
@ -6,11 +6,11 @@ import lombok.experimental.Accessors;
import java.util.Date;
/**
*
* Response DTO
*/
@Data
@Accessors(chain = true)
public class TransactionSuccessBO {
public class ThirdPayTransactionSuccessRespDTO {
/**
*

View File

@ -1,7 +1,9 @@
package cn.iocoder.mall.pay.biz.dataobject;
package cn.iocoder.mall.payservice.dal.mysql.dataobject.refund;
import cn.iocoder.common.framework.dataobject.BaseDO;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.util.Date;
@ -9,9 +11,11 @@ import java.util.Date;
/**
* 退 DO
*/
@TableName("pay_refund")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class PayRefundDO extends BaseDO {
public class PayRefundDO extends DeletableDO {
/**
*

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.pay.biz.dataobject;
package cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@ -1,13 +1,17 @@
package cn.iocoder.mall.pay.biz.dataobject;
package cn.iocoder.mall.payservice.dal.mysql.dataobject.transaction;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import cn.iocoder.mall.mybatis.core.dataobject.DeletableDO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
*
*/
@TableName("pay_transaction_extension")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class PayTransactionExtensionDO extends DeletableDO {
@ -42,7 +46,7 @@ public class PayTransactionExtensionDO extends DeletableDO {
/**
*
*
* @see cn.iocoder.mall.pay.api.constant.PayTransactionStatusEnum
* @see cn.iocoder.mall.payservice.enums.transaction.PayTransactionStatusEnum
* WAITING SUCCESS
*/
private Integer status;

View File

@ -1,105 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pay</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pay-application</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>mall-spring-boot</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>pay-service-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>system-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>user-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
</dependency>
<!-- 服务保障相关 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 测试相关 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 监控相关 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- 打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,6 +0,0 @@
swagger:
enable: true
title: 支付子系统
description: 支付子系统
version: 1.0.0
base-package: cn.iocoder.mall.pay.application.controller

View File

@ -1,32 +0,0 @@
spring:
application:
name: pay-application
# Spring Cloud 配置项
cloud:
# Spring Cloud Sentinel 配置项
sentinel:
transport:
dashboard: s1.iocoder.cn:12088 # Sentinel Dashboard 服务地址
eager: true # 项目启动时,直接连接到 Sentinel
# server
server:
port: 18084
servlet:
context-path: /pay-api/
swagger:
enable: true
title: 支付子系统
description: 支付子系统
version: 1.0.0
base-package: cn.iocoder.mall.pay.application.controller
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true

View File

@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>pay</artifactId>
<groupId>cn.iocoder.mall</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pay-service-api</artifactId>
<dependencies>
<!-- Mall 相关 -->
<dependency>
<groupId>cn.iocoder.mall</groupId>
<artifactId>common-framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId> <!-- use mapstruct-jdk8 for Java 8 or higher -->
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,24 +0,0 @@
package cn.iocoder.mall.pay.biz.client;
import cn.iocoder.mall.pay.api.constant.PayChannelEnum;
import java.util.HashMap;
import java.util.Map;
public class PaySDKFactory {
private static Map<Integer, AbstractPaySDK> SDKS = new HashMap<>();
static {
SDKS.put(PayChannelEnum.PINGXX.getId(), new PingxxPaySDK());
}
public static AbstractPaySDK getSDK(Integer payChannel) {
AbstractPaySDK sdk = SDKS.get(payChannel);
if (sdk == null) {
throw new NullPointerException("找不到合适的 PaySDK " + payChannel);
}
return sdk;
}
}

View File

@ -1,112 +0,0 @@
package cn.iocoder.mall.pay.biz.dataobject;
import cn.iocoder.common.framework.dataobject.DeletableDO;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* DO
*/
@Data
@Accessors(chain = true)
public class PayTransactionDO extends DeletableDO {
/**
*
*/
private Integer id;
/**
*
*
* 线 appId
*
* 1. appId = 1024
* 2. appId = 2048
*/
private String appId;
/**
* 线
*
* 1. 使 String 线使 String
* 2. appId orderId
*/
private String orderId;
/**
* IP
*/
private String createIp;
/**
*
*/
private String orderSubject;
/**
*
*/
private String orderDescription;
/**
*
*/
private String orderMemo;
/**
*
*
* TODO
*/
private Integer price;
/**
*
*
* @see cn.iocoder.mall.pay.api.constant.PayTransactionStatusEnum
*/
private Integer status;
/**
*
*/
private Date expireTime;
/**
* 线
*/
private Date finishTime;
/**
*
*/
private String notifyUrl;
// TODO return url
/**
*
*
* @see PayTransactionExtensionDO#getId()
*/
private Integer extensionId;
/**
*
*
* @see cn.iocoder.mall.pay.api.constant.PayChannelEnum
*/
private Integer payChannel;
/**
*
*/
private Date paymentTime;
/**
*
*
*
*/
private Date notifyTime;
/**
*
*/
private String tradeNo;
// ========== 退款相关 ==========
/**
* 退
*/
private Integer refundTotal;
}

View File

@ -14,10 +14,7 @@
<artifactId>onemall</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<!-- <module>order</module>-->
<module>common</module>
<!-- <module>ops</module>-->
<!-- <module>pay</module>-->
<module>mall-dependencies</module>
<module>user-service-project</module>
<module>user-web-app</module>