feat: make stripe functional

This commit is contained in:
Constantin Simonis 2025-02-13 10:22:33 +01:00
parent 177dd78592
commit 1d0162d250
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
6 changed files with 56 additions and 56 deletions

View file

@ -8,6 +8,8 @@ import com.stripe.param.PriceCreateParams;
import com.stripe.param.checkout.SessionCreateParams;
import de.szut.casino.deposit.dto.AmountDto;
import de.szut.casino.deposit.dto.SessionIdDto;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
@ -17,32 +19,28 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class DepositController {
@Value("${stripe.secret.key}")
private String stripeKey;
@PostMapping("/deposit/checkout")
public ResponseEntity<? extends Object> checkout(@RequestBody AmountDto amountDto) {
Stripe.apiKey = "sk_test_51QrePYIvCfqz7ANgqam8rEwWcMeKiLOof3j6SCMgu2sl4sESP45DJxca16mWcYo1sQaiBv32CMR6Z4AAAGQPCJo300ubuZKO8I";
try {
SessionCreateParams params = SessionCreateParams.builder()
.addLineItem(SessionCreateParams.LineItem.builder()
.setPriceData(InvoiceItemCreateParams.PriceData.builder()
.setCurrency("EUR")
.setUnitAmount(1L)
.build()
)
.build())
.setSuccessUrl("http://localhost:8080/deposit/success")
.setMode(SessionCreateParams.Mode.PAYMENT)
.build();
try {
Session session = Session.create(params);
public ResponseEntity<SessionIdDto> checkout(@RequestBody @Valid AmountDto amountDto) throws StripeException {
Stripe.apiKey = stripeKey;
return ResponseEntity.ok(new SessionIdDto(session.getId()));
} catch (StripeException e) {
return ResponseEntity.ok(e);
}
} catch (Exception e) {
return ResponseEntity.ok(e);
}
SessionCreateParams params = SessionCreateParams.builder()
.addLineItem(SessionCreateParams.LineItem.builder()
.setAmount((long) amountDto.getAmount() * 100)
.setCurrency("EUR")
.setQuantity(1L)
.setName("Einzahlung")
.build())
.setSuccessUrl("http://localhost:8080/deposit/success")
.setMode(SessionCreateParams.Mode.PAYMENT)
.build();
Session session = Session.create(params);
return ResponseEntity.ok(new SessionIdDto(session.getId()));
}
}

View file

@ -1,21 +1,17 @@
package de.szut.casino.deposit.dto;
import jakarta.validation.constraints.Min;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class AmountDto {
@Min(50)
private double amount;
public AmountDto() {
}
public AmountDto(double amount) {
this.amount = amount;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}

View file

@ -3,7 +3,7 @@ spring.datasource.username=postgres_user
spring.datasource.password=postgres_pass
server.port=8080
spring.jpa.hibernate.ddl-auto=create-drop
stripe.secret.key=sk_test_51QrePYIvCfqz7ANgqam8rEwWcMeKiLOof3j6SCMgu2sl4sESP45DJxca16mWcYo1sQaiBv32CMR6Z4AAAGQPCJo300ubuZKO8I
spring.application.name=lf12_starter
#client registration configuration