|
@@ -3,56 +3,91 @@ package com.szwl.controller;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.szwl.common.AccessTokenCommon;
|
|
|
import com.szwl.constant.AirwallexConstant;
|
|
|
import com.szwl.model.bean.PaymentIntentRequestBody;
|
|
|
import com.szwl.model.bean.RefundRequestBody;
|
|
|
import com.szwl.model.bo.R;
|
|
|
import com.szwl.model.bo.ResponseModel;
|
|
|
+import com.szwl.model.dto.*;
|
|
|
import com.szwl.model.entity.TOrderAbroad;
|
|
|
import com.szwl.model.utils.AccessTokenThreadUtil;
|
|
|
import com.szwl.service.AirwallexService;
|
|
|
import com.szwl.service.TAdminService;
|
|
|
import com.szwl.service.TOrderAbroadService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiModelProperty;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
-import static com.szwl.constant.ResponseCodesEnum.L0006;
|
|
|
-
|
|
|
//@CrossOrigin
|
|
|
-@Api(value = "/api/airwallexPay", tags = {"空中云汇" })
|
|
|
+@Api(value = "/api/airwallexPay", tags = {"空中云汇"})
|
|
|
@RestController
|
|
|
@RequestMapping("/api/airwallexPay")
|
|
|
@Slf4j
|
|
|
public class AirwallexPayController {
|
|
|
@Value("${test.value:bbb}")
|
|
|
private String testValue;
|
|
|
- @Autowired
|
|
|
+
|
|
|
TAdminService tAdminService;
|
|
|
- @Autowired
|
|
|
+
|
|
|
AirwallexService airwallexService;
|
|
|
- @Resource
|
|
|
+
|
|
|
TOrderAbroadService tOrderAbroadService;
|
|
|
|
|
|
+ public AirwallexPayController(TAdminService tAdminService, AirwallexService airwallexService, TOrderAbroadService tOrderAbroadService) {
|
|
|
+ this.tAdminService = tAdminService;
|
|
|
+ this.airwallexService = airwallexService;
|
|
|
+ this.tOrderAbroadService = tOrderAbroadService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "创建收款人")
|
|
|
+ @PostMapping("/caBeneficiary")
|
|
|
+ public JsonNode caBeneficiary(@RequestBody CaBeneficiaryRequestDTO requestDTO) {
|
|
|
+
|
|
|
+ BeneficiaryDTO beneficiary = requestDTO.getBeneficiary();
|
|
|
+ List<String> paymentMethods = requestDTO.getPaymentMethods();
|
|
|
+ String nickname = requestDTO.getNickname();
|
|
|
+ String resp = airwallexService.caBeneficiary(beneficiary, nickname, paymentMethods);
|
|
|
+
|
|
|
+ try {
|
|
|
+ JsonNode jsonNode = new ObjectMapper().readTree(resp);
|
|
|
+ return jsonNode;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+// JSONObject jsonObject = JSON.parseObject(resp);
|
|
|
+// String beneficiaryId = jsonObject.getString("beneficiary_id");
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取authCode")
|
|
|
+ @PostMapping("/getAuthCode")
|
|
|
+ public JsonNode getAuthCode(@RequestBody GetAuthCodeDTO getAuthCodeDTO) {
|
|
|
+ String codeChallenge = getAuthCodeDTO.getCodeChallenge();
|
|
|
+ String[] scope = getAuthCodeDTO.getScope();
|
|
|
+ String resp = airwallexService.getAuthCode(codeChallenge, scope);
|
|
|
+ try {
|
|
|
+ JsonNode jsonNode = new ObjectMapper().readTree(resp);
|
|
|
+ return jsonNode;
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
// @GetMapping("/getAccessToken")
|
|
|
// public ResponseModel<?> getAccessToken() {
|
|
|
// String accessToken = airwallexService.getAccessToken();
|
|
@@ -81,6 +116,9 @@ public class AirwallexPayController {
|
|
|
// return R.fail(L0006);
|
|
|
// }
|
|
|
|
|
|
+ // 如果是海外客户,使用的是 Airwallex ,就要判断他有没有设置分销
|
|
|
+ // 在 Airwallex 支付之前,要先判断
|
|
|
+
|
|
|
BigDecimal amount = paymentIntentRequestBody.getAmount();
|
|
|
String currency = paymentIntentRequestBody.getCurrency();
|
|
|
String merchantOrderId = paymentIntentRequestBody.getMerchantOrderId();
|
|
@@ -178,12 +216,12 @@ public class AirwallexPayController {
|
|
|
// String city = JSON.toJSONString(cityJson);
|
|
|
|
|
|
Map<String, Object> intentDetails = new HashMap<>();
|
|
|
- intentDetails.put("amount",amount);
|
|
|
- intentDetails.put("currency",currency);
|
|
|
+ intentDetails.put("amount", amount);
|
|
|
+ intentDetails.put("currency", currency);
|
|
|
// intentDetails.put("state",state);
|
|
|
- intentDetails.put("type",type);
|
|
|
- intentDetails.put("createdAt",createdAt);
|
|
|
- intentDetails.put("status",status);
|
|
|
+ intentDetails.put("type", type);
|
|
|
+ intentDetails.put("createdAt", createdAt);
|
|
|
+ intentDetails.put("status", status);
|
|
|
|
|
|
return new JSONObject(intentDetails);
|
|
|
}
|
|
@@ -191,7 +229,7 @@ public class AirwallexPayController {
|
|
|
|
|
|
@ApiOperation(value = "发起退款")
|
|
|
@PostMapping("/createARefund")
|
|
|
- ResponseModel<String> createARefund(@RequestBody RefundRequestBody refundRequestBody) {
|
|
|
+ public ResponseModel<String> createARefund(@RequestBody RefundRequestBody refundRequestBody) {
|
|
|
log.info("发起退款");
|
|
|
String requestId = UUID.randomUUID().toString().trim().replaceAll("-", "");
|
|
|
|
|
@@ -207,7 +245,7 @@ public class AirwallexPayController {
|
|
|
lambdaQueryWrapper.eq(TOrderAbroad::getPaymentIntentId, paymentIntentId);
|
|
|
TOrderAbroad orderAbroad = tOrderAbroadService.getOne(lambdaQueryWrapper);
|
|
|
|
|
|
- if(orderAbroad == null) {
|
|
|
+ if (orderAbroad == null) {
|
|
|
return R.fail("订单为空/error");
|
|
|
}
|
|
|
|
|
@@ -311,17 +349,43 @@ public class AirwallexPayController {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// @ApiOperation(value = "新建一笔转账")
|
|
|
-// @PostMapping()
|
|
|
-// public R caPayment(@RequestBody PaymentRequestBody paymentRequestBody) {
|
|
|
-// log.info("发起一笔转账");
|
|
|
-//
|
|
|
-//
|
|
|
-// airwallexService.caPayment()
|
|
|
-//
|
|
|
-//
|
|
|
-// return R.ok();
|
|
|
-// }
|
|
|
+ @ApiOperation(value = "新建一笔付款")
|
|
|
+ @PostMapping("/caPayment")
|
|
|
+ public R caPayment(@RequestBody CaPaymentRequestDTO caPaymentRequestDTO) {
|
|
|
+
|
|
|
+ String resp = airwallexService.caPayment(caPaymentRequestDTO);
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode jsonNode = null;
|
|
|
+ try {
|
|
|
+ jsonNode = objectMapper.readTree(resp);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 断言确保 jsonNode 不为 null
|
|
|
+ assert jsonNode != null;
|
|
|
+ String paymentId = jsonNode.get("payment_id").asText();
|
|
|
+
|
|
|
+ // 返回 payment_id
|
|
|
+ return R.ok(paymentId);
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ @ApiOperation(value = "查询支付结果")
|
|
|
+ @GetMapping("/getPaymentById/{payment_id}")
|
|
|
+ public R getPaymentById(@PathVariable("payment_id") String paymentId) {
|
|
|
+
|
|
|
+ String resp = airwallexService.getPaymentById(paymentId);
|
|
|
+
|
|
|
+ return R.ok(resp);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询当前账户余额")
|
|
|
+ @GetMapping("/getCurrentBalances")
|
|
|
+ public R getCurrentBalances() {
|
|
|
+
|
|
|
+ String resp = airwallexService.getCurrentBalances();
|
|
|
+
|
|
|
+ return R.ok(resp);
|
|
|
+ }
|
|
|
+}
|