File tree Expand file tree Collapse file tree 4 files changed +65
-33
lines changed
Expand file tree Collapse file tree 4 files changed +65
-33
lines changed Original file line number Diff line number Diff line change 11package org .nacha .paymentsystem .application ;
22import org .springframework .web .bind .annotation .*;
3-
3+ import org .nacha .paymentsystem .domain .Payment ;
4+ import org .nacha .paymentsystem .application .PaymentService ;
45
56@ RestController
67@ RequestMapping ("/api/payments" )
78public class PaymentController {
89
10+ private final PaymentService paymentService ;
11+
912 public PaymentController (PaymentService paymentService ) {
1013 this .paymentService = paymentService ;
1114 }
1215
1316 @ PostMapping ("/process" )
14- public void processPayment (@ RequestBody Payment payment ) {
17+ public String createPayment (@ RequestBody Payment payment ) {
1518 paymentService .processPayment (payment );
19+ return "Payment process successfully" ;
1620 }
1721
22+ @ GetMapping ("/{id}" )
23+ public Payment getPayment (@ PathVariable Long id ) {
24+ return paymentService .getPaymentById (id );
25+ }
26+
27+
1828}
Original file line number Diff line number Diff line change 11package org .nacha .paymentsystem .application ;
22
3+ import org .nacha .paymentsystem .domain .Payment ;
4+ import org .nacha .paymentsystem .infrastructure .persistence .PaymentRespository ;
5+ import org .springframework .stereotype .Service ;
36
7+ @ Service
48public class PaymentService {
9+
10+ private final PaymentRespository paymentRespository ;
11+
12+ public PaymentService (PaymentRepository paymentRepository ) {
13+ this .paymentRespository = paymentRepository ;
14+ }
15+
516 public void processPayment (Payment payment ) {
617 // Business logic for processing a payment
7-
818 if (!payment ) {
919 System .out .println ("No payment received" );
1020 }
21+ validatePayment (payment );
22+ paymentRespository .save (payment );
23+
24+ // additional logic (e.g., remittance instructions, message)
25+ }
1126
12- // proper handling of ACH accessible transaction
13- // data can move, so must be secure
14- PaymentService p1 = new PaymentService ();
15- System .out .println (int (payment ));
27+ public Payment getPaymentById (Long id ) {
28+ return paymentRespository .findById (id ).orElseThrow (() -> new RuntimeException ("Payment not found" ));
1629 }
1730
1831 public void validatePayment (Payment payment ) {
Original file line number Diff line number Diff line change 11package org .nacha .paymentsystem .application ;
22
3+ import org .springframework .stereotype .Service ;
4+
5+ @ Service
36public class WorkflowService {
47
58 public void startWorkflow (Workflow workflow ) {
Original file line number Diff line number Diff line change 11package org .nacha .paymentsystem .application ;
22
3- public class Payment {
3+ import jakarta . persistence .*;
44
5+ @ Entity
6+ public class Payment {
7+ @ Id
8+ @ GeneratedValue (strategy = GenerationType .IDENTITY )
59 // This class represents the core business model (Payment).
6- private String paymentId ;
7- private double amount ;
8- private String sender ;
9- private String receiver ;
10+
11+ /id
12+ private Long id ;
13+ public Long getId () {
14+ return id ;
15+ }
16+ public void setId (Long id ) {
17+ this .id = id ;
18+ }
1019
1120
12- // Getter and Setter
13- public String getPaymentId () {
14- return paymentId ;
21+ //payer
22+ private String payer ;
23+ public String getPayer () {
24+ return payer ;
25+ }
26+ public void setPayer (String payer ) {
27+ this .payer = payer ;
1528 }
1629
17- public void setPaymentId (String paymentId ) {
18- this .paymentId = paymentId ;
30+
31+ //payee
32+ private String payee ;
33+ public String getPayee () {
34+ return payee ;
1935 }
36+ public void setPayee (String payee ) {
37+ this .payee = payee ;
38+ }
39+
2040
41+ // amount
42+ private double amount ;
2143 public double getAmount () {
2244 return amount ;
2345 }
24-
2546 public void setAmount (double amount ) {
2647 this .amount = amount ;
2748 }
2849
29- public String getSender () {
30- return sender ;
31- }
32-
33- public void setSender (String sender ) {
34- this .sender = sender ;
35- }
36-
37- public void setReceiver (String receiver ) {
38- this .receiver = receiver ;
39- }
40-
41- public String getReceiver () {
42- return receiver ;
43- }
4450}
You can’t perform that action at this time.
0 commit comments