Exemplo n.º 1
0
 @Test
 public void testChargeRetrievePerCallAPIKey() throws StripeException {
   Charge createdCharge = Charge.create(defaultChargeParams, Stripe.apiKey);
   Charge retrievedCharge = Charge.retrieve(createdCharge.getId(), Stripe.apiKey);
   assertEquals(createdCharge.getCreated(), retrievedCharge.getCreated());
   assertEquals(createdCharge.getId(), retrievedCharge.getId());
 }
Exemplo n.º 2
0
 /**
  * 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);
   }
 }