/** * This method processes the pending payment using the configured payment gateway (at the time of * writing, only STRIPE) and returns a PaymentResult. In order to preserve the consistency of the * payment, when a non-gateway Exception is thrown, it rethrows an IllegalStateException * * @param reservationId * @param gatewayToken * @param price * @param event * @param email * @param customerName * @param billingAddress * @return PaymentResult * @throws java.lang.IllegalStateException if there is an error after charging the credit card */ public PaymentResult processPayment( String reservationId, String gatewayToken, int price, Event event, String email, CustomerName customerName, String billingAddress) { try { final Charge charge = stripeManager.chargeCreditCard( gatewayToken, price, event, reservationId, email, customerName.getFullName(), billingAddress); log.info("transaction {} paid: {}", reservationId, charge.getPaid()); transactionRepository.insert( charge.getId(), reservationId, ZonedDateTime.now(), price, event.getCurrency(), charge.getDescription(), PaymentProxy.STRIPE.name()); return PaymentResult.successful(charge.getId()); } catch (Exception e) { if (e instanceof StripeException) { return PaymentResult.unsuccessful(stripeManager.handleException((StripeException) e)); } throw new IllegalStateException(e); } }
public PaymentResult processPaypalPayment( String reservationId, String token, String payerId, int price, Event event) { try { String transactionId = paypalManager.commitPayment(reservationId, token, payerId, event); transactionRepository.insert( transactionId, reservationId, ZonedDateTime.now(), price, event.getCurrency(), "Paypal confirmation", PaymentProxy.PAYPAL.name()); return PaymentResult.successful(transactionId); } catch (Exception e) { log.warn("errow while processing paypal payment: " + e.getMessage(), e); if (e instanceof PayPalRESTException) { return PaymentResult.unsuccessful(ErrorsCode.STEP_2_PAYPAL_UNEXPECTED); } throw new IllegalStateException(e); } }