Search in sources :

Example 16 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BeanStreamPayment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    try {
        // authorize a preauth
        String trnID = capturableTransaction.getTransactionDetails().get("TRANSACTIONID");
        String amnt = productPriceUtils.getAdminFormatedAmount(store, order.getTotal());
        /**
         *				merchant_id=123456789&requestType=BACKEND
         *				&trnType=PAC&username=user1234&password=pass1234&trnID=1000
         *				2115 --> requires also adjId [not documented]
         */
        StringBuilder messageString = new StringBuilder();
        messageString.append("requestType=BACKEND&");
        messageString.append("merchant_id=").append(configuration.getIntegrationKeys().get("merchantid")).append("&");
        messageString.append("trnType=").append("PAC").append("&");
        messageString.append("username=").append(configuration.getIntegrationKeys().get("username")).append("&");
        messageString.append("password=").append(configuration.getIntegrationKeys().get("password")).append("&");
        messageString.append("trnAmount=").append(amnt).append("&");
        messageString.append("adjId=").append(trnID).append("&");
        messageString.append("trnID=").append(trnID);
        LOGGER.debug("REQUEST SENT TO BEANSTREAM -> " + messageString.toString());
        return sendTransaction(null, store, messageString.toString(), "PAC", TransactionType.CAPTURE, PaymentType.CREDITCARD, order.getTotal(), configuration, module);
    } catch (Exception e) {
        if (e instanceof IntegrationException)
            throw (IntegrationException) e;
        throw new IntegrationException("Error while processing BeanStream transaction", e);
    }
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 17 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BraintreePayment method refund.

