|
|
@@ -0,0 +1,34 @@
|
|
|
+package com.kxs.common.pay.handlers;
|
|
|
+
|
|
|
+import com.kxs.common.core.exception.GlobalCustomerException;
|
|
|
+import com.kxs.common.pay.enums.PayPlatformEnum;
|
|
|
+import com.kxs.common.pay.service.PayService;
|
|
|
+import com.kxs.common.pay.service.ali.AliPayService;
|
|
|
+import com.kxs.common.pay.service.wechat.WxPayService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 支付工厂类
|
|
|
+ *
|
|
|
+ * @author 没秃顶的码农
|
|
|
+ * @date 2024-04-26
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class PaymentFactory {
|
|
|
+
|
|
|
+ private final AliPayService aliPayService;
|
|
|
+
|
|
|
+ private final WxPayService wxPayService;
|
|
|
+
|
|
|
+ public PayService getPayService(String payMethod) {
|
|
|
+ if (payMethod.equalsIgnoreCase(PayPlatformEnum.ALIPAY.getType())) {
|
|
|
+ return aliPayService;
|
|
|
+ } else if (payMethod.equalsIgnoreCase(PayPlatformEnum.WX.getType())) {
|
|
|
+ return wxPayService;
|
|
|
+ } else {
|
|
|
+ throw new GlobalCustomerException("Invalid payment method");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|