Search in sources :

Example 21 with Transaction

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

the class Stripe3Payment 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(".", "");
        PaymentIntent paymentIntent = PaymentIntent.retrieve(trnID);
        Map<String, Object> params = new HashMap<>();
        params.put("payment_intent", paymentIntent.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) 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 22 with Transaction

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

the class Stripe3Payment 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 the PaymentIntent ID created on the Frontend, that we will now store.
         */
        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;
        }
        Stripe.apiKey = apiKey;
        PaymentIntent paymentIntent = PaymentIntent.retrieve(token);
        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", paymentIntent.getStatus());
        // <---- We store the PI id here
        transaction.getTransactionDetails().put("TRNORDERNUMBER", paymentIntent.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) 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 23 with Transaction

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

the class Stripe3Payment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    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;
        }
        // <---- We retrieve the PI id here
        String chargeId = capturableTransaction.getTransactionDetails().get("TRNORDERNUMBER");
        if (StringUtils.isBlank(chargeId)) {
            IntegrationException te = new IntegrationException("Can't process Stripe capture, missing TRNORDERNUMBER");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        String amnt = productPriceUtils.getAdminFormatedAmount(store, order.getTotal());
        String strAmount = String.valueOf(amnt);
        strAmount = strAmount.replace(".", "");
        Stripe.apiKey = apiKey;
        PaymentIntent paymentIntent = PaymentIntent.retrieve(chargeId);
        PaymentIntentCaptureParams params = PaymentIntentCaptureParams.builder().setAmountToCapture(Long.parseLong(strAmount)).setStatementDescriptor(store.getStorename().length() > 22 ? store.getStorename().substring(0, 22) : store.getStorename()).build();
        paymentIntent = paymentIntent.capture(params);
        transaction.setAmount(order.getTotal());
        transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.CAPTURE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
        transaction.getTransactionDetails().put("TRNAPPROVED", paymentIntent.getStatus());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", paymentIntent.getId());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
        return transaction;
    } catch (Exception e) {
        throw buildException(e);
    }
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) PaymentIntent(com.stripe.model.PaymentIntent) PaymentIntentCaptureParams(com.stripe.param.PaymentIntentCaptureParams) 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 24 with Transaction

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

the class StripePayment method capture.

@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    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;
        }
        String chargeId = capturableTransaction.getTransactionDetails().get("TRNORDERNUMBER");
        if (StringUtils.isBlank(chargeId)) {
            IntegrationException te = new IntegrationException("Can't process Stripe capture, missing TRNORDERNUMBER");
            te.setExceptionType(IntegrationException.TRANSACTION_EXCEPTION);
            te.setMessageCode("message.payment.error");
            te.setErrorCode(IntegrationException.TRANSACTION_EXCEPTION);
            throw te;
        }
        Stripe.apiKey = apiKey;
        Charge ch = Charge.retrieve(chargeId);
        ch.capture();
        transaction.setAmount(order.getTotal());
        transaction.setOrder(order);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(TransactionType.CAPTURE);
        transaction.setPaymentType(PaymentType.CREDITCARD);
        transaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
        transaction.getTransactionDetails().put("TRNAPPROVED", ch.getStatus());
        transaction.getTransactionDetails().put("TRNORDERNUMBER", ch.getId());
        transaction.getTransactionDetails().put("MESSAGETEXT", null);
        return transaction;
    } catch (Exception e) {
        throw buildException(e);
    }
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) 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 25 with Transaction

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

the class StripePayment method initTransaction.

@Override
public Transaction initTransaction(MerchantStore store, Customer customer, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Validate.notNull(configuration, "Configuration cannot be null");
    String publicKey = configuration.getIntegrationKeys().get("publishableKey");
    Validate.notNull(publicKey, "Publishable key not found in configuration");
    Transaction transaction = new Transaction();
    transaction.setAmount(amount);
    transaction.setDetails(publicKey);
    transaction.setPaymentType(payment.getPaymentType());
    transaction.setTransactionDate(new Date());
    transaction.setTransactionType(payment.getTransactionType());
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) 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