|
@@ -19,14 +19,18 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.yaml.snakeyaml.events.Event;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.sql.Wrapper;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
-import static com.szwl.constant.AirwallexConstant.WEBHOOKS_KEY;
|
|
|
+import static com.szwl.common.WebhooksCommon.WEBHOOKS_KEY_PAYMENT_INTENT;
|
|
|
+import static com.szwl.common.WebhooksCommon.WEBHOOKS_KEY_REFUND;
|
|
|
import static com.szwl.constant.AirwallexConstant.ENV;
|
|
|
|
|
|
|
|
@@ -73,7 +77,7 @@ public class WebhookController {
|
|
|
String signature = request.getHeader("x-signature");
|
|
|
|
|
|
// Get your secret
|
|
|
- String secret = getSecret();
|
|
|
+ String secret = getSecretRefund();
|
|
|
|
|
|
if (HmacUtils.hmacSha256Hex(secret, valueToDigest.toString()).equals(signature)) {
|
|
|
|
|
@@ -81,14 +85,18 @@ public class WebhookController {
|
|
|
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
|
|
|
|
-
|
|
|
JSONObject jsonObject = JSON.parseObject(payload);
|
|
|
- String data = jsonObject.getString("data");
|
|
|
- JSONObject jsonObject1 = JSON.parseObject(data);
|
|
|
- String dataObject = jsonObject1.getString("object");
|
|
|
- JSONObject jsonObject2 = JSON.parseObject(dataObject);
|
|
|
- String refundId = jsonObject2.getString("id");
|
|
|
- String status = jsonObject2.getString("status");
|
|
|
+ JSONObject object = jsonObject.getJSONObject("data").getJSONObject("object");
|
|
|
+ String refundId = object.getString("id");
|
|
|
+ String status = object.getString("status");
|
|
|
+
|
|
|
+// JSONObject jsonObject = JSON.parseObject(payload);
|
|
|
+// String data = jsonObject.getString("data");
|
|
|
+// JSONObject jsonObject1 = JSON.parseObject(data);
|
|
|
+// String dataObject = jsonObject1.getString("object");
|
|
|
+// JSONObject jsonObject2 = JSON.parseObject(dataObject);
|
|
|
+// String refundId = jsonObject2.getString("id");
|
|
|
+// String status = jsonObject2.getString("status");
|
|
|
|
|
|
// 如果退款成功
|
|
|
if (status.equals("RECEIVED") || status.equals("ACCEPTED") || status.equals("SUCCEEDED")) {
|
|
@@ -97,6 +105,9 @@ public class WebhookController {
|
|
|
lambdaQueryWrapper.eq(TOrderAbroad::getRefundId, refundId);
|
|
|
TOrderAbroad orderAbroad = tOrderAbroadService.getOne(lambdaQueryWrapper);
|
|
|
|
|
|
+ if (Objects.isNull(orderAbroad)) {
|
|
|
+ return "订单为空/error";
|
|
|
+ }
|
|
|
// 设置订单支付状态为 已退款
|
|
|
orderAbroad.setPayStatus(3);
|
|
|
tOrderAbroadService.updateById(orderAbroad);
|
|
@@ -136,7 +147,7 @@ public class WebhookController {
|
|
|
String signature = request.getHeader("x-signature");
|
|
|
|
|
|
// Get your secret
|
|
|
- String secret = getSecret();
|
|
|
+ String secret = getSecretPaymentInent();
|
|
|
|
|
|
if (HmacUtils.hmacSha256Hex(secret, valueToDigest.toString()).equals(signature)) {
|
|
|
|
|
@@ -146,15 +157,40 @@ public class WebhookController {
|
|
|
responseBody = "payment intent ok";
|
|
|
|
|
|
// 如果用户支付成功,将订单支付状态改成 1已支付。
|
|
|
- JSONObject jsonObject = JSON.parseObject(payload);
|
|
|
- String data = jsonObject.getString("data");
|
|
|
- JSONObject jsonObject1 = JSON.parseObject(data);
|
|
|
- String dataObject = jsonObject1.getString("object");
|
|
|
- JSONObject jsonObject2 = JSON.parseObject(dataObject);
|
|
|
- String requestId = jsonObject2.getString("request_id");
|
|
|
- QueryWrapper<TOrderAbroad> tOrderAbroadQueryWrapper = new QueryWrapper<>();
|
|
|
- tOrderAbroadQueryWrapper.eq("request_id",requestId);
|
|
|
- TOrderAbroad orderAbroad = tOrderAbroadService.getOne(tOrderAbroadQueryWrapper);
|
|
|
+// JSONObject jsonObj = JSON.parseObject(payload);
|
|
|
+// String data = jsonObj.getString("data");
|
|
|
+// JSONObject jsonObject1 = JSON.parseObject(data);
|
|
|
+// String dataObject = jsonObject1.getString("object");
|
|
|
+// JSONObject jsonObject2 = JSON.parseObject(dataObject);
|
|
|
+// String paymentIntentId = jsonObject2.getString("id");
|
|
|
+// JSONObject data1 = jsonObj.getJSONObject("data");
|
|
|
+// JSONObject object = data1.getJSONObject("object");
|
|
|
+// String paymentIntentId = object.getString("id");
|
|
|
+// QueryWrapper<TOrderAbroad> tOrderAbroadQueryWrapper = new QueryWrapper<>();
|
|
|
+// tOrderAbroadQueryWrapper.eq("payment_intent_id",paymentIntentId);
|
|
|
+ String paymentIntentId = JSON.parseObject(payload).getJSONObject("data").getJSONObject("object").getString("id");
|
|
|
+// JSONObject jsonObj = Optional.ofNullable(jsonObject)
|
|
|
+// .flatMap(jsonObject1 -> Optional.ofNullable(jsonObject1.getJSONObject("data")))
|
|
|
+// .flatMap(jsonObject1 -> Optional.ofNullable(jsonObject1.getJSONObject("object")))
|
|
|
+// .flatMap(jsonObject1 -> Optional.ofNullable(jsonObject1.getJSONObject("id")))
|
|
|
+// .orElse(null);
|
|
|
+// JSONObject idJson = Optional.ofNullable(jsonObj)
|
|
|
+// .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("data")))
|
|
|
+// .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("object")))
|
|
|
+// .flatMap(jsonObject -> Optional.ofNullable(jsonObject.getJSONObject("id")))
|
|
|
+// .orElse(null);
|
|
|
+// JSONObject idJson = Optional.ofNullable(jsonObj)
|
|
|
+// .map(jsonObject -> jsonObject.getJSONObject("data"))
|
|
|
+// .map(jsonObject -> jsonObject.getJSONObject("object"))
|
|
|
+// .map(jsonObject -> jsonObject.getJSONObject("id"))
|
|
|
+// .orElse(null);
|
|
|
+// String paymentIntentId = JSON.toJSONString(idJson);
|
|
|
+ LambdaQueryWrapper<TOrderAbroad> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ lambdaQueryWrapper.eq(TOrderAbroad::getPaymentIntentId, paymentIntentId);
|
|
|
+// QueryWrapper<TOrderAbroad> lambdaQueryWrapper = new QueryWrapper<>();
|
|
|
+// lambdaQueryWrapper.eq("payment_intent_id", paymentIntentId);
|
|
|
+ TOrderAbroad orderAbroad = tOrderAbroadService.getOne(lambdaQueryWrapper);
|
|
|
+
|
|
|
System.out.println(orderAbroad);
|
|
|
|
|
|
orderAbroad.setPayStatus(1);
|
|
@@ -173,15 +209,17 @@ public class WebhookController {
|
|
|
|
|
|
// TODO: 验签失败,先retrieve手动获取订单信息,如果成功,走上面那一套,如果失败不做处理
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
- System.out.println(response);
|
|
|
- System.out.println(responseBody);
|
|
|
+// System.out.println(response);
|
|
|
+// System.out.println(responseBody);
|
|
|
return responseBody;
|
|
|
}
|
|
|
|
|
|
- private String getSecret() {
|
|
|
- return WEBHOOKS_KEY;
|
|
|
+ private String getSecretPaymentInent() {
|
|
|
+ return WEBHOOKS_KEY_PAYMENT_INTENT;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getSecretRefund() {
|
|
|
+ return WEBHOOKS_KEY_REFUND;
|
|
|
}
|
|
|
}
|