@Override
  public BookingInfo payWithStripe(@Named("token") String token, BookingInfo bookingInfo) {
    ObjectifyService.begin();
    logger.info("payWithStripe" + bookingInfo.getPaidPrice());
    Profil profil = bookingServiceManager.getProfil();
    logger.info("payWithStripe" + bookingInfo.getPaidPrice());
    Route route = ofy().load().type(Route.class).id(bookingInfo.getRouteId()).now();
    ContractorInfo contractorInfo = bookingServiceManager.getContractor(bookingInfo);
    Agent agent = ofy().load().type(Agent.class).id(contractorInfo.getAgentId()).now();
    Long orderCount = agent.getOrderCount();
    String orderRef = orderCount + "_" + bookingInfo.getName();

    String refusal = stripePayment.charge(token, bookingInfo, profil.getStripeSecret(), orderRef);
    if (refusal == null) {
      bookingInfo = bookingServiceManager.setPayed(profil, bookingInfo, OrderStatus.PAID, orderRef);
      if (bookingInfo != null) {
        AgentInfo agentInfo = bookingServiceManager.getAgent(contractorInfo);
        Mailer.sendConfirmation(bookingInfo, profil, agentInfo, contractorInfo);
        financeManager.addPayment(bookingInfo, new Date());
        ofy().save().entity(agent).now();
      }
    } else {
      bookingInfo.setStripeRefusalReason(refusal);
    }
    return bookingInfo;
  }
 @Override
 // @ApiMethod(name = "share.request.send", httpMethod = "post")
 public BookingInfo sendShareRequest(BookingInfo bookingInfo) {
   ObjectifyService.begin();
   Profil profil = bookingServiceManager.getProfil();
   BookingInfo parentBooking = bookingServiceManager.getBookingAsInfo(bookingInfo.getParentId());
   Mailer.sendShareRequest(parentBooking, bookingInfo, profil);
   return bookingInfo;
 }
  public void sendRatingRequest() {
    Profil profil = bookingServiceManager.getProfil();
    List<BookingInfo> list = bookingServiceManager.getListFeedbackRequest();
    logger.info("todo size:" + list.size());
    for (BookingInfo bi : list) {
      Mailer.setFeedbackRequest(bi, profil);
    }

    for (BookingInfo bi : bookingServiceManager.getArchiveList()) {
      bookingServiceManager.archive(bi);
    }
  }
 @Override
 @ApiMethod(name = "bookings.agent", path = "bookingsagent", httpMethod = "post")
 public List<BookingInfo> getBookingsForAgent(AgentInfo agentInfo)
     throws IllegalArgumentException {
   ObjectifyService.begin();
   return bookingServiceManager.getBookingsAsInfo(agentInfo.getId());
 }
 @Override
 // @ApiMethod(name = "profil.get", httpMethod = "post")
 public ProfilInfo getPaypalProfil() throws IllegalArgumentException {
   ObjectifyService.begin();
   ProfilInfo profilInfo = bookingServiceManager.getProfil().getInfo();
   logger.info(profilInfo.toString());
   return profilInfo;
 }
  @Override
  public List<BookingInfo> cancelBooking(BookingInfo bookingInfo, AgentInfo agentInfo)
      throws IllegalArgumentException {
    bookingServiceManager.cancel(bookingInfo);
    financeManager.cancel(bookingInfo.getId());

    return getBookingsForAgent(agentInfo);
  }
 @Override
 @ApiMethod(name = "bookings.route", path = "bookingsroute", httpMethod = "post")
 public List<BookingInfo> getBookingsForRoute(RouteInfo routeInfo)
     throws IllegalArgumentException {
   ObjectifyService.begin();
   logger.info("route inquiry:" + routeInfo.getStart() + " -> " + routeInfo.getEnd());
   return bookingServiceManager.getBookingsForRoute(routeInfo);
 }
  @Override
  @ApiMethod(name = "bookings.share.accepted", httpMethod = "post")
  public List<BookingInfo> handleShareAccepted(@Named("id") Long sharerId)
      throws IllegalArgumentException {
    ObjectifyService.begin();
    BookingInfo sharer = bookingServiceManager.getBookingAsInfo(sharerId);
    BookingInfo parentBookingInfo = bookingServiceManager.getBookingAsInfo(sharer.getParentId());

    BookingInfo sharerBookingInfo = bookingServiceManager.setShareAccepted(sharer);
    List<BookingInfo> list = null;
    if (sharerBookingInfo.getStatus() == SHARE_ACCEPTED) {
      list = Lists.newArrayList(parentBookingInfo, sharerBookingInfo);
      Mailer.sendShareAccepted(
          sharerBookingInfo.getEmail(),
          parentBookingInfo,
          sharer,
          bookingServiceManager.getProfil());
    } else {
      logger.severe("share failed " + sharerId);
    }
    return list;
  }
 @Override
 // @ApiMethod(name = "bookings.add", httpMethod = "post")
 public BookingInfo addBooking(BookingInfo bookingInfo) throws IllegalArgumentException {
   ObjectifyService.begin();
   return bookingServiceManager.addBookingWithClient(bookingInfo, getClient());
 }
 // @ApiMethod(name = "routes.test.init", httpMethod = "post")
 @Override
 public void initTestRoutes() throws IllegalArgumentException {
   bookingServiceManager.createAgentWithRoutes("*****@*****.**");
 }