String bankResponseCode = resp.getValue("response_code");
LOGGER.debug("bankResponseCode ="+bankResponseCode);
String transactionId = resp.getValue("transaction_id");
LOGGER.debug("transactionId ="+transactionId);
Order pendingOrder = Portal.getInstance().getPricingService().getOrder(Long.valueOf(orderId));
LOGGER.debug("pendingOrder ="+pendingOrder);
//payment authorized
if(pendingOrder != null) {
LOGGER.info("order:" + pendingOrder.getId() + "found for this payment");
PaymentInfo paymentInfo = Portal.getInstance().getPricingService().getPayment(pendingOrder);
LOGGER.debug("paymentInfo ="+paymentInfo);
//verify that payment is not yet registered
if(paymentInfo == null) {
//send email confirmation
if(!pendingOrder.getBuyer().isMailVerified()) {
ServiceFactory.getRegistrationService().sendEmailVerification(pendingOrder.getBuyer());
}
//store payment info
LOGGER.info("creating payment info...");
paymentInfo = Portal.getInstance().getPricingService().newPaymentInfo(pendingOrder, transactionId, authorisationId, bankResponseCode);
if(PricingService.RESPONSE_OK.equals(bankResponseCode)) {
//create license
pendingOrder.setStatus(Order.ORDER_PAYED);
LOGGER.info("order " + pendingOrder.getId() + " payed...");
DaoFactory.getOrderDao().save(pendingOrder);
LOGGER.info("creating licence...");
List lic = ServiceFactory.getLicenseService().addLicense(pendingOrder);
UserImpl buyer = pendingOrder.getBuyer();
// We modify user for fidelity
Product p = pendingOrder.getPrice().getProduct();
int years = pendingOrder.getSubscribedYears();
FidelityService fs = ServiceFactory.getFidelityService();
fs.buy(buyer, p, years, pendingOrder.getSubscribedUsers());
LOGGER.info("creating invoice...");
Invoice invoice = ServiceFactory.getCommercialService().createInvoice(pendingOrder, pendingOrder.getPurchaser());
ServiceFactory.getRegistrationService().sendLicenseBuyConfirmationMail(pendingOrder.getBuyer(), pendingOrder, lic, invoice);
LOGGER.info("payment created");
return paymentInfo;
} else {
// TODO g�rer annulation ou refus de paiement
pendingOrder.setStatus(Order.ORDER_PAYMENT_REFUSED);
LOGGER.info("order " + pendingOrder.getId() + " payment refused, code : " + bankResponseCode);
DaoFactory.getOrderDao().save(pendingOrder);
LOGGER.warn("Payment refused by bank return code:"+bankResponseCode);
PaymentRefusedException e = new PaymentRefusedException(bankResponseCode);
e.appendError(RessourceBundleApplicationMessage.error("registration.payment-form.error." + bankResponseCode, null));
throw e;
}
} else {
LOGGER.info("payment already done for order " + pendingOrder.getId());
}
return paymentInfo;
} else {
throw ServiceException.create("Internal error", "No order found withid="+orderId+" defined in transaction id="+transactionId, null);
}