use of com.salesmanager.shop.model.order.transaction.PersistablePayment in project shopizer by shopizer-ecommerce.
the class PersistablePaymentPopulator method populate.
@Override
public Payment populate(PersistablePayment source, Payment target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistablePayment cannot be null");
Validate.notNull(pricingService, "pricingService must be set");
if (target == null) {
target = new Payment();
}
try {
target.setAmount(pricingService.getAmount(source.getAmount()));
target.setModuleName(source.getPaymentModule());
target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("paymentToken", source.getPaymentToken());
target.setPaymentMetaData(metadata);
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.shop.model.order.transaction.PersistablePayment 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.shop.model.order.transaction.PersistablePayment in project shopizer by shopizer-ecommerce.
the class OrderPaymentApi method init.
@RequestMapping(value = { "/auth/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, HttpServletRequest request, HttpServletResponse response) throws Exception {
try {
Principal principal = request.getUserPrincipal();
String userName = principal.getName();
Customer customer = customerService.getByNick(userName);
if (customer == null) {
response.sendError(401, "Error while initializing the payment customer not authorized");
return null;
}
ShoppingCart cart = shoppingCartService.getByCode(code, merchantStore);
if (cart == null) {
throw new ResourceNotFoundException("Cart code " + code + " does not exist");
}
if (cart.getCustomerId() == null) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
return null;
}
if (cart.getCustomerId().longValue() != customer.getId().longValue()) {
response.sendError(404, "Cart code " + code + " does not exist for exist for user " + userName);
return null;
}
PersistablePaymentPopulator populator = new PersistablePaymentPopulator();
populator.setPricingService(pricingService);
Payment paymentModel = new Payment();
populator.populate(payment, paymentModel, merchantStore, language);
Transaction transactionModel = paymentService.initTransaction(customer, paymentModel, merchantStore);
ReadableTransaction transaction = new ReadableTransaction();
ReadableTransactionPopulator trxPopulator = new ReadableTransactionPopulator();
trxPopulator.setOrderService(orderService);
trxPopulator.setPricingService(pricingService);
trxPopulator.populate(transactionModel, transaction, merchantStore, language);
return transaction;
} catch (Exception e) {
LOGGER.error("Error while initializing the payment", e);
try {
response.sendError(503, "Error while initializing the payment " + e.getMessage());
} catch (Exception ignore) {
}
return null;
}
}
Aggregations