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

Added payment link programmatically #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ dependencies {
implementation group: 'io.github.boostchicken', name: 'spring-data-dynamodb', version: '5.2.5'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
testImplementation 'junit:junit:4.13.2'
implementation group: 'com.stripe', name: 'stripe-java', version: '24.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'junit:junit:4.13.2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void setAvailableSportsIds(List<String> availableSportsIds) {
@Builder
@NoArgsConstructor
@AllArgsConstructor

public static class StripePaymentLink {

Double amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
public interface SportRepository extends CrudRepository<Sport, String> {

Optional<Sport> findById(String sportId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Optional;

@EnableScan
public interface SportsVenueRepository extends CrudRepository<SportsVenues, String> {

SportsVenues findByCityIdAndSportsVenueId(String cityId, String sportsVenueId);
}
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;
Expand All @@ -28,6 +33,10 @@ public class EventBuilder {

EventRepository eventRepository;

SportsVenueRepository sportsVenueRepository;

CityRepository cityRepository;

@Autowired SportsVenueBuilder sportsVenueBuilder;

public EventBuilder(EventRepository eventRepository) {
Expand Down Expand Up @@ -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()));
Comment on lines +215 to +216
Copy link
Collaborator

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?


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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
Expand Down
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;
}
Loading