Merge pull request 'Update the stripe api' (!119) from fix-renovate into main
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Release / Release (push) Successful in 56s
				
			
		
		
	
	
		
	
		
			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:
		
				commit
				
					
						823cb88807
					
				
			
		
					 5 changed files with 114 additions and 456 deletions
				
			
		|  | @ -39,7 +39,7 @@ repositories { | |||
| } | ||||
| 
 | ||||
| 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-web") | ||||
|     compileOnly("org.projectlombok:lombok") | ||||
|  |  | |||
|  | @ -52,10 +52,14 @@ public class DepositController { | |||
| 
 | ||||
|         SessionCreateParams params = SessionCreateParams.builder() | ||||
|                 .addLineItem(SessionCreateParams.LineItem.builder() | ||||
|                         .setAmount((long) amountDto.getAmount() * 100) | ||||
|                         .setCurrency("EUR") | ||||
|                         .setPriceData(SessionCreateParams.LineItem.PriceData.builder() | ||||
|                                 .setCurrency("EUR") | ||||
|                                 .setUnitAmount((long) amountDto.getAmount() * 100) | ||||
|                                 .setProductData(SessionCreateParams.LineItem.PriceData.ProductData.builder() | ||||
|                                         .setName("Einzahlung") | ||||
|                                         .build()) | ||||
|                                 .build()) | ||||
|                         .setQuantity(1L) | ||||
|                         .setName("Einzahlung") | ||||
|                         .build()) | ||||
|                 .setSuccessUrl(frontendHost+"/home?success=true") | ||||
|                 .setCancelUrl(frontendHost+"/home?success=false") | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ public class TransactionService { | |||
|                 .build(); | ||||
|         Session checkoutSession = Session.retrieve(sessionID, params, null); | ||||
| 
 | ||||
|         if (!Objects.equals(checkoutSession.getPaymentStatus(), "paid")) { | ||||
|         if (!"paid".equals(checkoutSession.getPaymentStatus())) { | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|  | @ -53,10 +53,12 @@ public class TransactionService { | |||
|         transaction.setStatus(TransactionStatus.SUCCEEDED); | ||||
| 
 | ||||
|         UserEntity user = transaction.getUser(); | ||||
|         user.addBalance(checkoutSession.getAmountTotal()); | ||||
|         Long amountTotal = checkoutSession.getAmountTotal(); | ||||
|         if (amountTotal != null) { | ||||
|             user.addBalance(amountTotal); | ||||
|         } | ||||
| 
 | ||||
|         userRepository.save(user); | ||||
|         transactionRepository.save(transaction); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -51,12 +51,18 @@ public class WebhookController { | |||
|         switch (event.getType()) { | ||||
|             case "checkout.session.completed": | ||||
|             case "checkout.session.async_payment_succeeded": | ||||
|                 Session session = (Session) event.getData().getObject(); | ||||
| 
 | ||||
|                 this.transactionService.fulfillCheckout(session.getId()); | ||||
|                 EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer(); | ||||
|                  | ||||
|                 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; | ||||
|             default: | ||||
| 
 | ||||
|                 // No action needed for other event types | ||||
|                 break; | ||||
|         } | ||||
| 
 | ||||
|         return ResponseEntity.ok().body(null); | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Reference in a new issue