add: logic for stripe credit payment & rename pay module name to payment
This commit is contained in:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -1 +1,3 @@
|
||||
{}
|
||||
{
|
||||
"java.compile.nullAnalysis.mode": "automatic"
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
@@ -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);
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数编号获取详细信息
|
||||
*/
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.wfc.pay.domain;
|
||||
package org.wfc.payment.domain;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.wfc.pay.domain.vo;
|
||||
package org.wfc.payment.domain.vo;
|
||||
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
|
||||
@@ -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;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.wfc.pay.domain.vo;
|
||||
package org.wfc.payment.domain.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* 参数配置 数据层
|
||||
@@ -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
|
||||
@@ -1,14 +1,17 @@
|
||||
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
|
||||
*
|
||||
@@ -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
|
||||
@@ -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 参数配置信息
|
||||
@@ -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
|
||||
@@ -6,7 +6,7 @@ server:
|
||||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: wfc-pay
|
||||
name: wfc-payment
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: '@profileName@'
|
||||
@@ -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" />
|
||||
@@ -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" />
|
||||
Reference in New Issue
Block a user