Merge branch 'dev/dev_xp' into dev/dev
# Conflicts: # src/main/resources/paypal-sandbox.properties
This commit is contained in:
@@ -19,7 +19,7 @@ public interface PayPalCheckoutService {
|
||||
Boolean doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException;
|
||||
|
||||
String queryOrder(String orderNo) throws SerializeException;
|
||||
Order queryOrder(String orderNo) throws SerializeException;
|
||||
|
||||
Order captureOrder(String orderId) throws IOException;
|
||||
|
||||
@@ -28,5 +28,7 @@ public interface PayPalCheckoutService {
|
||||
String getOAuth();
|
||||
|
||||
void processOrder(String orderId);
|
||||
|
||||
void checkOrderStatus(String orderNo) throws SerializeException;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.ai.da.service.impl;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ai.da.common.config.PayPalClient;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.PayPalCheckoutConstant;
|
||||
import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.utils.RedisUtil;
|
||||
import com.ai.da.common.utils.paypalRequest.AuthenticationRequest;
|
||||
@@ -27,7 +26,6 @@ import com.paypal.payments.CapturesRefundRequest;
|
||||
import com.paypal.payments.RefundRequest;
|
||||
import com.paypal.payments.RefundsGetRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -329,7 +327,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
|
||||
* @return
|
||||
* @throws SerializeException
|
||||
*/
|
||||
public String queryOrder(String orderNo) throws SerializeException {
|
||||
public Order queryOrder(String orderNo) throws SerializeException {
|
||||
OrdersGetRequest request = new OrdersGetRequest(orderNo);
|
||||
|
||||
HttpResponse<Order> response = null;
|
||||
@@ -337,33 +335,31 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
|
||||
response = payPalClient.client(mode, clientId, clientSecret).execute(request);
|
||||
} catch (Exception e) {
|
||||
log.error("paypal订单查询失败,失败原因 ===> {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
System.out.println("Status Code: " + response.statusCode());
|
||||
System.out.println("Status: " + response.result().status());
|
||||
System.out.println("Order id: " + response.result().id());
|
||||
log.debug("Status Code: " + response.statusCode() + "\tStatus: " + response.result().status() + "\tOrder id: " + response.result().id());
|
||||
if (response.result().purchaseUnits().get(0).payments() != null) {
|
||||
List<Capture> captures = response.result().purchaseUnits().get(0).payments().captures();
|
||||
if (captures != null) {
|
||||
for (Capture capture : captures) {
|
||||
System.out.println("\t订单编号= " + capture.invoiceId() + "\tCapture Id= " + capture.id() + "\tCapture status= " + capture.status() + "\tCapture amount= " + capture.amount().currencyCode() + ":" + capture.amount().value());
|
||||
log.debug("\t订单编号= " + capture.invoiceId() + "\tCapture Id= " + capture.id() + "\tCapture status= " + capture.status() + "\tCapture amount= " + capture.amount().currencyCode() + ":" + capture.amount().value());
|
||||
}
|
||||
}
|
||||
List<Refund> refunds = response.result().purchaseUnits().get(0).payments().refunds();
|
||||
if (refunds != null) {
|
||||
for (Refund refund : refunds) {
|
||||
System.out.println("\t售后编号= " + refund.invoiceId() + "\tRefund Id= " + refund.id() + "\tRefund status= " + refund.status() + "\tRefund amount= " + refund.amount().currencyCode() + ":" + refund.amount().value());
|
||||
log.debug("\t售后编号= " + refund.invoiceId() + "\tRefund Id= " + refund.id() + "\tRefund status= " + refund.status() + "\tRefund amount= " + refund.amount().currencyCode() + ":" + refund.amount().value());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("Links: ");
|
||||
for (com.paypal.orders.LinkDescription link : response.result().links()) {
|
||||
System.out.println("\t" + link.rel() + ": " + link.href() + "\tCall Type: " + link.method());
|
||||
log.debug("Links: \t" + link.rel() + ": " + link.href() + "\tCall Type: " + link.method());
|
||||
}
|
||||
|
||||
System.out.println("Full response body:");
|
||||
|
||||
String json = new JSONObject(new Json().serialize(response.result())).toString(4);
|
||||
System.out.println(json);
|
||||
return null;
|
||||
log.info("Full response body: {}", json);
|
||||
return response.result();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,6 +594,49 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
|
||||
creditsService.buyCredits(orderInfo.getAccountId(), orderInfo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkOrderStatus(String orderNo) throws SerializeException {
|
||||
|
||||
log.warn("根据订单号核实订单状态 ===> {}", orderNo);
|
||||
|
||||
Order result = this.queryOrder(orderNo);
|
||||
|
||||
// 订单未创建 | 订单异常 | 订单创建过但未支付
|
||||
if(result == null || PayPalOrderStatusEnum.CREATED.getStatus().equals(result.status())){
|
||||
log.warn("核实订单未创建 ===> {}", orderNo);
|
||||
//更新本地订单状态
|
||||
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.TIMEOUT_CLOSED);
|
||||
return ;
|
||||
}
|
||||
|
||||
// 解析查单响应结果
|
||||
String tradeStatus = result.status();
|
||||
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
|
||||
|
||||
// 支付了,但还没完成
|
||||
if(PayPalOrderStatusEnum.APPROVED.getStatus().equals(tradeStatus)){
|
||||
log.warn("核实订单未支付 ===> {}", orderNo);
|
||||
// 更新商户端订单状态
|
||||
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.ORDER_PROCESSING);
|
||||
}
|
||||
|
||||
if(PayPalOrderStatusEnum.COMPLETED.getStatus().equals(tradeStatus)){
|
||||
log.warn("核实订单已支付 ===> {}", orderNo);
|
||||
//如果订单已支付,则更新商户端订单状态
|
||||
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.SUCCESS);
|
||||
//并记录支付日志
|
||||
paymentInfoService.createPaymentInfoForPayPal(result);
|
||||
// 添加积分变更记录
|
||||
creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(),
|
||||
CreditsEventsEnum.BUY_CREDITS.getName() + "--Paypal",
|
||||
CreditsEventsEnum.BUY_CREDITS.getValue(),
|
||||
"positive");
|
||||
// 更新积分
|
||||
creditsService.buyCredits(orderByOrderNo.getAccountId(),orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user