Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass mutations #312

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public List<com.flickmatch.platform.graphql.type.Event> getEvents(String cityId,

// Fetch all events within the date range
List<Event> eventsInRange = eventRepository.findByEventIdCityIdAndEventIdDateBetween(cityId, startFormattedDate, endFormattedDate);
System.out.println("total events retrieved= " + eventsInRange.size());
// System.out.println("total events retrieved= " + eventsInRange.size());

for (Event event : eventsInRange) {
String eventDate = event.getDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ public RazorPaymentRequest createPaymentRequest(final String orderId,
.build())
.collect(Collectors.toList());

try {
// Create or update the user with the provided phone number
CreateUserInput createUserInput = CreateUserInput.builder()
.email(email) // Assuming you have the email from the payment request
.phoneNumber(phoneNumber)
.build();
userBuilder.createUser(createUserInput);
} catch (Exception e) {
log.error("Error creating user: " + e.getMessage());
}

// System.out.println(orderId + " " + uniqueEventId + " " + " " + date + " " + location + " " + gameNumber + " " +email);
RazorPaymentRequest razorPaymentRequest = RazorPaymentRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public InitiatePaymentOutput initiatePayment(@Argument InitiatePaymentInput inpu
@Autowired
RazorPayProxy razorPayProxy;

public String sanitizeLog(String input) {
return input.replaceAll("[\r\n]", ""); // Remove line breaks to prevent log injection
}



String formatDateToString(LocalDate date) {
return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
Expand All @@ -86,8 +91,10 @@ public RazorPayOutput initiateRazorPayment(@Argument RazorPayInput input) {
String phoneNumber = input.getPhoneNumber();

// Log the phone number before creating the payment request
log.info("Phone number to be saved: {}", phoneNumber);
log.info("Razorpay OrderId Generated", orderId);
// log.info("Phone number to be saved: {}", phoneNumber);
// log.info("Razorpay OrderId Generated", orderId);
log.info("Phone number to be saved: {}", sanitizeLog(phoneNumber));
log.info("Razorpay OrderId Generated", sanitizeLog(orderId));

razorPaymentRequestBuilder.createPaymentRequest(orderId,
input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email, phoneNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public class RazorPaymentCallbackController {
@Value("${razorpay.key.secret}")
private String secret;

// Utility method to sanitize inputs for logging
private String sanitizeForLog(String input) {
if (input == null) return ""; // Avoid NullPointerException
return input.replaceAll("[\n\r\t]", "_") // Replace newline, carriage return, tab with underscore
.replaceAll("[^\\p{Print}]", ""); // Remove non-printable characters
}


// @Autowired
// WhatsAppProxy whatsAppProxy;
Expand All @@ -53,6 +60,8 @@ public ResponseEntity<?> processRazorCallback(@RequestParam("razorpay_order_id")
@RequestParam("razorpay_payment_id") String paymentId,
@RequestParam("razorpay_signature") String signature) {

String sanitizedOrderId = sanitizeForLog(orderId);
log.info("Processing callback for order {}", sanitizedOrderId);
String uniqueEventId;
int flag=0;
try {
Expand All @@ -62,6 +71,9 @@ public ResponseEntity<?> processRazorCallback(@RequestParam("razorpay_order_id")
options.put("razorpay_payment_id",paymentId);
options.put("razorpay_signature", signature);
RazorPaymentRequest paymentRequest = paymentRequestBuilder.getPaymentRequest(orderId);

log.info("Processing callback for email " + paymentRequest.getEmail() + " and uniqueEventId " + paymentRequest.getUniqueEventId());

uniqueEventId = paymentRequest.getUniqueEventId();

String[] parts =uniqueEventId.split("-");
Expand All @@ -72,6 +84,15 @@ public ResponseEntity<?> processRazorCallback(@RequestParam("razorpay_order_id")
// https://razorpay.com/docs/payments/server-integration/java/payment-gateway/build-integration/#generate-signature-on-your-server

boolean status = Utils.verifyPaymentSignature(options, secret);

// Sanitize user inputs to avoid log injection
// String sanitizedOrderId = orderId.replaceAll("[\n\r]", "");
String sanitizedPaymentId = sanitizeForLog(paymentId);
String sanitizedSignature = sanitizeForLog(signature);

log.info("OrderId: {}, PaymentId: {}, Signature: {}", sanitizedOrderId, sanitizedPaymentId, sanitizedSignature);
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
log.info("Status: {}", status);

if(status) {
if(PAID_STATUS.equals(paymentRequest.getStatus())) {
log.info("Ignoring duplicate payments.");
Expand All @@ -85,12 +106,14 @@ public ResponseEntity<?> processRazorCallback(@RequestParam("razorpay_order_id")

else {
if (orderId.matches("\\w+")) {
log.info("Invalid signature for orderId : " + orderId);
log.info("Invalid signature for orderId : {}", sanitizedOrderId);
} else {
log.info("Invalid signature for orderId :[INVALID]");
}
}

log.info("Proceeding for redirection part.");

try {
eventDate = LocalDate.parse(dateStr, formatter);
} catch (DateTimeParseException e) {
Expand All @@ -107,17 +130,19 @@ public ResponseEntity<?> processRazorCallback(@RequestParam("razorpay_order_id")
catch (Exception e) {
log.error("Error processing callback: {}", e.getLocalizedMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing callback");
// log.error("Error processing callback: {}", e.getMessage(), e);
}




// whatsAppProxy.sendNotification(eventBuilder.getEventDataForNotification(uniqueEventId));
HttpHeaders headers = new HttpHeaders();
if (flag==1) {
headers.add("Location", "https://play.flickmatch.in/event/" + uniqueEventId);
headers.add("Location", "https://play.flickmatch.in/event/" + sanitizedOrderId);
}
else {
headers.add("Location", "https://play.flickmatch.in/match-queues#"+uniqueEventId);
headers.add("Location", "https://play.flickmatch.in/match-queues#" + sanitizedOrderId);
}
return new ResponseEntity<>(headers, HttpStatus.FOUND);

Expand Down
Loading