@Override
public Transaction refund(boolean partial, MerchantStore store, Transaction transaction, Order order, BigDecimal amount, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    String merchantId = configuration.getIntegrationKeys().get("merchant_id");
    String publicKey = configuration.getIntegrationKeys().get("public_key");
    String privateKey = configuration.getIntegrationKeys().get("private_key");
    Validate.notNull(merchantId, "merchant_id cannot be null");
    Validate.notNull(publicKey, "public_key cannot be null");
    Validate.notNull(privateKey, "private_key cannot be null");
    String auth = transaction.getTransactionDetails().get("TRANSACTIONID");
    if (StringUtils.isBlank(auth)) {
        IntegrationException te = new IntegrationException("Can't process Braintree refund, missing transaction id");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Environment environment = Environment.PRODUCTION;
    if (configuration.getEnvironment().equals("TEST")) {
        // sandbox
        environment = Environment.SANDBOX;
    }
    BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
    Result<com.braintreegateway.Transaction> result = gateway.transaction().refund(auth, amount);
    String trxId = null;
    if (result.isSuccess()) {
        com.braintreegateway.Transaction settledTransaction = result.getTarget();
        trxId = settledTransaction.getId();
    } else {
        String errorString = "";
        for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
            errorString += "Error: " + error.getCode() + ": " + error.getMessage() + "\n";
        }
        IntegrationException te = new IntegrationException("Can't process Braintree refund " + errorString);
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    if (StringUtils.isBlank(trxId)) {
        IntegrationException te = new IntegrationException("Can't process Braintree refund, missing original transaction");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Transaction trx = new Transaction();
    trx.setAmount(amount);
    trx.setTransactionDate(new Date());
    trx.setTransactionType(TransactionType.REFUND);
    trx.setPaymentType(PaymentType.CREDITCARD);
    trx.getTransactionDetails().put("TRANSACTIONID", trxId);
    trx.getTransactionDetails().put("TRNAPPROVED", null);
    trx.getTransactionDetails().put("TRNORDERNUMBER", trxId);
    trx.getTransactionDetails().put("MESSAGETEXT", null);
    return trx;
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) Environment(com.braintreegateway.Environment) BraintreeGateway(com.braintreegateway.BraintreeGateway) ValidationError(com.braintreegateway.ValidationError) Date(java.util.Date)

Example 18 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BraintreePayment method authorizeAndCapture.

@Override
public Transaction authorizeAndCapture(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Validate.notNull(configuration, "Configuration cannot be null");
    String merchantId = configuration.getIntegrationKeys().get("merchant_id");
    String publicKey = configuration.getIntegrationKeys().get("public_key");
    String privateKey = configuration.getIntegrationKeys().get("private_key");
    Validate.notNull(merchantId, "merchant_id cannot be null");
    Validate.notNull(publicKey, "public_key cannot be null");
    Validate.notNull(privateKey, "private_key cannot be null");
    // paymentToken
    String nonce = payment.getPaymentMetaData().get("paymentToken");
    if (StringUtils.isBlank(nonce)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing authorization nounce");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Environment environment = Environment.PRODUCTION;
    if (configuration.getEnvironment().equals("TEST")) {
        // sandbox
        environment = Environment.SANDBOX;
    }
    BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
    TransactionRequest request = new TransactionRequest().amount(amount).paymentMethodNonce(nonce);
    Result<com.braintreegateway.Transaction> result = gateway.transaction().sale(request);
    String trxId = null;
    if (result.isSuccess()) {
        com.braintreegateway.Transaction transaction = result.getTarget();
        trxId = transaction.getId();
    } else {
        String errorString = "";
        for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
            errorString += "Error: " + error.getCode() + ": " + error.getMessage() + "\n";
        }
        IntegrationException te = new IntegrationException("Can't process Braintree auth + capture " + errorString);
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    if (StringUtils.isBlank(trxId)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing trxId");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Transaction trx = new Transaction();
    trx.setAmount(amount);
    trx.setTransactionDate(new Date());
    trx.setTransactionType(TransactionType.AUTHORIZECAPTURE);
    trx.setPaymentType(PaymentType.CREDITCARD);
    trx.getTransactionDetails().put("TRANSACTIONID", trxId);
    trx.getTransactionDetails().put("TRNAPPROVED", null);
    trx.getTransactionDetails().put("TRNORDERNUMBER", trxId);
    trx.getTransactionDetails().put("MESSAGETEXT", null);
    return trx;
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) Environment(com.braintreegateway.Environment) BraintreeGateway(com.braintreegateway.BraintreeGateway) ValidationError(com.braintreegateway.ValidationError) TransactionRequest(com.braintreegateway.TransactionRequest) Date(java.util.Date)

Example 19 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BraintreePayment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Validate.notNull(configuration, "Configuration cannot be null");
    String merchantId = configuration.getIntegrationKeys().get("merchant_id");
    String publicKey = configuration.getIntegrationKeys().get("public_key");
    String privateKey = configuration.getIntegrationKeys().get("private_key");
    Validate.notNull(merchantId, "merchant_id cannot be null");
    Validate.notNull(publicKey, "public_key cannot be null");
    Validate.notNull(privateKey, "private_key cannot be null");
    String auth = capturableTransaction.getTransactionDetails().get("TRANSACTIONID");
    if (StringUtils.isBlank(auth)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing authorization id");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Environment environment = Environment.PRODUCTION;
    if (configuration.getEnvironment().equals("TEST")) {
        // sandbox
        environment = Environment.SANDBOX;
    }
    BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
    BigDecimal amount = order.getTotal();
    Result<com.braintreegateway.Transaction> result = gateway.transaction().submitForSettlement(auth, amount);
    String trxId = null;
    if (result.isSuccess()) {
        com.braintreegateway.Transaction settledTransaction = result.getTarget();
        trxId = settledTransaction.getId();
    } else {
        String errorString = "";
        for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
            errorString += "Error: " + error.getCode() + ": " + error.getMessage() + "\n";
        }
        IntegrationException te = new IntegrationException("Can't process Braintree refund " + errorString);
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    if (StringUtils.isBlank(trxId)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing original transaction");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Transaction trx = new Transaction();
    trx.setAmount(amount);
    trx.setTransactionDate(new Date());
    trx.setTransactionType(TransactionType.CAPTURE);
    trx.setPaymentType(PaymentType.CREDITCARD);
    trx.getTransactionDetails().put("TRANSACTIONID", trxId);
    trx.getTransactionDetails().put("TRNAPPROVED", null);
    trx.getTransactionDetails().put("TRNORDERNUMBER", trxId);
    trx.getTransactionDetails().put("MESSAGETEXT", null);
    return trx;
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) Environment(com.braintreegateway.Environment) BraintreeGateway(com.braintreegateway.BraintreeGateway) ValidationError(com.braintreegateway.ValidationError) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 20 with IntegrationException

use of com.salesmanager.core.modules.integration.IntegrationException in project shopizer by shopizer-ecommerce.

the class BraintreePayment method authorize.

@Override
public Transaction authorize(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Validate.notNull(configuration, "Configuration cannot be null");
    String merchantId = configuration.getIntegrationKeys().get("merchant_id");
    String publicKey = configuration.getIntegrationKeys().get("public_key");
    String privateKey = configuration.getIntegrationKeys().get("private_key");
    Validate.notNull(merchantId, "merchant_id cannot be null");
    Validate.notNull(publicKey, "public_key cannot be null");
    Validate.notNull(privateKey, "private_key cannot be null");
    String nonce = payment.getPaymentMetaData().get("paymentToken");
    if (StringUtils.isBlank(nonce)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing authorization nounce");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Environment environment = Environment.PRODUCTION;
    if (configuration.getEnvironment().equals("TEST")) {
        // sandbox
        environment = Environment.SANDBOX;
    }
    BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
    TransactionRequest request = new TransactionRequest().amount(amount).paymentMethodNonce(nonce);
    Result<com.braintreegateway.Transaction> result = gateway.transaction().sale(request);
    String authorizationId = null;
    if (result.isSuccess()) {
        com.braintreegateway.Transaction transaction = result.getTarget();
        authorizationId = transaction.getId();
    } else if (result.getTransaction() != null) {
        com.braintreegateway.Transaction transaction = result.getTransaction();
        authorizationId = transaction.getAuthorizedTransactionId();
    } else {
        String errorString = "";
        for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
            errorString += "Error: " + error.getCode() + ": " + error.getMessage() + "\n";
        }
        IntegrationException te = new IntegrationException("Can't process Braintree authorization " + errorString);
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    if (StringUtils.isBlank(authorizationId)) {
        IntegrationException te = new IntegrationException("Can't process Braintree, missing authorizationId");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    Transaction trx = new Transaction();
    trx.setAmount(amount);
    trx.setTransactionDate(new Date());
    trx.setTransactionType(TransactionType.AUTHORIZE);
    trx.setPaymentType(PaymentType.CREDITCARD);
    trx.getTransactionDetails().put("TRANSACTIONID", authorizationId);
    trx.getTransactionDetails().put("TRNAPPROVED", null);
    trx.getTransactionDetails().put("TRNORDERNUMBER", authorizationId);
    trx.getTransactionDetails().put("MESSAGETEXT", null);
    return trx;
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Transaction(com.salesmanager.core.model.payments.Transaction) Environment(com.braintreegateway.Environment) BraintreeGateway(com.braintreegateway.BraintreeGateway) ValidationError(com.braintreegateway.ValidationError) TransactionRequest(com.braintreegateway.TransactionRequest) Date(java.util.Date)

Aggregations

IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)42 Date (java.util.Date)18 Transaction (com.salesmanager.core.model.payments.Transaction)17 AuthenticationException (com.stripe.exception.AuthenticationException)11 CardException (com.stripe.exception.CardException)11 InvalidRequestException (com.stripe.exception.InvalidRequestException)11 StripeException (com.stripe.exception.StripeException)11 HashMap (java.util.HashMap)10 ServiceException (com.salesmanager.core.business.exception.ServiceException)9 ArrayList (java.util.ArrayList)8 ModuleConfig (com.salesmanager.core.model.system.ModuleConfig)5 PaymentIntent (com.stripe.model.PaymentIntent)5 BraintreeGateway (com.braintreegateway.BraintreeGateway)4 Environment (com.braintreegateway.Environment)4 ValidationError (com.braintreegateway.ValidationError)4 ShippingOption (com.salesmanager.core.model.shipping.ShippingOption)4 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)4 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)4 ShippingQuoteModule (com.salesmanager.core.modules.integration.shipping.model.ShippingQuoteModule)4 Charge (com.stripe.model.Charge)4