From d329806652239b5afb8f5f28c6002703cbec8754 Mon Sep 17 00:00:00 2001 From: zhangtao <1316069495@qq.com> Date: Thu, 18 Mar 2021 16:02:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20alipay+=20=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/impls/AlipayChannelsConfig.java | 68 +++++++++++++++++++ .../core/impls/ClientManagerImpl.java | 29 +++++--- .../merchants/web/AlipayConfigController.java | 31 +++++++++ 3 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/AlipayChannelsConfig.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/merchants/web/AlipayConfigController.java diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/AlipayChannelsConfig.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/AlipayChannelsConfig.java new file mode 100644 index 000000000..5081dd21e --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/AlipayChannelsConfig.java @@ -0,0 +1,68 @@ +package au.com.royalpay.payment.manage.merchants.core.impls; + +import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper; +import com.alibaba.fastjson.JSONObject; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Optional; + +/** + * @Description + * @title: + * @Date 2021/1/28 11:15 + * @author: zhangTao + */ +@Component +public class AlipayChannelsConfig { + + @Resource + private ClientConfigMapper clientConfigMapper; + + + public boolean isMandatoryAlipayOnline(int clientId) { + Optional optionalClientConfigInfo = getClientConfig(clientId); + if (optionalClientConfigInfo.isPresent()){ + JSONObject clientConfigInfo = optionalClientConfigInfo.get(); + if (clientConfigInfo.getBooleanValue("mandatory_alipay_online")){ + return true; + } + } + return false; + } + + + + public void modifyMandatoryAlipayOnline(int clientId ,boolean mandatoryAlipayOnlineStatus){ + JSONObject mandatoryAlipayOnlineConfig = new JSONObject(); + mandatoryAlipayOnlineConfig.put("client_id",clientId); + mandatoryAlipayOnlineConfig.put("mandatory_alipay_online",mandatoryAlipayOnlineStatus); + clientConfigMapper.update(mandatoryAlipayOnlineConfig); + } + + + public boolean isAlipayPlus(int clientId) { + Optional optionalClientConfigInfo = getClientConfig(clientId); + if (optionalClientConfigInfo.isPresent()){ + JSONObject clientConfigInfo = optionalClientConfigInfo.get(); + if (clientConfigInfo.getBooleanValue("alipay_payment_channels")){ + return true; + } + } + return false; + } + + public void modifyAlipayPaymentChannels(int clientId ,boolean alipayPaymentChannelsStatus){ + JSONObject mandatoryAlipayOnlineConfig = new JSONObject(); + mandatoryAlipayOnlineConfig.put("client_id",clientId); + mandatoryAlipayOnlineConfig.put("alipay_payment_channels",alipayPaymentChannelsStatus); + clientConfigMapper.update(mandatoryAlipayOnlineConfig); + } + + + private Optional getClientConfig(int clientId) { + Optional optionalClientConfigInfo = Optional.of(clientConfigMapper.find(clientId)); + return optionalClientConfigInfo; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 325fcfd50..7b0de4e2b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -2,7 +2,6 @@ package au.com.royalpay.payment.manage.merchants.core.impls; import au.com.royalpay.payment.channels.alipay.config.AlipayConfig; import au.com.royalpay.payment.channels.alipay.config.AlipayEnvironment; -import au.com.royalpay.payment.channels.alipay.runtime.AlipayCommonApi; import au.com.royalpay.payment.channels.alipay.runtime.AlipayOnlineApi; import au.com.royalpay.payment.channels.alipay.runtime.AlipayRetailApi; import au.com.royalpay.payment.channels.alipay.runtime.entity.AlipayMerchantEntity; @@ -21,16 +20,15 @@ import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegist import au.com.royalpay.payment.channels.wechat.runtime.impls.WxPayMerchantRegisterLegacy; import au.com.royalpay.payment.channels.wechat.runtime.mappers.PaymentChannelMccGoodMapper; import au.com.royalpay.payment.channels.wechat.runtime.mappers.WxMerchantApplyMapper; -import au.com.royalpay.payment.core.ChannelMerchantApplicationService; import au.com.royalpay.payment.core.PaymentApi; import au.com.royalpay.payment.core.PaymentChannelApi; import au.com.royalpay.payment.core.beans.ChannelMerchantInfo; import au.com.royalpay.payment.core.beans.EmptyMerchantApplication; -import au.com.royalpay.payment.core.beans.MchChannelContract; import au.com.royalpay.payment.core.beans.MerchantApplicationResult; import au.com.royalpay.payment.core.exceptions.EmailException; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.core.impls.MerchantChannelApplicationManager; +import au.com.royalpay.payment.core.impls.MerchantChannelPermissionManager; import au.com.royalpay.payment.core.mappers.SysClientMapper; import au.com.royalpay.payment.core.utils.OrderExpiryRuleResolver; import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; @@ -99,6 +97,7 @@ import au.com.royalpay.payment.tools.lock.Locker; import au.com.royalpay.payment.tools.mail.SendMail; import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; import au.com.royalpay.payment.tools.merchants.beans.UpdateSurchargeDTO; +import au.com.royalpay.payment.tools.merchants.core.MerchantChannelPermissionResolver; import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; import au.com.royalpay.payment.tools.merchants.qrboard.QRBoard; import au.com.royalpay.payment.tools.merchants.qrboard.QRBoardProvider; @@ -127,8 +126,6 @@ import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; -import org.dom4j.DocumentException; -import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; @@ -330,7 +327,10 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Resource private SysClientUpayProfileMapper sysClientUpayProfileMapper; @Resource - private PaymentApi paymentApi; + private PaymentApi paymentApi; + @Resource + private MerchantChannelPermissionManager merchantChannelPermissionManager; + DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM yyyy"); @@ -549,6 +549,13 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid if (wechatMcc != null) { client.put("mc_code", wechatMcc.getIntValue("mc_code")); } + client.put("enable_alipayplus", false); + MerchantChannelPermissionResolver resolver = this.paymentApi.channelApi(PayChannel.ALIPAY_PLUS.getChannelCode()).getChannelPermissionResolver(); + if(!Objects.isNull(resolver)) { + if (resolver.newOrderEnabled(client)) { + client.put("enable_alipayplus", true); + } + } return client; } @@ -1565,13 +1572,17 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid @Override public void switchChannelPermission(JSONObject manager, String clientMoniker, String channel, boolean allow) { for (PaymentChannelApi channelApi : paymentApi.channels()) { - if (channelApi.channel().equalsIgnoreCase(channel) || "CB_BankPay".equalsIgnoreCase(channel)) { + if (channelApi.channel().equalsIgnoreCase(channel) ) { JSONObject client = getClientInfoByMoniker(clientMoniker); if (client == null) { throw new NotFoundException("Client Not Exists"); } - clientModifySupport.processClientConfigModify(new SwitchPermissionModify(manager, clientMoniker, "enable_" + channel.toLowerCase(), allow)); - + merchantChannelPermissionManager.switchMerchantChannelPermission(channelApi.getMetadata().payChannel(), client.getIntValue("client_id"), allow); + try { + clientModifySupport.processModify(new SwitchPermissionModify(manager, clientMoniker, "enable_" + channel.toLowerCase(), allow)); + } catch (Exception e) { + logger.error("Failed to change channel switch:{}" ,channel); + } logger.info("{}({}) switched client {} channel {} to {}", manager.getString("display_name"), manager.getString("manager_id"), clientMoniker, channel, allow); if (allow && (StringUtils.equalsAnyIgnoreCase("Wechat", channel) || StringUtils.equalsAnyIgnoreCase("Alipay", channel))) { int clientId = client.getIntValue("client_id"); diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/web/AlipayConfigController.java b/src/main/java/au/com/royalpay/payment/manage/merchants/web/AlipayConfigController.java new file mode 100644 index 000000000..88e78fa6f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/web/AlipayConfigController.java @@ -0,0 +1,31 @@ +package au.com.royalpay.payment.manage.merchants.web; + + +import au.com.royalpay.payment.manage.merchants.core.impls.AlipayChannelsConfig; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @Description + * @title: + * @Date 2021/2/1 9:42 + * @author: zhangTao + */ +@RestController +@RequestMapping("/sys/partners") +public class AlipayConfigController { + + @Resource + AlipayChannelsConfig alipayChannelsConfig; + + @RequestMapping(method = RequestMethod.PUT,value = "/modifyAlipayPaymentChannels/{clientId}/{alipayPaymentChannelsStatus}") + public void modifyAlipayPaymentChannels(@PathVariable Integer clientId, @PathVariable Boolean alipayPaymentChannelsStatus) { + alipayChannelsConfig.modifyAlipayPaymentChannels(clientId,alipayPaymentChannelsStatus); + } + + +}