forked from hashicorp-demoapp/payments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestPaymentController.java
More file actions
59 lines (45 loc) · 1.84 KB
/
Copy pathRestPaymentController.java
File metadata and controls
59 lines (45 loc) · 1.84 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
package payments;
import java.util.HashMap;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Conditional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.Tracer.SpanBuilder;
@Conditional(ConditionOnMissingQueueAndDB.class)
@RestController
public class RestPaymentController {
Logger logger = LoggerFactory.getLogger(RestPaymentController.class);
@Autowired
Tracer tracer;
@PostMapping("/")
@ResponseBody
public PaymentResponse pay(@RequestBody PaymentRequest request) {
// Log it - tracer
HashMap<String, String> cardSpanMap = new HashMap<>();
cardSpanMap.put("name", request.getName());
cardSpanMap.put("type", request.getType());
cardSpanMap.put("number", request.getNumber());
cardSpanMap.put("exp", request.getExpiry());
Span cardSpan = tracer.buildSpan("process card").start();
cardSpan.log(cardSpanMap);
// Log it - stdout
logger.info("New payment");
logger.info("Fullname: {}", request.getName());
logger.info("CC Type: {}", request.getType());
logger.info("CC Number: {}", request.getNumber());
logger.info("CC Expiration: {}", request.getExpiry());
logger.info("CC CVC: {}", request.getCvc());
cardSpan.finish();
return new PaymentResponse(UUID.randomUUID().toString(),
"Payment processed successfully, card details returned for demo purposes, not for production",
request.getNumber(), "Encryption Disabled");
}
}