feat: alipay+ 开关

master
zhangtao 4 years ago
parent 43b305f47a
commit d329806652

@ -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<JSONObject> 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<JSONObject> 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<JSONObject> getClientConfig(int clientId) {
Optional<JSONObject> optionalClientConfigInfo = Optional.of(clientConfigMapper.find(clientId));
return optionalClientConfigInfo;
}
}

@ -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.AlipayConfig;
import au.com.royalpay.payment.channels.alipay.config.AlipayEnvironment; 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.AlipayOnlineApi;
import au.com.royalpay.payment.channels.alipay.runtime.AlipayRetailApi; import au.com.royalpay.payment.channels.alipay.runtime.AlipayRetailApi;
import au.com.royalpay.payment.channels.alipay.runtime.entity.AlipayMerchantEntity; 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.impls.WxPayMerchantRegisterLegacy;
import au.com.royalpay.payment.channels.wechat.runtime.mappers.PaymentChannelMccGoodMapper; 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.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.PaymentApi;
import au.com.royalpay.payment.core.PaymentChannelApi; import au.com.royalpay.payment.core.PaymentChannelApi;
import au.com.royalpay.payment.core.beans.ChannelMerchantInfo; import au.com.royalpay.payment.core.beans.ChannelMerchantInfo;
import au.com.royalpay.payment.core.beans.EmptyMerchantApplication; 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.beans.MerchantApplicationResult;
import au.com.royalpay.payment.core.exceptions.EmailException; import au.com.royalpay.payment.core.exceptions.EmailException;
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.core.impls.MerchantChannelApplicationManager; 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.mappers.SysClientMapper;
import au.com.royalpay.payment.core.utils.OrderExpiryRuleResolver; import au.com.royalpay.payment.core.utils.OrderExpiryRuleResolver;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; 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.mail.SendMail;
import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; 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.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.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.merchants.qrboard.QRBoard; import au.com.royalpay.payment.tools.merchants.qrboard.QRBoard;
import au.com.royalpay.payment.tools.merchants.qrboard.QRBoardProvider; 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.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.Font;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
@ -330,7 +327,10 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Resource @Resource
private SysClientUpayProfileMapper sysClientUpayProfileMapper; private SysClientUpayProfileMapper sysClientUpayProfileMapper;
@Resource @Resource
private PaymentApi paymentApi; private PaymentApi paymentApi;
@Resource
private MerchantChannelPermissionManager merchantChannelPermissionManager;
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM yyyy"); DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM yyyy");
@ -549,6 +549,13 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
if (wechatMcc != null) { if (wechatMcc != null) {
client.put("mc_code", wechatMcc.getIntValue("mc_code")); 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; return client;
} }
@ -1565,13 +1572,17 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Override @Override
public void switchChannelPermission(JSONObject manager, String clientMoniker, String channel, boolean allow) { public void switchChannelPermission(JSONObject manager, String clientMoniker, String channel, boolean allow) {
for (PaymentChannelApi channelApi : paymentApi.channels()) { for (PaymentChannelApi channelApi : paymentApi.channels()) {
if (channelApi.channel().equalsIgnoreCase(channel) || "CB_BankPay".equalsIgnoreCase(channel)) { if (channelApi.channel().equalsIgnoreCase(channel) ) {
JSONObject client = getClientInfoByMoniker(clientMoniker); JSONObject client = getClientInfoByMoniker(clientMoniker);
if (client == null) { if (client == null) {
throw new NotFoundException("Client Not Exists"); 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); 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))) { if (allow && (StringUtils.equalsAnyIgnoreCase("Wechat", channel) || StringUtils.equalsAnyIgnoreCase("Alipay", channel))) {
int clientId = client.getIntValue("client_id"); int clientId = client.getIntValue("client_id");

@ -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);
}
}
Loading…
Cancel
Save