feat(deposit): enhance payment session handling and error logging
Some checks failed
Some checks failed
This commit is contained in:
parent
9981ebc9d1
commit
6182ff717f
3 changed files with 24 additions and 12 deletions
|
@ -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")
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
|
@ -51,14 +51,20 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue