Search in sources :

Example 6 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class Stripe3Payment method initTransaction.

@Override
public Transaction initTransaction(MerchantStore store, Customer customer, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    String strAmount = String.valueOf(amount);
    strAmount = strAmount.replace(".", "");
    Transaction transaction = new Transaction();
    try {
        String apiKey = configuration.getIntegrationKeys().get("secretKey");
        if (StringUtils.isBlank(apiKey)) {
            IntegrationException te = new IntegrationException("Can't process Stripe, missing payment.metaData");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        Stripe.apiKey = apiKey;
        PaymentIntentCreateParams createParams = new PaymentIntentCreateParams.Builder().setCurrency(store.getCurrency().getCode()).setAmount(Long.parseLong(strAmount)).setCaptureMethod(PaymentIntentCreateParams.CaptureMethod.MANUAL).build();
        // Create a PaymentIntent with the order amount and currency
        PaymentIntent intent = PaymentIntent.create(createParams);
        intent.getClientSecret();
        transaction.setAmount(amount);
        // transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.AUTHORIZE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", intent.getId());
        transaction.getTransactionDetails().put("TRNAPPROVED", intent.getStatus());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", intent.getId());
        transaction.getTransactionDetails().put("INTENTSECRET", intent.getClientSecret());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
    } catch (Exception e) {
        throw buildException(e);
    }
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) PaymentIntentCreateParams(com.stripe.param.PaymentIntentCreateParams) PaymentIntent(com.stripe.model.PaymentIntent) Date(java.util.Date) CardException(com.stripe.exception.CardException) InvalidRequestException(com.stripe.exception.InvalidRequestException) AuthenticationException(com.stripe.exception.AuthenticationException) StripeException(com.stripe.exception.StripeException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 7 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class StripePayment method refund.

@Override
public Transaction refund(boolean partial, MerchantStore store, Transaction transaction, Order order, BigDecimal amount, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    String apiKey = configuration.getIntegrationKeys().get("secretKey");
    if (StringUtils.isBlank(apiKey)) {
        IntegrationException te = new IntegrationException("Can't process Stripe, missing payment.metaData");
        te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
        te.setMessageCode("message.payment.error");
        te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
        throw te;
    }
    try {
        String trnID = transaction.getTransactionDetails().get("TRNORDERNUMBER");
        String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
        Stripe.apiKey = apiKey;
        // stripe does not support floating point
        // so amnt * 100 or remove floating point
        // 553.47 = 55347
        String strAmount = String.valueOf(amnt);
        strAmount = strAmount.replace(".", "");
        Charge ch = Charge.retrieve(trnID);
        Map<String, Object> params = new HashMap<>();
        params.put("charge", ch.getId());
        params.put("amount", strAmount);
        Refund re = Refund.create(params);
        transaction = new Transaction();
        transaction.setAmount(order.getTotal());
        transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.CAPTURE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", transaction.getTransactionDetails().get("TRANSACTIONID"));
        transaction.getTransactionDetails().put("TRNAPPROVED", re.getReason());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", re.getId());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
        return transaction;
    } catch (Exception e) {
        throw buildException(e);
    }
}
Also used : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) Refund(com.stripe.model.Refund) Transaction(com.salesmanager.core.model.payments.Transaction) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) Date(java.util.Date) CardException(com.stripe.exception.CardException) InvalidRequestException(com.stripe.exception.InvalidRequestException) AuthenticationException(com.stripe.exception.AuthenticationException) StripeException(com.stripe.exception.StripeException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 8 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class StripePayment method authorize.

@Override
public Transaction authorize(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Transaction transaction = new Transaction();
    try {
        String apiKey = configuration.getIntegrationKeys().get("secretKey");
        if (payment.getPaymentMetaData() == null || StringUtils.isBlank(apiKey)) {
            IntegrationException te = new IntegrationException("Can't process Stripe, missing payment.metaData");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        /**
         * this is send by stripe from tokenization ui
         */
        String token = payment.getPaymentMetaData().get("stripe_token");
        if (StringUtils.isBlank(token)) {
            IntegrationException te = new IntegrationException("Can't process Stripe, missing stripe token");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        String amnt = productPriceUtils.getAdminFormatedAmount(store, amount);
        // stripe does not support floating point
        // so amnt * 100 or remove floating point
        // 553.47 = 55347
        String strAmount = String.valueOf(amnt);
        strAmount = strAmount.replace(".", "");
        Map<String, Object> chargeParams = new HashMap<String, Object>();
        chargeParams.put("amount", strAmount);
        chargeParams.put("capture", false);
        chargeParams.put("currency", store.getCurrency().getCode());
        // obtained with Stripe.js
        chargeParams.put("source", token);
        chargeParams.put("description", new StringBuilder().append(TRANSACTION).append(" - ").append(store.getStorename()).toString());
        Stripe.apiKey = apiKey;
        Charge ch = Charge.create(chargeParams);
        // Map<String,String> metadata = ch.getMetadata();
        transaction.setAmount(amount);
        // transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.AUTHORIZE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", token);
        transaction.getTransactionDetails().put("TRNAPPROVED", ch.getStatus());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", ch.getId());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
    } catch (Exception e) {
        throw buildException(e);
    }
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) HashMap(java.util.HashMap) Charge(com.stripe.model.Charge) Date(java.util.Date) CardException(com.stripe.exception.CardException) InvalidRequestException(com.stripe.exception.InvalidRequestException) AuthenticationException(com.stripe.exception.AuthenticationException) StripeException(com.stripe.exception.StripeException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException)

Example 9 with Transaction

use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.

the class BeanStreamPayment method parseResponse.

private Transaction parseResponse(TransactionType transactionType, PaymentType paymentType, Map<String, String> nvp, BigDecimal amount) throws Exception {
    Transaction transaction = new Transaction();
    transaction.setAmount(amount);
    // transaction.setOrder(order);
    transaction.setTransactionDate(new Date());
    transaction.setTransactionType(transactionType);
    transaction.setPaymentType(PaymentType.CREDITCARD);
    transaction.getTransactionDetails().put("TRANSACTIONID", (String) nvp.get("TRNID"));
    transaction.getTransactionDetails().put("TRNAPPROVED", (String) nvp.get("TRNAPPROVED"));
    transaction.getTransactionDetails().put("TRNORDERNUMBER", (String) nvp.get("TRNORDERNUMBER"));
    transaction.getTransactionDetails().put("MESSAGETEXT", (String) nvp.get("MESSAGETEXT"));
    if (nvp.get("INTERNALORDERID") != null) {
        transaction.getTransactionDetails().put("INTERNALORDERID", (String) nvp.get("INTERNALORDERID"));
    }
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) Date(java.util.Date)

Example 10 with Transaction

use of com.salesmanager.core.model.payments.Transaction 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)

Aggregations

Transaction (com.salesmanager.core.model.payments.Transaction)38 Date (java.util.Date)25 IntegrationException (com.salesmanager.core.modules.integration.IntegrationException)17 ServiceException (com.salesmanager.core.business.exception.ServiceException)15 HashMap (java.util.HashMap)10 AuthenticationException (com.stripe.exception.AuthenticationException)9 CardException (com.stripe.exception.CardException)9 InvalidRequestException (com.stripe.exception.InvalidRequestException)9 StripeException (com.stripe.exception.StripeException)9 BraintreeGateway (com.braintreegateway.BraintreeGateway)5 Environment (com.braintreegateway.Environment)5 Order (com.salesmanager.core.model.order.Order)5 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)5 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)5 PaymentModule (com.salesmanager.core.modules.integration.payment.model.PaymentModule)5 ReadableTransaction (com.salesmanager.shop.model.order.transaction.ReadableTransaction)5 PaymentIntent (com.stripe.model.PaymentIntent)5 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 ValidationError (com.braintreegateway.ValidationError)4