-
Notifications
You must be signed in to change notification settings - Fork 2
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
Added payment link programmatically #105
Open
AstitvaBhardwaj
wants to merge
3
commits into
main
Choose a base branch
from
Astitva-Payment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
package com.flickmatch.platform.graphql.builder; | ||
|
||
import com.flickmatch.platform.dynamodb.model.City; | ||
import com.flickmatch.platform.dynamodb.model.Event; | ||
import com.flickmatch.platform.dynamodb.repository.CityRepository; | ||
import com.flickmatch.platform.dynamodb.repository.EventRepository; | ||
import com.flickmatch.platform.dynamodb.repository.SportsVenueRepository; | ||
import com.flickmatch.platform.graphql.input.CreateEventInput; | ||
import com.flickmatch.platform.graphql.input.JoinEventInput; | ||
import com.flickmatch.platform.graphql.type.Player; | ||
import com.flickmatch.platform.graphql.type.SportsVenue; | ||
import com.flickmatch.platform.graphql.type.StripePaymentLink; | ||
import com.flickmatch.platform.graphql.util.DateUtil; | ||
import com.stripe.Stripe; | ||
import com.stripe.exception.StripeException; | ||
import com.stripe.model.PaymentLink; | ||
import com.stripe.param.PaymentLinkCreateParams; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.flickmatch.platform.dynamodb.model.SportsVenues; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.*; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
@@ -28,6 +33,10 @@ public class EventBuilder { | |
|
||
EventRepository eventRepository; | ||
|
||
SportsVenueRepository sportsVenueRepository; | ||
|
||
CityRepository cityRepository; | ||
|
||
@Autowired SportsVenueBuilder sportsVenueBuilder; | ||
|
||
public EventBuilder(EventRepository eventRepository) { | ||
|
@@ -184,11 +193,50 @@ private String getPaymentUrlForEvent(SportsVenue sportsVenue, Double amount) { | |
if (stripePaymentLinkForAmount.isEmpty()) { | ||
//Todo: For now keeping it soft dependency, we need to throw exception in future | ||
log.error("Can't find stripe payment link in venue"); | ||
return null; | ||
return createPaymentLink(amount); | ||
} | ||
return stripePaymentLinkForAmount.get().getUrl(); | ||
} | ||
private String createPaymentLink(Double amount) { | ||
Stripe.apiKey = "sk_test_tR3PYbcVNZZ796tH88S4VQ2u";; | ||
try { | ||
PaymentLinkCreateParams params = | ||
PaymentLinkCreateParams.builder() | ||
.addLineItem( | ||
PaymentLinkCreateParams.LineItem.builder() | ||
.setPrice(String.valueOf(amount)) | ||
.setQuantity(1L) | ||
.build() | ||
) | ||
.build(); | ||
PaymentLink paymentLink = PaymentLink.create(params); | ||
String paymentLinkUrl = paymentLink.getUrl(); | ||
|
||
SportsVenues sportsVenues = new SportsVenues(); | ||
String cityId = String.valueOf(Long.valueOf(sportsVenues.getCityId())); | ||
|
||
SportsVenues.SportsVenue sportsVenue1 = new SportsVenues.SportsVenue(); | ||
String sportsVenueId = String.valueOf(Long.valueOf(sportsVenue1.getSportsVenueId())); | ||
|
||
SportsVenues sportsVenue = sportsVenueRepository.findByCityIdAndSportsVenueId(cityId, sportsVenueId); | ||
if (sportsVenue != null) { | ||
StripePaymentLink stripePaymentLink = StripePaymentLink.builder() | ||
.amount(amount) | ||
.url(paymentLinkUrl) | ||
.build(); | ||
|
||
sportsVenue1.setStripePaymentLinks((List<SportsVenues.StripePaymentLink>) stripePaymentLink); | ||
List<SportsVenues> sportsVenuesList = new ArrayList<>(); | ||
sportsVenuesList.add((SportsVenues) sportsVenue1.getStripePaymentLinks()); | ||
sportsVenueRepository.saveAll(sportsVenuesList); | ||
Comment on lines
+228
to
+231
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't we overriding existing list here? |
||
} | ||
|
||
return paymentLinkUrl; | ||
} catch (StripeException e) { | ||
log.error("Error creating Stripe payment link: " + e.getMessage()); | ||
return null; | ||
} | ||
} | ||
private com.flickmatch.platform.graphql.type.Event mapEventToGQLType(Event.EventDetails eventDetails, String date, String localTimeZone) { | ||
String eventId = date + "-" + eventDetails.getIndex(); | ||
int players = eventDetails.getReservedPlayersCount() / 2; | ||
|
6 changes: 5 additions & 1 deletion
6
platform/src/main/java/com/flickmatch/platform/graphql/type/StripePaymentLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.flickmatch.platform.graphql.type; | ||
|
||
import com.flickmatch.platform.dynamodb.model.SportsVenues; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
AstitvaBhardwaj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Builder | ||
@Getter | ||
public class StripePaymentLink { | ||
@AllArgsConstructor | ||
public class StripePaymentLink{ | ||
Double amount; | ||
String url; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are creating a new object and reading cityId from it. Is it desired behavior?