diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/MerchantChannelPermissionService.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/MerchantChannelPermissionService.java new file mode 100644 index 000000000..e4538e039 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/MerchantChannelPermissionService.java @@ -0,0 +1,8 @@ +package au.com.royalpay.payment.manage.merchants.core; + +import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.request.entities.RPayMerchantEntity; +import com.alibaba.fastjson.JSONObject; + +public interface MerchantChannelPermissionService { + RPayMerchantEntity copyMerchantWarriorConfig(JSONObject manager, String targetClientMoniker, String sourceClientMoniker); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/MerchantChannelPermissionServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/MerchantChannelPermissionServiceImpl.java new file mode 100644 index 000000000..341123324 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/MerchantChannelPermissionServiceImpl.java @@ -0,0 +1,73 @@ +package au.com.royalpay.payment.manage.merchants.core.impls; + +import au.com.royalpay.payment.channels.rpaypaymentsvc.mappers.RPayMerchantMapper; +import au.com.royalpay.payment.channels.rpaypaymentsvc.runtime.request.entities.RPayMerchantEntity; +import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper; +import au.com.royalpay.payment.manage.mappers.system.RateMapper; +import au.com.royalpay.payment.manage.mappers.system.SysClientUpayProfileMapper; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.manage.merchants.core.MerchantChannelPermissionService; +import au.com.royalpay.payment.tools.defines.PayChannel; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; +import com.alibaba.fastjson.JSONObject; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; + +@Service +public class MerchantChannelPermissionServiceImpl implements MerchantChannelPermissionService { + @Resource + private MerchantInfoProvider merchantInfoProvider; + @Resource + private ClientManager clientManager; + @Resource + private SysClientUpayProfileMapper sysClientUpayProfileMapper; + @Resource + private RPayMerchantMapper rPayMerchantMapper; + @Resource + private ClientRateMapper clientRateMapper; + + @Override + @Transactional + public RPayMerchantEntity copyMerchantWarriorConfig(JSONObject manager, String targetClientMoniker, String sourceClientMoniker) { + JSONObject targetMerchant = merchantInfoProvider.getClientInfoByMoniker(targetClientMoniker); + JSONObject sourceMerchant = merchantInfoProvider.getClientInfoByMoniker(sourceClientMoniker); + int sourceClientId = sourceMerchant.getIntValue("client_id"); + int targetClientId = targetMerchant.getIntValue("client_id"); + JSONObject targetProfile = sysClientUpayProfileMapper.findInfo(targetClientId); + if (targetProfile == null) { + JSONObject sourceProfile = sysClientUpayProfileMapper.findInfo(sourceClientId); + if (sourceProfile == null) { + throw new BadRequestException("Missing merchant's UPay profile"); + } + targetProfile = new JSONObject(sourceProfile); + targetProfile.put("client_id", targetClientId); + targetProfile.put("client_moniker", targetMerchant.getString("client_moniker")); + sysClientUpayProfileMapper.save(targetProfile); + } + RPayMerchantEntity targetRPayMch = rPayMerchantMapper.findMerchant(targetClientId); + if (targetRPayMch == null) { + RPayMerchantEntity sourceRPayMch = rPayMerchantMapper.findMerchant(sourceClientId); + if (sourceRPayMch == null) { + throw new BadRequestException("Source merchant not enabled card payment"); + } + targetRPayMch = sourceRPayMch; + targetRPayMch.setClientId(targetMerchant.getIntValue("client_id")); + targetRPayMch.setClientMoniker(targetMerchant.getString("client_moniker")); + rPayMerchantMapper.save(targetRPayMch); + } + clientManager.switchPermission(manager, targetClientMoniker, "enable_rpaypmt_card", sourceMerchant.getBooleanValue("enable_rpaypmt_card")); + clientManager.switchPermission(manager, targetClientMoniker, "enable_rpaypmt_dd", sourceMerchant.getBooleanValue("enable_rpaypmt_dd")); + JSONObject targetRate = merchantInfoProvider.clientCurrentRate(targetClientId,new Date(),PayChannel.RPAY_CHANNEL_CARD.getChannelCode()); + if (targetRate==null) { + JSONObject sourceRate = merchantInfoProvider.clientCurrentRate(sourceClientId, new Date(), PayChannel.RPAY_CHANNEL_CARD.getChannelCode()); + targetRate = new JSONObject(sourceRate); + targetRate.put("client_id", targetClientId); + clientRateMapper.saveRate(targetRate); + } + return targetRPayMch; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java index 628043377..efd63bec4 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/web/PartnerManageController.java @@ -5,6 +5,7 @@ import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.manage.dev.core.MerchantLocationService; import au.com.royalpay.payment.manage.merchants.beans.*; import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.manage.merchants.core.MerchantChannelPermissionService; import au.com.royalpay.payment.manage.merchants.core.bank.AustraliaBankClientNullException; import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; import au.com.royalpay.payment.manage.permission.manager.RequireManager; @@ -41,6 +42,8 @@ public class PartnerManageController { @Resource private TradeLogService tradeLogService; @Resource + private MerchantChannelPermissionService merchantChannelPermissionService; + @Resource private MerchantLocationService merchantLocationService; @RequestMapping(method = RequestMethod.GET) @@ -441,7 +444,7 @@ public class PartnerManageController { @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { try { return clientManager.getBankInfo(manager, clientMoniker, bsbNo); - }catch (AustraliaBankClientNullException e){ + } catch (AustraliaBankClientNullException e) { throw new InvalidShortIdException(); } } @@ -850,13 +853,13 @@ public class PartnerManageController { @ManagerMapping(value = "/{clientMoniker}/get_merchant_ids/{merchantAppId}", method = RequestMethod.PUT, role = {ManagerRole.OPERATOR, ManagerRole.ADMIN}) public void changeSubMerchantApplication(@PathVariable("clientMoniker") String clientMoniker, @PathVariable("merchantAppId") String merchantAppId, - @RequestBody NewSubMerchantIdApply subMerchantIdApply, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { - clientManager.changeApplicationSubMerchantById(clientMoniker, merchantAppId,subMerchantIdApply,manager); + @RequestBody NewSubMerchantIdApply subMerchantIdApply, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + clientManager.changeApplicationSubMerchantById(clientMoniker, merchantAppId, subMerchantIdApply, manager); } @ManagerMapping(value = "/{clientMoniker}/get_merchant_ids/{subMerchantId}/status", method = RequestMethod.GET, role = {ManagerRole.OPERATOR, ManagerRole.ADMIN}) - public JSONObject querySubMerchantStatus(@PathVariable("clientMoniker") String clientMoniker,@PathVariable("subMerchantId") String subMerchantId){ - return clientManager.querySubMerchantStatus(clientMoniker,subMerchantId); + public JSONObject querySubMerchantStatus(@PathVariable("clientMoniker") String clientMoniker, @PathVariable("subMerchantId") String subMerchantId) { + return clientManager.querySubMerchantStatus(clientMoniker, subMerchantId); } @ManagerMapping(value = "/{clientMoniker}/register/alipay_gms", method = RequestMethod.POST, role = {ManagerRole.OPERATOR, ManagerRole.ADMIN}) @@ -1031,6 +1034,12 @@ public class PartnerManageController { return clientManager.queryMWMerchantIdStatus(clientMoniker, manager); } + @ManagerMapping(value = "/{clientMoniker}/copy_mw_config", method = RequestMethod.POST, role = {ManagerRole.DEVELOPER}) + public RPayMerchantEntity copyMWConfig(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, + @RequestBody JSONObject body) { + return merchantChannelPermissionService.copyMerchantWarriorConfig(manager, clientMoniker, body.getString("client_moniker")); + } + @ManagerMapping(value = "/{clientMoniker}/query/mw_info", method = RequestMethod.GET, role = {ManagerRole.OPERATOR, ManagerRole.ADMIN}) public RPayMerchantEntity queryMWMerchantInfo(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { return clientManager.queryMWMerchantInfo(clientMoniker, manager);