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 { | 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") | ||||||
|  |  | ||||||
|  | @ -52,11 +52,15 @@ 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") | ||||||
|                         .setQuantity(1L) |                                 .setUnitAmount((long) amountDto.getAmount() * 100) | ||||||
|  |                                 .setProductData(SessionCreateParams.LineItem.PriceData.ProductData.builder() | ||||||
|                                         .setName("Einzahlung") |                                         .setName("Einzahlung") | ||||||
|                                         .build()) |                                         .build()) | ||||||
|  |                                 .build()) | ||||||
|  |                         .setQuantity(1L) | ||||||
|  |                         .build()) | ||||||
|                 .setSuccessUrl(frontendHost+"/home?success=true") |                 .setSuccessUrl(frontendHost+"/home?success=true") | ||||||
|                 .setCancelUrl(frontendHost+"/home?success=false") |                 .setCancelUrl(frontendHost+"/home?success=false") | ||||||
|                 .setMode(SessionCreateParams.Mode.PAYMENT) |                 .setMode(SessionCreateParams.Mode.PAYMENT) | ||||||
|  |  | ||||||
|  | @ -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,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(); | ||||||
|                  |                  | ||||||
|  |                 if (dataObjectDeserializer.getObject().isPresent()) { | ||||||
|  |                     Session session = (Session) dataObjectDeserializer.getObject().get(); | ||||||
|                     this.transactionService.fulfillCheckout(session.getId()); |                     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
											
										
									
								
							
		Reference in a new issue