提交 a6b686ef authored 作者: 吴德鹏's avatar 吴德鹏

update dpo

上级 64f4033f
......@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
......@@ -47,11 +48,49 @@ public class DpoPayController extends Controller {
this.config = config;
}
@GetMapping("/notify/web")
public void payNotifyWeb(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Result result = new Result();
// try {
System.out.println("DPO支付回调");
//订单号
String orderId = request.getParameter("CompanyRef");
//交易ID
String transId = request.getParameter("TransID");
//交易令牌
String transToken = request.getParameter("TransactionToken");
System.err.println("transID:" + transId);
System.err.println("transToken:" + transToken);
//logger.info("DPO支付:" + "开始支付校验");
Optional<TbCfOrder> byId = repository.findById(orderId);
String orderSource = null;
if (byId.isPresent()) {
orderSource = byId.get().getOrderSource().toString();
}
if (!StringUtils.isBlank(orderId) && !StringUtils.isBlank(transToken)) {
boolean verifyPay = verifyPay(transToken, orderId);
if (verifyPay) {
//logger.info("DPO支付:" + "支付校验成功");
// result.setMessage("Pay for success");
// result.setCode(ResultCodeEnum.SUCCESS.getCode());
response.sendRedirect(config.getSuccessUrl());
} else {
response.sendRedirect(config.getFailedUrl());
}
}
// } catch (Exception e) {
// return new Result<>(result,ResultCodeEnum.SERVICE_ERROR.getCode(), "Pay for failure");
// //logger.error("DPO支付回调发生异常--->>>" + e.toString());
// }
}
@GetMapping("/notify")
public Result payNotify(HttpServletRequest request, HttpServletResponse response) {
Result result = new Result();
try {
public void payNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
// Result result = new Result();
// try {
System.out.println("DPO支付回调");
//订单号
String orderId = request.getParameter("CompanyRef");
......@@ -62,30 +101,38 @@ public class DpoPayController extends Controller {
System.err.println("transID:" + transId);
System.err.println("transToken:" + transToken);
//logger.info("DPO支付:" + "开始支付校验");
Optional<TbCfOrder> byId = repository.findById(orderId);
String orderSource = null;
if (byId.isPresent()) {
orderSource = byId.get().getOrderSource().toString();
}
if (!StringUtils.isBlank(orderId) && !StringUtils.isBlank(transToken)) {
boolean verifyPay = verifyPay(transToken, orderId);
if (verifyPay) {
//logger.info("DPO支付:" + "支付校验成功");
result.setMessage("Pay for success");
result.setCode(ResultCodeEnum.SUCCESS.getCode());
return result;
// result.setMessage("Pay for success");
// result.setCode(ResultCodeEnum.SUCCESS.getCode());
response.sendRedirect(config.getMobileSuccessUrl());
} else {
response.sendRedirect(config.getMobileSuccessUrl());
}
}
return new Result<>(result,ResultCodeEnum.SERVICE_ERROR.getCode(), "Pay for failure");
} catch (Exception e) {
return new Result<>(result,ResultCodeEnum.SERVICE_ERROR.getCode(), "Pay for failure");
//logger.error("DPO支付回调发生异常--->>>" + e.toString());
}
// } catch (Exception e) {
// return new Result<>(result,ResultCodeEnum.SERVICE_ERROR.getCode(), "Pay for failure");
// //logger.error("DPO支付回调发生异常--->>>" + e.toString());
// }
}
@Transactional
public boolean verifyPay(String transToken, String orderId) {
boolean verify = false;
try {
// try {
Optional<TbCfOrder> byId = repository.findById(orderId);
if( !byId.isPresent() ) return false;
if (!byId.isPresent()) return false;
TbCfOrder order = byId.get();
......@@ -110,7 +157,9 @@ public class DpoPayController extends Controller {
//校验交易状态码
if (config.getSuccessCode().equals(resCode)) {
TbCfUserInfo user = this.user.user();
if( user.hasFcm() ){
System.out.println("this.user===========" + this.user);
System.out.println("user================" + user);
if (user != null && user.hasFcm()) {
sendNotification(user.getFcm(), "Order alert !!", "Order of $" + order.getRealityPay() + " has been successfully paid !!");
}
//获取缓存中的订单
......@@ -149,9 +198,9 @@ public class DpoPayController extends Controller {
logger.error("DPO支付:状态码--->>>" + resCode);
}
}
} catch (Exception e) {
logger.error("DPO支付:订单号" + orderId + "支付异常--->>>" + e.toString());
}
// } catch (Exception e) {
// logger.error("DPO支付:订单号" + orderId + "支付异常--->>>" + e.toString());
// }
return verify;
}
......@@ -185,18 +234,18 @@ public class DpoPayController extends Controller {
public Result payment(@RequestParam("orderId") String orderId) {
if( orderId == null || orderId.trim().isEmpty())
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(),"Parameters cannot be empty");
if (orderId == null || orderId.trim().isEmpty())
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(), "Parameters cannot be empty");
Optional<TbCfOrder> byId = repository.findById(orderId);
if(!byId.isPresent())
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(),"Order not found !");
if (!byId.isPresent())
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(), "Order not found !");
TbCfOrder order = byId.get();
if (OrderStatusEnum.PAID.getValue().equals(order.getPayStatus()) ){
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(),"Order has been paid !");
if (OrderStatusEnum.PAID.getValue().equals(order.getPayStatus())) {
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(), "Order has been paid !");
}
......@@ -206,7 +255,7 @@ public class DpoPayController extends Controller {
if (!amountFlag) {
// logger.error("DPO支付:订单号" + orderId + "传入的金额有误");
// payErrorInfo(result, "Wrong order amount");
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(),"Wrong order amount");
return new Result(ResultCodeEnum.ILLEGAL_ARGUMENT.getCode(), "Wrong order amount");
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//logger.info("DPO支付:订单号" + orderId + "创建交易,交易时间:" + dateFormat.format(new Date()));
......@@ -223,20 +272,20 @@ public class DpoPayController extends Controller {
String resCode = api3G.getString("Result");
String transToken = api3G.getString("TransToken");
if (config.getSuccessCode().equals(resCode)) {
HashMap<String,Object> resultMap = new HashMap<>();
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("transToken", transToken);
resultMap.put("payUrl", config.getRedirectUrl() + "?ID=" + transToken);
resultMap.put("orderInfo", order);
// result.setData(resultMap);
// logger.info("DPO支付:订单号" + orderId + "创建令牌成功");
return new Result<>(resultMap,"Pay success");
return new Result<>(resultMap, "Pay success");
}
// logger.info("DPO支付:订单号" + orderId + "创建令牌失败,状态码:" + resCode);
// payErrorInfo(result, "DPO支付:订单号" + orderId + "创建令牌失败,状态码:" + resCode);
}
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(),"DPO支付:订单号" + orderId + "创建令牌失败,状态码:");
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(), "DPO支付:订单号" + orderId + "创建令牌失败,状态码:");
}
private Map<String, Object> getParameters(String transToken) {
......@@ -259,13 +308,12 @@ public class DpoPayController extends Controller {
tranMap.put("PaymentCurrency", "USD");
tranMap.put("CompanyRef", order.getOrderId());
tranMap.put("CompanyRefUnique", 0);
logger.info("getOrderSource---------->>>>>>>>>>>>" + order.getOrderSource());
//回调地址
if (order.getOrderSource() != null && "1".equals(order.getOrderSource().toString())) {
tranMap.put("RedirectURL", config.getNotifyUrl());
} else if (order.getOrderSource() != null && "2".equals(order.getOrderSource().toString())) {
if (order.getOrderSource() != null && "2".equals(order.getOrderSource().toString())) {
tranMap.put("RedirectURL", config.getNotifyUrl() + "/web");
} else if (order.getOrderSource() != null && "3".equals(order.getOrderSource().toString())) {
tranMap.put("RedirectURL", config.getNotifyUrl() + "/mobile");
} else {
tranMap.put("RedirectURL", config.getNotifyUrl());
}
System.out.println("回调地址:" + tranMap.get("RedirectURL"));
//取消地址
......
......@@ -72,7 +72,7 @@ public class FlutterWaveController extends Controller {
public ResponseEntity<String> payForOrderByCard(@RequestParam("orderId") String orderId, @RequestBody FlutterWaveCard flutterWaveCard) {
RaveConstant.PUBLIC_KEY = PUBLIC_KEY;
RaveConstant.SECRET_KEY = SECRET_KEY;
RaveConstant.ENVIRONMENT = Environment.LIVE; //or live
RaveConstant.ENVIRONMENT = Environment.STAGING; //or live
// Result result = new Result();
Optional<TbCfOrder> byId = repository.findById(orderId);
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
......@@ -21,6 +22,7 @@ import java.util.*;
* @author lipengjun
* @date 2020-02-20 12:04:18
*/
@ToString
@Entity
@Getter
@Setter
......
......@@ -65,7 +65,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/api/auth/**","/search/image/**", "/itemStation/**", "/startPage/**", "/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**","/version/**","/flutterwave/notify/**").permitAll()
.authorizeRequests().antMatchers("/api/auth/**","/search/image/**", "/itemStation/**", "/startPage/**", "/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**","/version/**","/flutterwave/notify/**","/dpo/notify/**").permitAll()
.antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated();
......
package com.example.afrishop_v3.security.services;
import com.example.afrishop_v3.controllers.DpoPayController;
import com.example.afrishop_v3.models.TbCfUserInfo;
import com.example.afrishop_v3.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class AuthenticationUser implements IAuthenticationFacade {
private final UserRepository repository;
private static Logger logger = LoggerFactory.getLogger(AuthenticationUser.class);
public AuthenticationUser(UserRepository repository) {
this.repository = repository;
......@@ -20,12 +25,15 @@ public class AuthenticationUser implements IAuthenticationFacade {
return SecurityContextHolder.getContext().getAuthentication();
}
public TbCfUserInfo user(){
public TbCfUserInfo user() {
String name = getAuthentication().getName();
return repository.findFirstByFirebaseUidOrAccount(name,name).orElseGet(null);
// logger.info("登录的用户:" + name);
Optional<TbCfUserInfo> user = repository.findFirstByFirebaseUidOrAccount(name, name);
// logger.info("用户:" + user);
return user.isPresent() ? user.get() : null;
}
public String userId(){
public String userId() {
return user().getUserId();
}
}
server:
servlet:
context-path: /afrishop
port: 8099
spring:
datasource:
url: jdbc:mysql://159.138.48.71:3306/chinafrica_ref?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
......@@ -14,7 +19,8 @@ spring:
upload:
api: http://dev.diaosaas.com:8302/africa-shop/api/upload/uploadBase64
api: http://admin.afrieshop.com/api/upload/uploadBase64
#易境通物流
......@@ -36,40 +42,39 @@ logistics:
#DPO相关配置
dpo:
#创建交易请求
createToken: createToken
create_token: createToken
#校验交易请求
verifyToken: verifyToken
verify_token: verifyToken
#取消交易请求
cancelToken: cancelToken
cancel_token: cancelToken
#CompanyToken
company_token: 9F416C11-127B-4DE2-AC7F-D5710E4C5E0A
company_token: E6759E15-C2F3-4526-ADEF-8FC0017BB1C4
#请求成功的状态码
success_code: "000"
#DPO支付API
payment_api: https://secure1.sandbox.directpay.online/API/v6/
payment_api: https://secure.3gdirectpay.com/API/v6/
#重定向地址
redirect_url: https://secure1.sandbox.directpay.online/payv2.php
redirect_url: https://secure.3gdirectpay.com/pay.asp
#服务类型
service_type: 5525
service_type: 35711
#回调地址
notify_url: http://159.138.48.71:8080/zion/dpo/notify
notify_url: https://app.afrieshop.com/afrishop/dpo/notify
#取消地址
back_url: http://159.138.48.71:8080/zion/dpo/cancel
back_url: https://app.afrieshop.com/afrishop/dpo/cancel
#支付成功页面
success_url: https://dev.diaosaas.com/afrishop_web/payment_successful
success_url: https://www.afrieshop.com/payment_successful
#支付失败页面
failed_url: https://dev.diaosaas.com/afrishop_web/payment_failed
failed_url: https://www.afrieshop.com/payment_failed
#WEB支付成功页面
mobile_success_url: https://m.afrieshop.com/#/Paysuccess
mobile_success_url: https://m.afrieshop.com/Paysuccess
#WEB支付成功页面
mobile_failed_url: https://m.afrieshop.com/#/PayFail
mobile_failed_url: https://m.afrieshop.com/PayFail
flutter:
pay_url: https://ravesandboxapi.flutterwave.com/flwv3-pug/getpaidx/api/v2/verify
pay_url: https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify
refund_url: https://api.ravepay.co/gpx/merchant/transactions/refund
redirect_url: http://159.138.48.71:8080/zion/flutterwave/notify
public_key: FLWPUBK_TEST-e3cc948e7cb24b2128fca3b781f6fce0-X
secret_key: FLWSECK_TEST-f88371ca63a989a4af95625475a0d22d-X
redirect_url: https://www.afrieshop.com/afrishop/flutterwave/notify
public_key: FLWPUBK-ee0f5d653f5f33fc89e6caf9de6a4c34-X
secret_key: FLWSECK-c06cdc19526077f3855b76045ca77de3-X
server:
servlet:
context-path: /afrishop
port: 8099
spring:
datasource:
url: jdbc:mysql://159.138.48.71:3306/chinafrica_ref?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
......@@ -14,7 +19,8 @@ spring:
upload:
api: http://dev.diaosaas.com:8302/africa-shop/api/upload/uploadBase64
api: http://admin.afrieshop.com/api/upload/uploadBase64
#易境通物流
......@@ -52,23 +58,23 @@ dpo:
#服务类型
service_type: 35711
#回调地址
notify_url: http://159.138.48.71:8080/zion/dpo/notify
notify_url: https://app.afrieshop.com/afrishop/dpo/notify
#取消地址
back_url: http://159.138.48.71:8080/zion/dpo/cancel
back_url: https://app.afrieshop.com/afrishop/dpo/cancel
#支付成功页面
success_url: https://www.afrieshop.com/payment_successful
#支付失败页面
failed_url: https://www.afrieshop.com/payment_failed
#WEB支付成功页面
mobile_success_url: https://m.afrieshop.com/#/Paysuccess
mobile_success_url: https://m.afrieshop.com/Paysuccess
#WEB支付成功页面
mobile_failed_url: https://m.afrieshop.com/#/PayFail
mobile_failed_url: https://m.afrieshop.com/PayFail
flutter:
pay_url: https://api.ravepay.co/flwv3-pug/getpaidx/api/v2/verify
refund_url: https://api.ravepay.co/gpx/merchant/transactions/refund
redirect_url: http://159.138.48.71:8080/zion/flutterwave/notify
redirect_url: https://www.afrieshop.com/afrishop/flutterwave/notify
public_key: FLWPUBK-ee0f5d653f5f33fc89e6caf9de6a4c34-X
secret_key: FLWSECK-c06cdc19526077f3855b76045ca77de3-X
spring:
datasource:
url: jdbc:mysql://47.106.242.175:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url: jdbc:mysql://159.138.48.71:3306/chinafrica_ref?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
driver-class-name : com.mysql.cj.jdbc.Driver
password: diaoyun666
driver-class-name: com.mysql.cj.jdbc.Driver
password: Diaoyunnuli.8
redis:
#Redis数据库分片索引(默认为0)
database: 0
host: 127.0.0.1
port: 6379
password:
password: AfriShop_date@2#!&
upload:
api: http://admin.afrieshop.com/api/upload/uploadBase64
api: http://dev.diaosaas.com:8302/africa-shop/api/upload/uploadBase64
#易境通物流
......@@ -52,23 +51,23 @@ dpo:
#服务类型
service_type: 5525
#回调地址
notify_url: http://165.22.82.105:7000/zion/dpo/notify
notify_url: https://app.afrieshop.com/afrishop/dpo/notify
#取消地址
back_url: http://165.22.82.105:7000/zion/dpo/cancel
back_url: https://app.afrieshop.com/afrishop/dpo/cancel
#支付成功页面
success_url: https://dev.diaosaas.com/afrishop_web/payment_successful
success_url: https://www.afrieshop.com/payment_successful
#支付失败页面
failed_url: https://dev.diaosaas.com/afrishop_web/payment_failed
failed_url: https://www.afrieshop.com/payment_failed
#WEB支付成功页面
mobile_success_url: https://m.afrieshop.com/#/Paysuccess
mobile_success_url: https://m.afrieshop.com/Paysuccess
#WEB支付成功页面
mobile_failed_url: https://m.afrieshop.com/#/PayFail
mobile_failed_url: https://m.afrieshop.com/PayFail
flutter:
pay_url: https://ravesandboxapi.flutterwave.com/flwv3-pug/getpaidx/api/v2/verify
refund_url: https://api.ravepay.co/gpx/merchant/transactions/refund
redirect_url: http://165.22.82.105:7000/zion/flutterwave/notify
redirect_url: https://www.afrieshop.com/afrishop/flutterwave/notify
public_key: FLWPUBK_TEST-e3cc948e7cb24b2128fca3b781f6fce0-X
secret_key: FLWSECK_TEST-f88371ca63a989a4af95625475a0d22d-X
server.servlet.context-path=/zion
server.servlet.context-path=/afrishop
spring.jpa.hibernate.ddl-auto=update
server.port = 7000
server.port = 8099
#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/afrishop_test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
#spring.datasource.username=root
#spring.datasource.password=Diaoyunnuli.8
......
package com.example.afrishop_v3;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AfrishopV3ApplicationTests {
@Test
void contextLoads() {
}
}
//package com.example.afrishop_v3;
//
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//
//@SpringBootTest
//class AfrishopV3ApplicationTests {
//
// @Test
// void contextLoads() {
//
//
// }
//
//}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论