예제 #1
0
  @RequestMapping(value = "/order/create", method = RequestMethod.POST)
  public ResponseEntity<Response> createOrder(
      @RequestBody MerchantOrder order, UriComponentsBuilder ucBuilder) {

    Response response = new Response();
    try {
      validate(order);
      orderService.add(order);
      Payment payment = new Payment();
      payment.setUrl("http://localhost:8080/safeguard/payment/create/");
      payment.setAmount(order.getAmount());
      paymentService.add(payment);
      response.setPaymentId(payment.getId());
      response.setPaymentUrl(payment.getUrl() + payment.getId());
      response.setSuccess(true);
      return new ResponseEntity<Response>(response, HttpStatus.CREATED);
    } catch (Exception ex) {
      response.setSuccess(false);

      for (String message : ex.getMessage().split(System.getProperty("line.separator"))) {
        response.addMessage(message);
      }
      return new ResponseEntity<Response>(response, HttpStatus.BAD_REQUEST);
    }
  }
예제 #2
0
  @RequestMapping(value = "/login", method = RequestMethod.POST, consumes = "application/json")
  public ResponseEntity<Response> login(@RequestBody User user) {

    Response response = new Response();

    try {
      validateUser(user);
      user.setLoggedIn(true);
      userService.update(user);
      response.setSuccess(true);
      response.addMessage("Logged in successfuly");
      return new ResponseEntity<Response>(response, HttpStatus.OK);

    } catch (Exception ex) {
      response.setSuccess(false);

      for (String message : ex.getMessage().split(System.getProperty("line.separator"))) {
        response.addMessage(message);
      }

      return new ResponseEntity<Response>(response, HttpStatus.BAD_REQUEST);
    }
  }
예제 #3
0
  @RequestMapping(
      value = "/payment/create/{id}",
      method = RequestMethod.POST,
      consumes = "application/json")
  public ResponseEntity<Response> createPayment(
      @PathVariable("id") int id, @RequestBody Payment payment) {

    Response response = new Response();

    try {
      System.out.println(payment.getExpirationDate());
      validatePayment(payment);
      response = sendRequest(createAcquirerOrder(payment));
      return new ResponseEntity<Response>(response, HttpStatus.OK);
    } catch (Exception ex) {
      response.setSuccess(false);

      for (String message : ex.getMessage().split(System.getProperty("line.separator"))) {
        response.addMessage(message);
      }
      return new ResponseEntity<Response>(response, HttpStatus.BAD_REQUEST);
    }
  }