2
0

add: logic for stripe credit payment & rename pay module name to payment

This commit is contained in:
2024-11-27 18:39:54 +08:00
parent dd62a85f51
commit fd0a93dff8
23 changed files with 163 additions and 39 deletions

View File

@@ -1 +1,3 @@
{}
{
"java.compile.nullAnalysis.mode": "automatic"
}

View File

@@ -14,6 +14,7 @@
<module>wfc-job</module>
<module>wfc-file</module>
<module>wfc-modules-user</module>
<module>wfc-pay</module>
</modules>
<artifactId>wfc-modules</artifactId>

View File

@@ -9,10 +9,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>wfc-modules-pay</artifactId>
<artifactId>wfc-modules-payment</artifactId>
<description>
wfc-modules-pay
wfc-modules-payment
</description>
<dependencies>

View File

@@ -1,10 +1,12 @@
package org.wfc.pay;
package org.wfc.payment;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.wfc.common.security.annotation.EnableCustomConfig;
import org.wfc.common.security.annotation.EnableRyFeignClients;
import org.wfc.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
/**
* Pay module
@@ -17,6 +19,14 @@ import org.wfc.common.swagger.annotation.EnableCustomSwagger2;
@SpringBootApplication
public class WfcPayApplication
{
// @Autowired
// private LocaleMessageUtil localeMessageUtil;
// @GetMapping("/greeting")
// public String greeting() {
// return localeMessageUtil.getMessage("greeting.message");
// }
public static void main(String[] args)
{
SpringApplication.run(WfcPayApplication.class, args);

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.controller;
package org.wfc.payment.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,8 +17,11 @@ import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.pay.domain.CreditCard;
import org.wfc.pay.service.ICreditCardService;
import org.wfc.payment.domain.CreditCard;
import org.wfc.payment.domain.PaymentRequest;
import org.wfc.payment.service.ICreditCardService;
import org.springframework.http.ResponseEntity;
import org.wfc.common.core.constant.HttpStatus;
/**
* Credit card pay controller
@@ -26,12 +29,23 @@ import org.wfc.pay.service.ICreditCardService;
* @author simon
*/
@RestController
@RequestMapping("/creditCard")
@RequestMapping("/payments")
public class CreditCardController extends BaseController
{
@Autowired
private ICreditCardService ccPayService;
@PostMapping("/creditCard")
public ResponseEntity<String> processPayment(@RequestBody PaymentRequest paymentRequest) {
// 调用支付服务处理支付请求
boolean paymentResult = ccPayService.processPayment(paymentRequest);
if (paymentResult) {
return ResponseEntity.ok("Payment successful");
} else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Payment failed");
}
}
/**
* 根据参数编号获取详细信息
*/

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.controller;
package org.wfc.payment.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -13,8 +13,8 @@ import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.pay.domain.PayPal;
import org.wfc.pay.service.IPayPalService;
import org.wfc.payment.domain.PayPal;
import org.wfc.payment.service.IPayPalService;
/**

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.domain;
package org.wfc.payment.domain;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.domain;
package org.wfc.payment.domain;
import org.wfc.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;

View File

@@ -0,0 +1,65 @@
package org.wfc.payment.domain;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.wfc.common.core.annotation.Excel;
import org.wfc.common.core.annotation.Excel.ColumnType;
import org.wfc.common.core.web.domain.BaseEntity;
/**
* 参数配置表 sys_config
*
* @author wfc
*/
public class PaymentRequest extends BaseEntity {
private String cardNumber;
private String cardHolderName;
private String expirationDate;
private String cvv;
private int amount; // 以分为单位
// Getters and Setters
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber = cardNumber;
}
public String getCardHolderName() {
return cardHolderName;
}
public void setCardHolderName(String cardHolderName) {
this.cardHolderName = cardHolderName;
}
public String getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public String getCvv() {
return cvv;
}
public void setCvv(String cvv) {
this.cvv = cvv;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.domain.vo;
package org.wfc.payment.domain.vo;
import org.wfc.common.core.utils.StringUtils;

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.domain.vo;
package org.wfc.payment.domain.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.domain.vo;
package org.wfc.payment.domain.vo;
import java.io.Serializable;
import java.util.List;

View File

@@ -1,7 +1,7 @@
package org.wfc.pay.mapper;
package org.wfc.payment.mapper;
import java.util.List;
import org.wfc.pay.domain.CreditCard;
import org.wfc.payment.domain.CreditCard;
/**
* 参数配置 数据层

View File

@@ -1,6 +1,6 @@
package org.wfc.pay.mapper;
package org.wfc.payment.mapper;
import org.wfc.pay.domain.PayPal;
import org.wfc.payment.domain.PayPal;
/**
* Paypal mapper

View File

@@ -1,17 +1,20 @@
package org.wfc.pay.service;
import org.wfc.pay.domain.CreditCard;
package org.wfc.payment.service;
import org.wfc.payment.domain.CreditCard;
import org.wfc.payment.domain.PaymentRequest;
/**
* Credit card pay service layer
*
* @author wfc
*/
public interface ICreditCardService
public interface ICreditCardService
{
public boolean processPayment(PaymentRequest paymentRequest);
/**
* select credit card information
*
*
* @param userId User ID
* @return Credit card info
*/

View File

@@ -1,6 +1,6 @@
package org.wfc.pay.service;
package org.wfc.payment.service;
import org.wfc.pay.domain.PayPal;
import org.wfc.payment.domain.PayPal;
/**
* Paypal pay service layer

View File

@@ -1,4 +1,4 @@
package org.wfc.pay.service.impl;
package org.wfc.payment.service.impl;
import java.util.Collection;
import java.util.List;
@@ -11,9 +11,17 @@ import org.wfc.common.core.exception.ServiceException;
import org.wfc.common.core.text.Convert;
import org.wfc.common.core.utils.StringUtils;
import org.wfc.common.redis.service.RedisService;
import org.wfc.pay.domain.CreditCard;
import org.wfc.pay.mapper.CreditCardMapper;
import org.wfc.pay.service.ICreditCardService;
import org.wfc.payment.domain.CreditCard;
import org.wfc.payment.domain.PaymentRequest;
import org.wfc.payment.mapper.CreditCardMapper;
import org.wfc.payment.service.ICreditCardService;
import java.util.HashMap;
import java.util.Map;
import com.stripe.Stripe;
import com.stripe.model.Charge;
import com.stripe.exception.StripeException;
import com.stripe.param.ChargeCreateParams;
import org.springframework.beans.factory.annotation.Autowired;
/**
* 参数配置 服务层实现
@@ -25,9 +33,30 @@ public class CreditCardServiceImpl implements ICreditCardService
{
@Autowired
private CreditCardMapper creditCardMapper;
public void SetStripeApiKey(String apiKey) {
Stripe.apiKey = apiKey;
}
@Override
public boolean processPayment(PaymentRequest paymentRequest) {
ChargeCreateParams params = ChargeCreateParams.builder()
.setAmount((long) paymentRequest.getAmount())
.setCurrency("usd")
.setSource(paymentRequest.getCardNumber()) // 这里假设前端传递的是支付令牌
.setDescription("Charge for " + paymentRequest.getCardHolderName())
.build();
try {
Charge charge = Charge.create(params);
return charge.getPaid();
} catch (StripeException e) {
e.printStackTrace();
return false;
}
}
/**
* 查询参数置信息
* 查询参数置信息
*
* @param creditCardId 参数配置ID
* @return 参数配置信息

View File

@@ -1,10 +1,10 @@
package org.wfc.pay.service.impl;
package org.wfc.payment.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wfc.pay.mapper.PayPalMapper;
import org.wfc.pay.service.IPayPalService;
import org.wfc.pay.domain.PayPal;
import org.wfc.payment.mapper.PayPalMapper;
import org.wfc.payment.service.IPayPalService;
import org.wfc.payment.domain.PayPal;
/**
* PayPal service implementation

View File

@@ -6,7 +6,7 @@ server:
spring:
application:
# 应用名称
name: wfc-pay
name: wfc-payment
profiles:
# 环境配置
active: '@profileName@'

View File

@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.wfc.pay.mapper.CreditCardMapper">
<mapper namespace="org.wfc.payment.mapper.CreditCardMapper">
<resultMap type="CreditCard" id="CreditCardResult">
<id property="configId" column="config_id" />

View File

@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.wfc.pay.mapper.PayPalMapper">
<mapper namespace="org.wfc.payment.mapper.PayPalMapper">
<resultMap type="PayPal" id="PayPalResult">
<id property="deptId" column="dept_id" />