Search in sources :

Example 26 with Transaction

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

the class StripePayment method authorizeAndCapture.

@Override
public Transaction authorizeAndCapture(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    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;
    }
    String token = payment.getPaymentMetaData().get("stripe_token");
    if (StringUtils.isBlank(token)) {
        // possibly from api
        // from api
        token = payment.getPaymentMetaData().get("paymentToken");
    }
    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;
    }
    Transaction transaction = new Transaction();
    try {
        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", true);
        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.AUTHORIZECAPTURE);
        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 : IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) 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 27 with Transaction

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

the class BraintreePayment 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 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");
    Environment environment = Environment.PRODUCTION;
    if (configuration.getEnvironment().equals("TEST")) {
        // sandbox
        environment = Environment.SANDBOX;
    }
    BraintreeGateway gateway = new BraintreeGateway(environment, merchantId, publicKey, privateKey);
    String clientToken = gateway.clientToken().generate();
    Transaction transaction = new Transaction();
    transaction.setAmount(amount);
    transaction.setDetails(clientToken);
    transaction.setPaymentType(payment.getPaymentType());
    transaction.setTransactionDate(new Date());
    transaction.setTransactionType(payment.getTransactionType());
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) Environment(com.braintreegateway.Environment) BraintreeGateway(com.braintreegateway.BraintreeGateway) Date(java.util.Date)

Example 28 with Transaction

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

the class MoneyOrderPayment method authorizeAndCapture.

/*	@Override
	public Transaction capture(MerchantStore store, Customer customer,
			List<ShoppingCartItem> items, BigDecimal amount, Payment payment, Transaction transaction,
			IntegrationConfiguration configuration, IntegrationModule module)
			throws IntegrationException {
		//NOT REQUIRED
		return null;
	}*/
@Override
public Transaction authorizeAndCapture(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    Transaction transaction = new Transaction();
    transaction.setAmount(amount);
    transaction.setTransactionDate(new Date());
    transaction.setTransactionType(TransactionType.AUTHORIZECAPTURE);
    transaction.setPaymentType(PaymentType.MONEYORDER);
    return transaction;
}
Also used : Transaction(com.salesmanager.core.model.payments.Transaction) Date(java.util.Date)

Example 29 with Transaction

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

the class PayPalExpressCheckoutPayment method processTransaction.

private Transaction processTransaction(MerchantStore store, Customer customer, List<ShoppingCartItem> items, BigDecimal amount, Payment payment, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
    com.salesmanager.core.model.payments.PaypalPayment paypalPayment = (com.salesmanager.core.model.payments.PaypalPayment) payment;
    try {
        String mode = "sandbox";
        String env = configuration.getEnvironment();
        if (Constants.PRODUCTION_ENVIRONMENT.equals(env)) {
            mode = "production";
        }
        // get token from url and return the user to generate a payerid
        GetExpressCheckoutDetailsRequestType getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(paypalPayment.getPaymentToken());
        getExpressCheckoutDetailsRequest.setVersion("104.0");
        GetExpressCheckoutDetailsReq getExpressCheckoutDetailsReq = new GetExpressCheckoutDetailsReq();
        getExpressCheckoutDetailsReq.setGetExpressCheckoutDetailsRequest(getExpressCheckoutDetailsRequest);
        Map<String, String> configurationMap = new HashMap<String, String>();
        configurationMap.put("mode", mode);
        configurationMap.put("acct1.UserName", configuration.getIntegrationKeys().get("username"));
        configurationMap.put("acct1.Password", configuration.getIntegrationKeys().get("api"));
        configurationMap.put("acct1.Signature", configuration.getIntegrationKeys().get("signature"));
        PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
        GetExpressCheckoutDetailsResponseType getExpressCheckoutDetailsResponse = service.getExpressCheckoutDetails(getExpressCheckoutDetailsReq);
        String token = getExpressCheckoutDetailsResponse.getGetExpressCheckoutDetailsResponseDetails().getToken();
        String correlationID = getExpressCheckoutDetailsResponse.getCorrelationID();
        String ack = getExpressCheckoutDetailsResponse.getAck().getValue();
        String payerId = getExpressCheckoutDetailsResponse.getGetExpressCheckoutDetailsResponseDetails().getPayerInfo().getPayerID();
        if (!"Success".equals(ack)) {
            LOGGER.error("Wrong value from anthorize and capture transaction " + ack);
            throw new IntegrationException("Wrong paypal ack from init transaction " + ack);
        }
        PaymentDetailsType paymentDetail = new PaymentDetailsType();
        /**
         * IPN *
         */
        // paymentDetail.setNotifyURL("http://replaceIpnUrl.com");
        BasicAmountType orderTotal = new BasicAmountType();
        orderTotal.setValue(pricingService.getStringAmount(amount, store));
        orderTotal.setCurrencyID(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType.fromValue(payment.getCurrency().getCode()));
        paymentDetail.setOrderTotal(orderTotal);
        paymentDetail.setButtonSource("Shopizer_Cart_AP");
        /**
         * sale or pre-auth *
         */
        if (payment.getTransactionType().name().equals(TransactionType.AUTHORIZE.name())) {
            paymentDetail.setPaymentAction(urn.ebay.apis.eBLBaseComponents.PaymentActionCodeType.AUTHORIZATION);
        } else {
            paymentDetail.setPaymentAction(urn.ebay.apis.eBLBaseComponents.PaymentActionCodeType.SALE);
        }
        List<PaymentDetailsType> paymentDetails = new ArrayList<PaymentDetailsType>();
        paymentDetails.add(paymentDetail);
        DoExpressCheckoutPaymentRequestDetailsType doExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
        doExpressCheckoutPaymentRequestDetails.setToken(token);
        doExpressCheckoutPaymentRequestDetails.setPayerID(payerId);
        doExpressCheckoutPaymentRequestDetails.setPaymentDetails(paymentDetails);
        DoExpressCheckoutPaymentRequestType doExpressCheckoutPaymentRequest = new DoExpressCheckoutPaymentRequestType(doExpressCheckoutPaymentRequestDetails);
        doExpressCheckoutPaymentRequest.setVersion("104.0");
        DoExpressCheckoutPaymentReq doExpressCheckoutPaymentReq = new DoExpressCheckoutPaymentReq();
        doExpressCheckoutPaymentReq.setDoExpressCheckoutPaymentRequest(doExpressCheckoutPaymentRequest);
        DoExpressCheckoutPaymentResponseType doExpressCheckoutPaymentResponse = service.doExpressCheckoutPayment(doExpressCheckoutPaymentReq);
        String commitAck = doExpressCheckoutPaymentResponse.getAck().getValue();
        if (!"Success".equals(commitAck)) {
            LOGGER.error("Wrong value from transaction commit " + ack);
            throw new IntegrationException("Wrong paypal ack from init transaction " + ack);
        }
        List<PaymentInfoType> paymentInfoList = doExpressCheckoutPaymentResponse.getDoExpressCheckoutPaymentResponseDetails().getPaymentInfo();
        String transactionId = null;
        for (PaymentInfoType paymentInfo : paymentInfoList) {
            transactionId = paymentInfo.getTransactionID();
        }
        // TOKEN=EC-90U93956LU4997256&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2014-02-16T15:41:03Z&CORRELATIONID=39d4ab666c1d7&ACK=Success&VERSION=104.0&BUILD=9720069&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=4YA742984J1256935&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2014-02-16T15:41:03Z&PAYMENTINFO_0_AMT=1.00&PAYMENTINFO_0_FEEAMT=0.33&PAYMENTINFO_0_TAXAMT=0.00&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible,UnauthorizedPaymentEligible&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=TWLK53YN7GDM6&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success
        Transaction transaction = new Transaction();
        transaction.setAmount(amount);
        transaction.setTransactionDate(new Date());
        transaction.setTransactionType(payment.getTransactionType());
        transaction.setPaymentType(PaymentType.PAYPAL);
        transaction.getTransactionDetails().put("TOKEN", token);
        transaction.getTransactionDetails().put("PAYERID", payerId);
        transaction.getTransactionDetails().put("TRANSACTIONID", transactionId);
        transaction.getTransactionDetails().put("CORRELATION", correlationID);
        return transaction;
    } catch (Exception e) {
        throw new IntegrationException(e);
    }
}
Also used : HashMap(java.util.HashMap) BasicAmountType(urn.ebay.apis.CoreComponentTypes.BasicAmountType) ArrayList(java.util.ArrayList) GetExpressCheckoutDetailsReq(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsReq) GetExpressCheckoutDetailsRequestType(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsRequestType) GetExpressCheckoutDetailsResponseType(urn.ebay.api.PayPalAPI.GetExpressCheckoutDetailsResponseType) PaymentInfoType(urn.ebay.apis.eBLBaseComponents.PaymentInfoType) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) DoExpressCheckoutPaymentResponseType(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentResponseType) PayPalAPIInterfaceServiceService(urn.ebay.api.PayPalAPI.PayPalAPIInterfaceServiceService) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) IntegrationException(com.salesmanager.core.modules.integration.IntegrationException) DoExpressCheckoutPaymentRequestDetailsType(urn.ebay.apis.eBLBaseComponents.DoExpressCheckoutPaymentRequestDetailsType) Transaction(com.salesmanager.core.model.payments.Transaction) PaymentDetailsType(urn.ebay.apis.eBLBaseComponents.PaymentDetailsType) DoExpressCheckoutPaymentReq(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentReq) DoExpressCheckoutPaymentRequestType(urn.ebay.api.PayPalAPI.DoExpressCheckoutPaymentRequestType)

Example 30 with Transaction

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

the class OrderFacadeImpl method listTransactions.

@Override
public List<ReadableTransaction> listTransactions(Long orderId, MerchantStore store) {
    Validate.notNull(orderId, "orderId must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    List<ReadableTransaction> trx = new ArrayList<ReadableTransaction>();
    try {
        Order modelOrder = orderService.getOrder(orderId, store);
        if (modelOrder == null) {
            throw new ResourceNotFoundException("Order id [" + orderId + "] not found for store [" + store.getCode() + "]");
        }
        List<Transaction> transactions = transactionService.listTransactions(modelOrder);
        ReadableTransaction transaction = null;
        ReadableTransactionPopulator trxPopulator = null;
        for (Transaction tr : transactions) {
            transaction = new ReadableTransaction();
            trxPopulator = new ReadableTransactionPopulator();
            trxPopulator.setOrderService(orderService);
            trxPopulator.setPricingService(pricingService);
            trxPopulator.populate(tr, transaction, store, store.getDefaultLanguage());
            trx.add(transaction);
        }
        return trx;
    } catch (Exception e) {
        LOGGER.error("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
        throw new ServiceRuntimeException("Error while getting transactions for order [" + orderId + "] and store code [" + store.getCode() + "]");
    }
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) Transaction(com.salesmanager.core.model.payments.Transaction) ReadableTransactionPopulator(com.salesmanager.shop.populator.order.transaction.ReadableTransactionPopulator) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

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