Merge pull request 'Update the stripe api' (!119) from fix-renovate into main
All checks were successful
Release / Release (push) Successful in 56s

Reviewed-on: #119
Reviewed-by: Phan Huy Tran <ptran@noreply.localhost>
This commit is contained in:
Jan K9f 2025-04-02 10:21:33 +00:00
commit 823cb88807
Signed by:
GPG key ID: 944223E4D46B7412
5 changed files with 114 additions and 456 deletions

View file

@ -39,7 +39,7 @@ repositories {
} }
dependencies { dependencies {
implementation("com.stripe:stripe-java:20.136.0") implementation("com.stripe:stripe-java:29.0.0")
implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-web")
compileOnly("org.projectlombok:lombok") compileOnly("org.projectlombok:lombok")

View file

@ -52,10 +52,14 @@ public class DepositController {
SessionCreateParams params = SessionCreateParams.builder() SessionCreateParams params = SessionCreateParams.builder()
.addLineItem(SessionCreateParams.LineItem.builder() .addLineItem(SessionCreateParams.LineItem.builder()
.setAmount((long) amountDto.getAmount() * 100) .setPriceData(SessionCreateParams.LineItem.PriceData.builder()
.setCurrency("EUR") .setCurrency("EUR")
.setUnitAmount((long) amountDto.getAmount() * 100)
.setProductData(SessionCreateParams.LineItem.PriceData.ProductData.builder()
.setName("Einzahlung")
.build())
.build())
.setQuantity(1L) .setQuantity(1L)
.setName("Einzahlung")
.build()) .build())
.setSuccessUrl(frontendHost+"/home?success=true") .setSuccessUrl(frontendHost+"/home?success=true")
.setCancelUrl(frontendHost+"/home?success=false") .setCancelUrl(frontendHost+"/home?success=false")

View file

@ -40,7 +40,7 @@ public class TransactionService {
.build(); .build();
Session checkoutSession = Session.retrieve(sessionID, params, null); Session checkoutSession = Session.retrieve(sessionID, params, null);
if (!Objects.equals(checkoutSession.getPaymentStatus(), "paid")) { if (!"paid".equals(checkoutSession.getPaymentStatus())) {
return; return;
} }
@ -53,10 +53,12 @@ public class TransactionService {
transaction.setStatus(TransactionStatus.SUCCEEDED); transaction.setStatus(TransactionStatus.SUCCEEDED);
UserEntity user = transaction.getUser(); UserEntity user = transaction.getUser();
user.addBalance(checkoutSession.getAmountTotal()); Long amountTotal = checkoutSession.getAmountTotal();
if (amountTotal != null) {
user.addBalance(amountTotal);
}
userRepository.save(user); userRepository.save(user);
transactionRepository.save(transaction); transactionRepository.save(transaction);
} }
} }

View file

@ -51,12 +51,18 @@ public class WebhookController {
switch (event.getType()) { switch (event.getType()) {
case "checkout.session.completed": case "checkout.session.completed":
case "checkout.session.async_payment_succeeded": case "checkout.session.async_payment_succeeded":
Session session = (Session) event.getData().getObject(); EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
this.transactionService.fulfillCheckout(session.getId()); if (dataObjectDeserializer.getObject().isPresent()) {
Session session = (Session) dataObjectDeserializer.getObject().get();
this.transactionService.fulfillCheckout(session.getId());
} else {
logger.error("Failed to deserialize webhook event data");
}
break; break;
default: default:
// No action needed for other event types
break;
} }
return ResponseEntity.ok().body(null); return ResponseEntity.ok().body(null);

File diff suppressed because it is too large Load diff