diff --git a/platform/src/main/java/com/flickmatch/platform/dynamodb/model/RazorPaymentRequest.java b/platform/src/main/java/com/flickmatch/platform/dynamodb/model/RazorPaymentRequest.java index 9bf58d04..8239a139 100644 --- a/platform/src/main/java/com/flickmatch/platform/dynamodb/model/RazorPaymentRequest.java +++ b/platform/src/main/java/com/flickmatch/platform/dynamodb/model/RazorPaymentRequest.java @@ -27,6 +27,8 @@ public class RazorPaymentRequest { private String gameNumber; private String email; + private String phoneNumber; + @DynamoDBHashKey(attributeName="orderId") public String getOrderId() { @@ -64,6 +66,16 @@ public void setStatus(String status) { this.status = status; } + // Getter and Setter for phoneNumber + @DynamoDBAttribute(attributeName="phoneNumber") + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + @DynamoDBAttribute(attributeName="date") public String getDate() { return date; diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/PaymentRequestBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/PaymentRequestBuilder.java index a336c410..f8110044 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/PaymentRequestBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/PaymentRequestBuilder.java @@ -6,12 +6,13 @@ import com.flickmatch.platform.graphql.input.PlayerInput; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - +import lombok.extern.log4j.Log4j2; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @Service +@Log4j2 public class PaymentRequestBuilder { @Autowired @@ -26,6 +27,8 @@ public PaymentRequest createPaymentRequest(final String merchantTransactionId, .waNumber(playerInput.getWaNumber()) .build()) .collect(Collectors.toList()); + log.info("Razorpay Merchant Transaction Id", merchantTransactionId); + log.info("Players Joined", playerInputList); PaymentRequest paymentRequest = PaymentRequest.builder() .merchantTransactionId(merchantTransactionId) .uniqueEventId(uniqueEventId) diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/RazorPaymentRequestBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/RazorPaymentRequestBuilder.java index f05d1a6e..93fcfd9d 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/RazorPaymentRequestBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/RazorPaymentRequestBuilder.java @@ -7,6 +7,8 @@ import com.flickmatch.platform.dynamodb.repository.RazorPaymentRequestRepository; import com.flickmatch.platform.graphql.input.PlayerInput; import com.flickmatch.platform.graphql.input.RazorPayInput; +import com.flickmatch.platform.dynamodb.model.User; +import com.flickmatch.platform.graphql.input.CreateUserInput; import com.razorpay.Order; import com.razorpay.RazorpayClient; import com.razorpay.RazorpayException; @@ -23,12 +25,16 @@ @Service @Log4j2 public class RazorPaymentRequestBuilder { - @Autowired + + @Autowired RazorPaymentRequestRepository razorPaymentRequestRepository; + @Autowired + private UserBuilder userBuilder; // Inject UserBuilder + public String createOrderRequest(RazorpayClient razorpayClient, RazorPayInput input, EventBuilder eventBuilder,long amount) throws RazorpayException { JSONObject orderRequest = new JSONObject(); - String[] parts =input.getUniqueEventId().split("-"); + String[] parts = input.getUniqueEventId().split("-"); String cityId = parts[0]; String currency = input.getCurrency(); orderRequest.put("amount", amount); @@ -42,13 +48,23 @@ public RazorPaymentRequest createPaymentRequest(final String orderId, final String date, final String location, final String gameNumber, - final String email) { + final String email, + final String phoneNumber) { + List playerDetailsList = playerInputList.stream() .map(playerInput -> Event.PlayerDetails.builder() .name(playerInput.getName()) .waNumber(playerInput.getWaNumber()) .build()) .collect(Collectors.toList()); + + // 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); + // System.out.println(orderId + " " + uniqueEventId + " " + " " + date + " " + location + " " + gameNumber + " " +email); RazorPaymentRequest razorPaymentRequest = RazorPaymentRequest.builder() .orderId(orderId) @@ -59,6 +75,7 @@ public RazorPaymentRequest createPaymentRequest(final String orderId, .location(location) .gameNumber(gameNumber) .email(email) + .phoneNumber(phoneNumber) .build(); return razorPaymentRequestRepository.save(razorPaymentRequest); } diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/builder/UserBuilder.java b/platform/src/main/java/com/flickmatch/platform/graphql/builder/UserBuilder.java index 5f58b382..0e28589f 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/builder/UserBuilder.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/builder/UserBuilder.java @@ -14,7 +14,7 @@ @Service public class UserBuilder { - private UserRepository userRepository; + private final UserRepository userRepository; public UserBuilder(UserRepository userRepository) { this.userRepository = userRepository; @@ -22,34 +22,44 @@ public UserBuilder(UserRepository userRepository) { public User createUser(CreateUserInput input) { // Checking if the user already exists - Optional existingUser = userRepository.findByEmail(input.getEmail()); - if(existingUser.isPresent()) { - return existingUser.get(); - } - // Create a new User object - User newUser = new User(); - newUser.setEmail(input.getEmail()); - newUser.setName(input.getName()); - newUser.setPhoneNumber(input.getPhoneNumber()); - newUser.setHasActiveSubscription(false); - newUser.setSubscriptionHistory(new ArrayList<>()); + Optional existingUserOptional = userRepository.findByEmail(input.getEmail()); + User user; + + if(existingUserOptional.isPresent()) { + // User already exists, update the phone number + user = existingUserOptional.get(); + user.setPhoneNumber(input.getPhoneNumber()); + log.info("User already exists, updating phone number for user: {}", user); + return userRepository.save(user); + } else { + // Create a new User object + user = new User(); + user.setEmail(input.getEmail()); + user.setName(input.getName()); + user.setPhoneNumber(input.getPhoneNumber()); + user.setHasActiveSubscription(false); + user.setSubscriptionHistory(new ArrayList<>()); + log.info("Creating a new user: {}", user); + } try { - // Save the new user to the repository - userRepository.save(newUser); - log.info("User created successfully: {}", newUser); - return newUser; + // Save the user (new or updated) to the repository + userRepository.save(user); + log.info("User saved successfully: {}", user); + return user; } catch (Exception e) { - log.error("Error creating user: {}", e.getMessage()); + log.error("Error saving user: {}", e.getMessage()); throw e; } + } public List getAllUsers() { return userRepository.findAll(); } + public void createUserSubscription(String email,String passId,String subscriptionId) { try { // Find the existing user by email diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/controller/PaymentController.java b/platform/src/main/java/com/flickmatch/platform/graphql/controller/PaymentController.java index c47e0a1c..a42b7a4d 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/controller/PaymentController.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/controller/PaymentController.java @@ -83,8 +83,14 @@ public RazorPayOutput initiateRazorPayment(@Argument RazorPayInput input) { String location = city.getCityName(); String gameNumber = input.getUniqueEventId().split("-")[4]; String email = input.getEmail(); + 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); + razorPaymentRequestBuilder.createPaymentRequest(orderId, - input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email); + input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email, phoneNumber); return RazorPayOutput.builder().orderId(orderId).isInitiated(true).amount(amount).build(); } catch (DynamoDBMappingException dbe) { log.error("DynamoDB mapping error: {}", dbe.getMessage(), dbe); diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/controller/UserController.java b/platform/src/main/java/com/flickmatch/platform/graphql/controller/UserController.java index ad175ec7..389d1c30 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/controller/UserController.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/controller/UserController.java @@ -1,6 +1,7 @@ package com.flickmatch.platform.graphql.controller; import com.flickmatch.platform.dynamodb.model.User; +//import com.flickmatch.platform.dynamodb.service.PlayerService; import com.flickmatch.platform.graphql.builder.UserBuilder; import com.flickmatch.platform.graphql.input.CreateUserInput; import com.flickmatch.platform.graphql.type.UserResult; @@ -19,6 +20,7 @@ public class UserController { @Autowired private UserBuilder userBuilder; + //private PlayerService playerService; @MutationMapping public UserResult createUser(@Argument CreateUserInput input) { @@ -37,6 +39,11 @@ public UserResult createUser(@Argument CreateUserInput input) { } + +// @DeleteMapping("/{id}") +// public void deletePlayer(@PathVariable Long id) { +// playerService.deletePlayer(id); +// } @QueryMapping(name="users") public List getAllUsers() { return userBuilder.getAllUsers(); diff --git a/platform/src/main/java/com/flickmatch/platform/graphql/input/RazorPayInput.java b/platform/src/main/java/com/flickmatch/platform/graphql/input/RazorPayInput.java index 8ae67e60..c28009f3 100644 --- a/platform/src/main/java/com/flickmatch/platform/graphql/input/RazorPayInput.java +++ b/platform/src/main/java/com/flickmatch/platform/graphql/input/RazorPayInput.java @@ -13,4 +13,13 @@ public class RazorPayInput { List playerInputList; String currency; String email; + String phoneNumber; + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } } diff --git a/platform/src/main/resources/graphql/schema.graphqls b/platform/src/main/resources/graphql/schema.graphqls index 9daa6730..18d7e1de 100644 --- a/platform/src/main/resources/graphql/schema.graphqls +++ b/platform/src/main/resources/graphql/schema.graphqls @@ -77,6 +77,7 @@ input RazorPayInput { playerInputList: [PlayerInput!]! currency: String! email: String! + phoneNumber: String! } input PassPaymentInput { diff --git a/react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx b/react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx index 5840731b..44d7e8cc 100644 --- a/react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx +++ b/react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx @@ -211,7 +211,14 @@ export const JoinNow: FC = ({ generateUrl(); } else { // createOrder('2-2024-07-11-1', objectArray, setAmount, currency || 'INR', email) // to be changed after local testing - createOrder(uniqueEventId, objectArray, setAmount, currency || 'INR', email) // to be changed after local testing + createOrder( + uniqueEventId, + objectArray, + setAmount, + currency || 'INR', + email, + userData.phoneNumber, + ) // to be changed after local testing .then((orderId) => { setOrderId(orderId); setOpen(false); diff --git a/react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts b/react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts index cba67538..a69b07d1 100644 --- a/react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts +++ b/react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts @@ -4,6 +4,7 @@ const createOrder = ( setAmount: React.Dispatch>, currency: string, email: string, + phoneNumber: string, ): Promise => // fetch('http://localhost:8080/graphql', { fetch('https://service.flickmatch.in/platform-0.0.1-SNAPSHOT/graphql', { @@ -21,6 +22,7 @@ const createOrder = ( .join(',')}], currency : "${currency}" email : "${email}" + phoneNumber: "${phoneNumber}" } ) { orderId