Example #1
0
  public boolean expireTicket(final String ticketStr) {
    try {
      final PaymentRequestTicket ticket =
          (PaymentRequestTicket)
              ticketService.load(ticketStr, PaymentRequestTicket.Relationships.FROM_CHANNEL);
      // Check the member restriction
      final Member restricted = WebServiceContext.getMember();
      if (restricted != null && !restricted.equals(ticket.getTo())) {
        throw new Exception();
      }

      // Check the from channel
      final Channel resolvedChannel = WebServiceContext.getChannel();
      final Channel fromChannel = ticket.getFromChannel();
      final Channel toChannel = ticket.getToChannel();
      if ((fromChannel == null || !fromChannel.equals(resolvedChannel))
          && (toChannel == null || !toChannel.equals(resolvedChannel))) {
        throw new Exception();
      }

      // Check by status
      if (ticket.getStatus() == Ticket.Status.PENDING) {
        ticketService.expirePaymentRequestTicket(ticket);
        return true;
      }
    } catch (final Exception e) {
      webServiceHelper.error(e);
      // Ignore exceptions
    }
    return false;
  }