commit
99f9753d10
@ -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);
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
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.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.exceptions.NotFoundException;
|
||||||
|
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
|
||||||
|
import au.com.royalpay.payment.tools.merchants.exceptions.NoRateConfigException;
|
||||||
|
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);
|
||||||
|
if (targetMerchant == null) {
|
||||||
|
throw new NotFoundException("Merchant not found:" + targetClientMoniker);
|
||||||
|
}
|
||||||
|
JSONObject sourceMerchant = merchantInfoProvider.getClientInfoByMoniker(sourceClientMoniker);
|
||||||
|
if (sourceMerchant == null) {
|
||||||
|
throw new NotFoundException("Merchant not found:" + 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"));
|
||||||
|
try {
|
||||||
|
merchantInfoProvider.clientCurrentRate(targetClientId, new Date(), PayChannel.RPAY_CHANNEL_CARD.getChannelCode());
|
||||||
|
} catch (NoRateConfigException e) {
|
||||||
|
JSONObject rate = merchantInfoProvider.clientCurrentRate(sourceClientId, new Date(), PayChannel.RPAY_CHANNEL_CARD.getChannelCode());
|
||||||
|
rate.put("client_id", targetClientId);
|
||||||
|
rate.remove("client_rate_id");
|
||||||
|
clientRateMapper.saveRate(rate);
|
||||||
|
}
|
||||||
|
return targetRPayMch;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package au.com.royalpay.payment.manage.merchants.core.impls;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
|
||||||
|
import au.com.royalpay.payment.manage.merchants.core.MerchantChannelPermissionService;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ActiveProfiles({"proxy","common", "alipay", "wechat", "rpay", "rppaysvc"})
|
||||||
|
public class MerchantChannelPermissionServiceImplTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MerchantChannelPermissionService merchantChannelPermissionService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ManagerMapper managerMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
JSONObject manager = managerMapper.findByLoginId("yixian");
|
||||||
|
merchantChannelPermissionService.copyMerchantWarriorConfig(manager, "DV11", "DV02");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue