use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class OrderServiceImpl method getCapturableOrders.
@Override
public List<Order> getCapturableOrders(MerchantStore store, Date startDate, Date endDate) throws ServiceException {
List<Transaction> transactions = transactionService.listTransactions(startDate, endDate);
List<Order> returnOrders = null;
if (!CollectionUtils.isEmpty(transactions)) {
returnOrders = new ArrayList<Order>();
// order id
Map<Long, Order> preAuthOrders = new HashMap<Long, Order>();
// order id
Map<Long, List<Transaction>> processingTransactions = new HashMap<Long, List<Transaction>>();
for (Transaction trx : transactions) {
Order order = trx.getOrder();
if (TransactionType.AUTHORIZE.name().equals(trx.getTransactionType().name())) {
preAuthOrders.put(order.getId(), order);
}
// put transaction
List<Transaction> listTransactions = null;
if (processingTransactions.containsKey(order.getId())) {
listTransactions = processingTransactions.get(order.getId());
} else {
listTransactions = new ArrayList<Transaction>();
processingTransactions.put(order.getId(), listTransactions);
}
listTransactions.add(trx);
}
for (Long orderId : processingTransactions.keySet()) {
List<Transaction> trx = processingTransactions.get(orderId);
if (CollectionUtils.isNotEmpty(trx)) {
boolean capturable = true;
for (Transaction t : trx) {
if (TransactionType.CAPTURE.name().equals(t.getTransactionType().name())) {
capturable = false;
} else if (TransactionType.AUTHORIZECAPTURE.name().equals(t.getTransactionType().name())) {
capturable = false;
} else if (TransactionType.REFUND.name().equals(t.getTransactionType().name())) {
capturable = false;
}
}
if (capturable) {
Order o = preAuthOrders.get(orderId);
returnOrders.add(o);
}
}
}
}
return returnOrders;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class PersistableTransactionPopulator method populate.
@Override
public Transaction populate(PersistableTransaction source, Transaction target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableTransaction must not be null");
Validate.notNull(orderService, "OrderService must not be null");
Validate.notNull(pricingService, "OrderService must not be null");
if (target == null) {
target = new Transaction();
}
try {
target.setAmount(pricingService.getAmount(source.getAmount()));
target.setDetails(source.getDetails());
target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
if (source.getOrderId() != null && source.getOrderId().longValue() > 0) {
Order order = orderService.getById(source.getOrderId());
if (order == null) {
throw new ConversionException("Order with id " + source.getOrderId() + "does not exist");
}
target.setOrder(order);
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class OrderFacadeImpl method captureOrder.
@Override
public ReadableTransaction captureOrder(MerchantStore store, Order order, Customer customer, Language language) throws Exception {
Transaction transactionModel = paymentService.processCapturePayment(order, customer, store);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, store, language);
return transaction;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class OrderPaymentApi method init.
@RequestMapping(value = { "/cart/{code}/payment/init" }, method = RequestMethod.POST)
@ResponseBody
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableTransaction init(@Valid @RequestBody PersistablePayment payment, @PathVariable String code, @ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language) throws Exception {
ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
PersistablePaymentPopulator populator = new PersistablePaymentPopulator();
populator.setPricingService(pricingService);
Payment paymentModel = new Payment();
populator.populate(payment, paymentModel, merchantStore, language);
Transaction transactionModel = paymentService.initTransaction(null, paymentModel, merchantStore);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, merchantStore, language);
return transaction;
}
use of com.salesmanager.core.model.payments.Transaction in project shopizer by shopizer-ecommerce.
the class PayPalExpressCheckoutPayment method capture.
@Override
public Transaction capture(MerchantStore store, Customer customer, Order order, Transaction capturableTransaction, IntegrationConfiguration configuration, IntegrationModule module) throws IntegrationException {
try {
Validate.notNull(capturableTransaction, "Transaction cannot be null");
Validate.notNull(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), "Transaction details must contain a TRANSACTIONID");
Validate.notNull(order, "Order must not be null");
Validate.notNull(order.getCurrency(), "Order nust contain Currency object");
String mode = "sandbox";
String env = configuration.getEnvironment();
if (Constants.PRODUCTION_ENVIRONMENT.equals(env)) {
mode = "production";
}
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"));
DoCaptureReq doCaptureReq = new DoCaptureReq();
BasicAmountType amount = new BasicAmountType();
amount.setValue(pricingService.getStringAmount(order.getTotal(), store));
amount.setCurrencyID(urn.ebay.apis.eBLBaseComponents.CurrencyCodeType.fromValue(order.getCurrency().getCode()));
// DoCaptureRequest which takes mandatory params:
//
// Authorization ID - Authorization identification number of the
// payment you want to capture. This is the transaction ID
DoCaptureRequestType doCaptureRequest = new DoCaptureRequestType(capturableTransaction.getTransactionDetails().get("TRANSACTIONID"), amount, CompleteCodeType.NOTCOMPLETE);
doCaptureReq.setDoCaptureRequest(doCaptureRequest);
// ## Creating service wrapper object
// Creating service wrapper object to make API call and loading
// configuration file for your credentials and endpoint
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
DoCaptureResponseType doCaptureResponse = null;
// ## Making API call
// Invoke the appropriate method corresponding to API in service
// wrapper object
doCaptureResponse = service.doCapture(doCaptureReq);
// ### Success values
if (!"Success".equals(doCaptureResponse.getAck().getValue())) {
LOGGER.error("Wrong value from transaction commit " + doCaptureResponse.getAck().getValue());
throw new IntegrationException("Wrong paypal ack from refund transaction " + doCaptureResponse.getAck().getValue());
}
// if (doCaptureResponse.getAck().getValue()
// .equalsIgnoreCase("success")) {
// Authorization identification number
// logger.info("Authorization ID:"
// + doCaptureResponse.getDoCaptureResponseDetails()
// .getAuthorizationID());
// }
// ### Error Values
// Access error values from error list using getter methods
// else {
// List<ErrorType> errorList = doCaptureResponse.getErrors();
// logger.severe("API Error Message : "
// + errorList.get(0).getLongMessage());
// }
// String refundAck = refundTransactionResponse.getAck().getValue();
Transaction newTransaction = new Transaction();
newTransaction.setAmount(order.getTotal());
newTransaction.setTransactionDate(new Date());
newTransaction.setTransactionType(TransactionType.CAPTURE);
newTransaction.setPaymentType(PaymentType.PAYPAL);
newTransaction.getTransactionDetails().put("AUTHORIZATIONID", doCaptureResponse.getDoCaptureResponseDetails().getAuthorizationID());
newTransaction.getTransactionDetails().put("TRANSACTIONID", capturableTransaction.getTransactionDetails().get("TRANSACTIONID"));
return newTransaction;
} catch (Exception e) {
throw new IntegrationException(e);
}
}
Aggregations