Search in sources :

Example 21 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ShippingServiceImpl method saveShippingQuoteModuleConfiguration.

@Override
public void saveShippingQuoteModuleConfiguration(IntegrationConfiguration configuration, MerchantStore store) throws ServiceException {
    // validate entries
    try {
        String moduleCode = configuration.getModuleCode();
        ShippingQuoteModule quoteModule = (ShippingQuoteModule) shippingModules.get(moduleCode);
        if (quoteModule == null) {
            throw new ServiceException("Shipping quote module " + moduleCode + " does not exist");
        }
        quoteModule.validateModuleConfiguration(configuration, store);
    } catch (IntegrationException ie) {
        throw ie;
    }
    try {
        Map<String, IntegrationConfiguration> modules = new HashMap<String, IntegrationConfiguration>();
        MerchantConfiguration merchantConfiguration = merchantConfigurationService.getMerchantConfiguration(SHIPPING_MODULES, store);
        if (merchantConfiguration != null) {
            if (!StringUtils.isBlank(merchantConfiguration.getValue())) {
                String decrypted = encryption.decrypt(merchantConfiguration.getValue());
                modules = ConfigurationModulesLoader.loadIntegrationConfigurations(decrypted);
            }
        } else {
            merchantConfiguration = new MerchantConfiguration();
            merchantConfiguration.setMerchantStore(store);
            merchantConfiguration.setKey(SHIPPING_MODULES);
        }
        modules.put(configuration.getModuleCode(), configuration);
        String configs = ConfigurationModulesLoader.toJSONString(modules);
        String encrypted = encryption.encrypt(configs);
        merchantConfiguration.setValue(encrypted);
        merchantConfigurationService.saveOrUpdate(merchantConfiguration);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) HashMap(java.util.HashMap) CustomIntegrationConfiguration(com.salesmanager.core.model.system.CustomIntegrationConfiguration) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) ShippingQuoteModule(com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 22 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class ConfigurationModulesLoader method toJSONString.

public static String toJSONString(Map<String, IntegrationConfiguration> configurations) throws Exception {
    StringBuilder jsonModules = new StringBuilder();
    jsonModules.append("[");
    int count = 0;
    for (Object key : configurations.keySet()) {
        String k = (String) key;
        IntegrationConfiguration c = configurations.get(k);
        String jsonString = c.toJSONString();
        jsonModules.append(jsonString);
        count++;
        if (count < configurations.size()) {
            jsonModules.append(",");
        }
    }
    jsonModules.append("]");
    return jsonModules.toString();
}
Also used : IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration)

Example 23 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method processCapturePayment.

@Override
public Transaction processCapturePayment(Order order, Customer customer, MerchantStore store) throws ServiceException {
    Validate.notNull(customer);
    Validate.notNull(store);
    Validate.notNull(order);
    // must have a shipping module configured
    Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
    if (modules == null) {
        throw new ServiceException("No payment module configured");
    }
    IntegrationConfiguration configuration = modules.get(order.getPaymentModuleCode());
    if (configuration == null) {
        throw new ServiceException("Payment module " + order.getPaymentModuleCode() + " is not configured");
    }
    if (!configuration.isActive()) {
        throw new ServiceException("Payment module " + order.getPaymentModuleCode() + " is not active");
    }
    PaymentModule module = this.paymentModules.get(order.getPaymentModuleCode());
    if (module == null) {
        throw new ServiceException("Payment module " + order.getPaymentModuleCode() + " does not exist");
    }
    IntegrationModule integrationModule = getPaymentMethodByCode(store, order.getPaymentModuleCode());
    // TransactionType transactionType = payment.getTransactionType();
    // get the previous transaction
    Transaction trx = transactionService.getCapturableTransaction(order);
    if (trx == null) {
        throw new ServiceException("No capturable transaction for order id " + order.getId());
    }
    Transaction transaction = module.capture(store, customer, order, trx, configuration, integrationModule);
    transaction.setOrder(order);
    transactionService.create(transaction);
    OrderStatusHistory orderHistory = new OrderStatusHistory();
    orderHistory.setOrder(order);
    orderHistory.setStatus(OrderStatus.PROCESSED);
    orderHistory.setDateAdded(new Date());
    orderService.addOrderStatusHistory(order, orderHistory);
    order.setStatus(OrderStatus.PROCESSED);
    orderService.saveOrUpdate(order);
    return transaction;
}
Also used : PaymentModule(com.salesmanager.core.modules.integration.payment.model.PaymentModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule) Date(java.util.Date)

Example 24 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method initTransaction.

@Override
public Transaction initTransaction(Customer customer, Payment payment, MerchantStore store) throws ServiceException {
    Validate.notNull(store);
    Validate.notNull(payment);
    Validate.notNull(payment.getAmount());
    payment.setCurrency(store.getCurrency());
    BigDecimal amount = payment.getAmount();
    // must have a shipping module configured
    Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
    if (modules == null) {
        throw new ServiceException("No payment module configured");
    }
    IntegrationConfiguration configuration = modules.get(payment.getModuleName());
    if (configuration == null) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " is not configured");
    }
    if (!configuration.isActive()) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " is not active");
    }
    PaymentModule module = this.paymentModules.get(payment.getModuleName());
    if (module == null) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " does not exist");
    }
    IntegrationModule integrationModule = getPaymentMethodByCode(store, payment.getModuleName());
    Transaction transaction = module.initTransaction(store, customer, amount, payment, configuration, integrationModule);
    transactionService.save(transaction);
    return transaction;
}
Also used : PaymentModule(com.salesmanager.core.modules.integration.payment.model.PaymentModule) ServiceException(com.salesmanager.core.business.exception.ServiceException) Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) BigDecimal(java.math.BigDecimal) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule)

