-
Notifications
You must be signed in to change notification settings - Fork 461
/
Copy pathPaymentController.java
47 lines (39 loc) · 1.8 KB
/
PaymentController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.yas.payment.controller;
import com.yas.payment.service.PaymentService;
import com.yas.payment.viewmodel.CapturePaymentRequestVm;
import com.yas.payment.viewmodel.CapturePaymentResponseVm;
import com.yas.payment.viewmodel.InitPaymentRequestVm;
import com.yas.payment.viewmodel.InitPaymentResponseVm;
import com.yas.payment.viewmodel.CheckoutPaymentVm;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
public class PaymentController {
private final PaymentService paymentService;
@PostMapping(value = "/init")
public InitPaymentResponseVm initPayment(@Valid @RequestBody InitPaymentRequestVm initPaymentRequestVm) {
return paymentService.initPayment(initPaymentRequestVm);
}
@PostMapping(value = "/capture")
public CapturePaymentResponseVm capturePayment(@Valid @RequestBody CapturePaymentRequestVm capturePaymentRequestVM) {
return paymentService.capturePayment(capturePaymentRequestVM);
}
@GetMapping(value = "/cancel")
public ResponseEntity<String> cancelPayment() {
return ResponseEntity.ok("Payment cancelled");
}
@PostMapping("/events/payments")
public ResponseEntity<Long> createPaymentFromEvent(
@Valid @RequestBody CheckoutPaymentVm checkoutPaymentRequestDto
) {
Long paymentId = paymentService.createPaymentFromEvent(checkoutPaymentRequestDto);
return new ResponseEntity<>(paymentId, HttpStatus.CREATED);
}
}