private OrderPayPalDTO valueOf(ProfilePayPalDTO profile, OrderFullDTO order) { OrderPayPalDTO ordPp = new OrderPayPalDTO(); ordPp.setAricles(order.getCart()); ordPp.setIdOrder(order.getIdOrder().toString()); // importi ordPp.setDeliveryCost(order.getSpeseSpedizione()); ordPp.setTotalItemOrder(order.getImItemOrdine()); ordPp.setTotalDiscountOrder(order.getImOrdineDiscount()); ordPp.setTotalPriceOrder(order.getImOrdine()); ordPp.setCancelUrl(profile.getCancelUrl()); ordPp.setImageUrl(profile.getImageUrl()); ordPp.setLocale(profile.getLang()); ordPp.setRedirectUrl(profile.getRedirectUrl()); ordPp.setReturnUrl(profile.getReturnUrl()); // sconti if (order.getImOrdineDiscount() != null && order.getImOrdineDiscount().compareTo(BigDecimal.ZERO) > 0) { ordPp.setTxDiscounted(null); if (order.getIdCoupon() != null) { ordPp.setTxDiscounted(order.getIdCoupon()); } if (order.getIdFidelity() != null) { if (ordPp.getTxDiscounted() == null) { ordPp.setTxDiscounted(order.getIdFidelity()); } else { ordPp.setTxDiscounted(ordPp.getTxDiscounted() + "-" + order.getIdFidelity()); } } } return ordPp; }
@Override public DoExpressCheckoutPaymentDTO doExpressCheckoutPayment( GetExpressCheckoutDetailsDTO details, ProfilePayPalDTO profile, OrderFullDTO order) throws PayPalFundingFailureException, PayPalException, PayPalFailureException, StockNotPresentException, PayPalPostPaymentException { // TODO Auto-generated method stub // VERIFICO LA GIACENZA orderService.checkQtaInStock(order.getIdOrder(), order); // effettuo il doCheckOut, si paga... DoExpressCheckoutPaymentDTO checkDTO = getWrapper(profile) .doExpressCheckoutPayment( details, profilePayPal.getNotifyUrl(), profilePayPal.getRedirectUrl()); order.setIdTransaction(checkDTO.getPAYMENTINFO_0_TRANSACTIONID()); order.setIdStato( TypeStateOrder.fromString(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS()).getState()); order.setPendingReason(checkDTO.getPAYMENTINFO_0_PENDINGREASON()); try { // aggiorno l'ordine con lo stato, se completed o pending facciamo // anche // il decremento della qta TypeStateOrder state = TypeStateOrder.fromString(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS()); log.info( String.format( "stato PayPal %s- stato Othala %s", checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS(), Integer.toString(state.getState()))); if (isPaymentCompleted(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS()) || isPaymentPending(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS())) { orderService.confirmOrderPayment(order); } else { orderService.updateStateOrder(order.getIdOrder(), order, state); } // salvo il messaggio MessageIpnDTO ipn = new MessageIpnDTO(); ipn.setFgElaborato(false); ipn.setIdOrder(order.getIdOrder()); ipn.setIdTransaction(order.getIdTransaction()); ipn.setTxMessage(checkDTO.getOkMessage()); if (state.getState() == TypeStateOrder.PENDING.getState()) { ipn.setTxNote(checkDTO.getPAYMENTINFO_0_PENDINGREASON()); } ipn.setTxStato(checkDTO.getPAYMENTINFO_0_PAYMENTSTATUS()); messageIpnDAO.insertMessageIpn(ipn); } catch (Throwable e) { log.error("errore PaymentService dopo il pagamento", e); throw new PayPalPostPaymentException( e, order.getIdOrder(), "errore nel docheckout dopo il pagamento"); } return checkDTO; }