Example 25 with IntegrationConfiguration

use of com.salesmanager.core.model.system.IntegrationConfiguration in project shopizer by shopizer-ecommerce.

the class PaymentServiceImpl method processPayment.

@Override
public Transaction processPayment(Customer customer, MerchantStore store, Payment payment, List<ShoppingCartItem> items, Order order) throws ServiceException {
    Validate.notNull(customer);
    Validate.notNull(store);
    Validate.notNull(payment);
    Validate.notNull(order);
    Validate.notNull(order.getTotal());
    payment.setCurrency(store.getCurrency());
    BigDecimal amount = order.getTotal();
    // must have a shipping module configured
    Map<String, IntegrationConfiguration> modules = this.getPaymentModulesConfigured(store);
    if (modules == null) {
        throw new ServiceException("No payment module configured");
    }
    IntegrationConfiguration configuration = modules.get(payment.getModuleName());
    if (configuration == null) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " is not configured");
    }
    if (!configuration.isActive()) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " is not active");
    }
    String sTransactionType = configuration.getIntegrationKeys().get("transaction");
    if (sTransactionType == null) {
        sTransactionType = TransactionType.AUTHORIZECAPTURE.name();
    }
    try {
        TransactionType.valueOf(sTransactionType);
    } catch (IllegalArgumentException ie) {
        LOGGER.warn("Transaction type " + sTransactionType + " does noe exist, using default AUTHORIZECAPTURE");
        sTransactionType = "AUTHORIZECAPTURE";
    }
    if (sTransactionType.equals(TransactionType.AUTHORIZE.name())) {
        payment.setTransactionType(TransactionType.AUTHORIZE);
    } else {
        payment.setTransactionType(TransactionType.AUTHORIZECAPTURE);
    }
    PaymentModule module = this.paymentModules.get(payment.getModuleName());
    if (module == null) {
        throw new ServiceException("Payment module " + payment.getModuleName() + " does not exist");
    }
    if (payment instanceof CreditCardPayment && "true".equals(coreConfiguration.getProperty("VALIDATE_CREDIT_CARD"))) {
        CreditCardPayment creditCardPayment = (CreditCardPayment) payment;
        validateCreditCard(creditCardPayment.getCreditCardNumber(), creditCardPayment.getCreditCard(), creditCardPayment.getExpirationMonth(), creditCardPayment.getExpirationYear());
    }
    IntegrationModule integrationModule = getPaymentMethodByCode(store, payment.getModuleName());
    TransactionType transactionType = TransactionType.valueOf(sTransactionType);
    if (transactionType == null) {
        transactionType = payment.getTransactionType();
        if (transactionType.equals(TransactionType.CAPTURE.name())) {
            throw new ServiceException("This method does not allow to process capture transaction. Use processCapturePayment");
        }
    }
    Transaction transaction = null;
    if (transactionType == TransactionType.AUTHORIZE) {
        transaction = module.authorize(store, customer, items, amount, payment, configuration, integrationModule);
    } else if (transactionType == TransactionType.AUTHORIZECAPTURE) {
        transaction = module.authorizeAndCapture(store, customer, items, amount, payment, configuration, integrationModule);
    } else if (transactionType == TransactionType.INIT) {
        transaction = module.initTransaction(store, customer, amount, payment, configuration, integrationModule);
    }
    if (transactionType != TransactionType.INIT) {
        transactionService.create(transaction);
    }
    if (transactionType == TransactionType.AUTHORIZECAPTURE) {
        order.setStatus(OrderStatus.ORDERED);
        if (!payment.getPaymentType().name().equals(PaymentType.MONEYORDER.name())) {
            order.setStatus(OrderStatus.PROCESSED);
        }
    }
    return transaction;
}
Also used : PaymentModule(com.salesmanager.core.modules.integration.payment.model.PaymentModule) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) TransactionType(com.salesmanager.core.model.payments.TransactionType) ServiceException(com.salesmanager.core.business.exception.ServiceException) Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) BigDecimal(java.math.BigDecimal) IntegrationModule(com.salesmanager.core.model.system.IntegrationModule)

Aggregations

IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)27 ServiceException (com.salesmanager.core.business.exception.ServiceException)20 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)10 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)9 List (java.util.List)9 Language (com.salesmanager.core.model.reference.language.Language)8 BigDecimal (java.math.BigDecimal)8 Map (java.util.Map)8 CustomIntegrationConfiguration (com.salesmanager.core.model.system.CustomIntegrationConfiguration)7 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 PackageDetails (com.salesmanager.core.model.shipping.PackageDetails)6 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)6 IntegrationModuleConfiguration (com.salesmanager.shop.model.system.IntegrationModuleConfiguration)6 IntegrationModuleSummaryEntity (com.salesmanager.shop.model.system.IntegrationModuleSummaryEntity)6 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)6