Search in sources :

Example 6 with PaymentModule

use of com.salesmanager.core.modules.integration.payment.model.PaymentModule 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 7 with PaymentModule

use of com.salesmanager.core.modules.integration.payment.model.PaymentModule 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)7 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)7 ServiceException (com.salesmanager.core.business.exception.ServiceException)6 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)6 Transaction (com.salesmanager.core.model.payments.Transaction)5 BigDecimal (java.math.BigDecimal)4 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)2 Date (java.util.Date)2 PayPalExpressCheckoutPayment (com.salesmanager.core.business.modules.integration.payment.impl.PayPalExpressCheckoutPayment)1 Stripe3Payment (com.salesmanager.core.business.modules.integration.payment.impl.Stripe3Payment)1 AjaxResponse (com.salesmanager.core.business.utils.ajax.AjaxResponse)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 OrderTotal (com.salesmanager.core.model.order.OrderTotal)1 OrderTotalSummary (com.salesmanager.core.model.order.OrderTotalSummary)1 CreditCardPayment (com.salesmanager.core.model.payments.CreditCardPayment)1 PaypalPayment (com.salesmanager.core.model.payments.PaypalPayment)1 TransactionType (com.salesmanager.core.model.payments.TransactionType)1 Language (com.salesmanager.core.model.reference.language.Language)1 ShippingSummary (com.salesmanager.core.model.shipping.ShippingSummary)1 ShoppingCartItem (com.salesmanager.core.model.shoppingcart.ShoppingCartItem)1