feat: make stripe functional
This commit is contained in:
parent
177dd78592
commit
1d0162d250
6 changed files with 56 additions and 56 deletions
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue