Search in sources :

Example 1 with IntegrationModuleConfiguration

use of com.salesmanager.shop.model.system.IntegrationModuleConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentApi method configure.

@PostMapping(value = "/private/modules/payment")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
    try {
        List<IntegrationModule> modules = paymentService.getPaymentMethods(merchantStore);
        Map<String, IntegrationModule> map = modules.stream().collect(Collectors.toMap(IntegrationModule::getCode, module -> module));
        IntegrationModule config = map.get(configuration.getCode());
        if (config == null) {
            throw new ResourceNotFoundException("Payment module [" + configuration.getCode() + "] not found");
        }
        Map<String, IntegrationConfiguration> configuredModules = paymentService.getPaymentModulesConfigured(merchantStore);
        IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
        if (integrationConfiguration == null) {
            integrationConfiguration = new IntegrationConfiguration();
            integrationConfiguration.setModuleCode(configuration.getCode());
        }
        integrationConfiguration.setActive(configuration.isActive());
        integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
        integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
        integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
        paymentService.savePaymentModuleConfiguration(integrationConfiguration, merchantStore);
    } catch (ServiceException e) {
        LOGGER.error("Error getting payment modules", e);
        throw new ServiceRuntimeException("Error saving payment module", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceException(com.salesmanager.core.business.exception.ServiceException) RequestBody(org.springframework.web.bind.annotation.RequestBody) Language(com.salesmanager.core.model.reference.language.Language) ApiOperation(io.swagger.annotations.ApiOperation) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) PaymentService(com.salesmanager.core.business.services.payments.PaymentService) IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) ApiIgnore(springfox.documentation.annotations.ApiIgnore) List(java.util.List) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with IntegrationModuleConfiguration

use of com.salesmanager.shop.model.system.IntegrationModuleConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingConfigurationApi method configure.

@PostMapping(value = "/private/modules/shipping")
public void configure(@RequestBody IntegrationModuleConfiguration configuration, @ApiIgnore MerchantStore merchantStore) {
    try {
        List<IntegrationModule> modules = shippingService.getShippingMethods(merchantStore);
        Map<String, IntegrationModule> map = modules.stream().collect(Collectors.toMap(IntegrationModule::getCode, module -> module));
        IntegrationModule config = map.get(configuration.getCode());
        if (config == null) {
            throw new ResourceNotFoundException("Shipping module [" + configuration.getCode() + "] not found");
        }
        Map<String, IntegrationConfiguration> configuredModules = shippingService.getShippingModulesConfigured(merchantStore);
        IntegrationConfiguration integrationConfiguration = configuredModules.get(configuration.getCode());
        if (integrationConfiguration == null) {
            integrationConfiguration = new IntegrationConfiguration();
        }
        /**
         * Build return object for now this is a read copy
         */
        integrationConfiguration.setActive(configuration.isActive());
        integrationConfiguration.setDefaultSelected(configuration.isDefaultSelected());
        integrationConfiguration.setIntegrationKeys(configuration.getIntegrationKeys());
        integrationConfiguration.setIntegrationOptions(configuration.getIntegrationOptions());
        shippingService.saveShippingQuoteModuleConfiguration(integrationConfiguration, merchantStore);
    } catch (ServiceException e) {
        LOGGER.error("Error saving shipping modules", e);
        throw new ServiceRuntimeException("Error saving shipping module", e);
    }
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) ShippingFacade(com.salesmanager.shop.store.controller.shipping.facade.ShippingFacade) Constants(com.salesmanager.shop.constants.Constants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceException(com.salesmanager.core.business.exception.ServiceException) RequestBody(org.springframework.web.bind.annotation.RequestBody) Language(com.salesmanager.core.model.reference.language.Language) ApiOperation(io.swagger.annotations.ApiOperation) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) AuthorizationUtils(com.salesmanager.shop.utils.AuthorizationUtils) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Logger(org.slf4j.Logger) ApiImplicitParam(io.swagger.annotations.ApiImplicitParam) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) IntegrationModuleSummaryEntity(com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity) ApiIgnore(springfox.documentation.annotations.ApiIgnore) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Stream(java.util.stream.Stream) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with IntegrationModuleConfiguration

use of com.salesmanager.shop.model.system.IntegrationModuleConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentApi method paymentModule.

/**
 * Get merchant payment module details
 *
 * @param code
 * @param merchantStore
 * @param language
 * @return
 */
@GetMapping("/private/modules/payment/{code}")
@ApiOperation(httpMethod = "GET", value = "Payment module by code", produces = "application/json", response = List.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "string", defaultValue = "DEFAULT") })
public IntegrationModuleConfiguration paymentModule(@PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) {
    try {
        // get module
        IntegrationModule integrationModule = paymentService.getPaymentMethodByCode(merchantStore, code);
        if (integrationModule == null) {
            throw new ResourceNotFoundException("Payment module [" + code + "] not found");
        }
        IntegrationModuleConfiguration returnConfig = new IntegrationModuleConfiguration();
        returnConfig.setConfigurable(integrationModule.getConfigurable());
        returnConfig.setActive(false);
        returnConfig.setDefaultSelected(false);
        returnConfig.setCode(code);
        // configured modules
        IntegrationConfiguration config = paymentService.getPaymentConfiguration(code, merchantStore);
        if (config == null) {
            return returnConfig;
        }
        /**
         * Build return object for now this is a read copy
         */
        returnConfig.setActive(config.isActive());
        returnConfig.setDefaultSelected(config.isDefaultSelected());
        returnConfig.setCode(code);
        returnConfig.setIntegrationKeys(config.getIntegrationKeys());
        returnConfig.setIntegrationOptions(config.getIntegrationOptions());
        return returnConfig;
    } catch (ServiceException e) {
        LOGGER.error("Error getting payment module [" + code + "]", e);
        throw new ServiceRuntimeException("Error getting payment module [" + code + "]", e);
    }
}
Also used : IntegrationModuleConfiguration(com.salesmanager.shop.model.system.IntegrationModuleConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)3 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)3 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)3 IntegrationModuleConfiguration (com.salesmanager.shop.model.system.IntegrationModuleConfiguration)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)3 ApiOperation (io.swagger.annotations.ApiOperation)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 Language (com.salesmanager.core.model.reference.language.Language)2 IntegrationModuleSummaryEntity (com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity)2 Api (io.swagger.annotations.Api)2 ApiImplicitParam (io.swagger.annotations.ApiImplicitParam)2 SwaggerDefinition (io.swagger.annotations.SwaggerDefinition)2 Tag (io.swagger.annotations.Tag)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2