Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Swagger Docs for payment module #376

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.zufar.icedlatte.payment.api.RedirectEventProcessor;
import com.zufar.icedlatte.payment.api.WebhookEventProcessor;
import com.zufar.icedlatte.payment.exception.StripeSessionRetrievalException;
import io.swagger.v3.oas.annotations.Hidden;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -21,7 +22,7 @@
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(PaymentEndpoint.PAYMENT_URL)
@RequestMapping(value = PaymentEndpoint.PAYMENT_URL)
public class PaymentEndpoint implements com.zufar.icedlatte.openapi.payment.api.PaymentApi {

public static final String PAYMENT_URL = "/api/v1/payment";
Expand All @@ -30,6 +31,7 @@ public class PaymentEndpoint implements com.zufar.icedlatte.openapi.payment.api.
private final WebhookEventProcessor webhookEventProcessor;
private final RedirectEventProcessor redirectEventProcessor;

@Hidden
@GetMapping
public ResponseEntity<SessionWithClientSecretDto> processPayment(final HttpServletRequest request) {
log.info("Received request to process payment");
Expand All @@ -39,6 +41,13 @@ public ResponseEntity<SessionWithClientSecretDto> processPayment(final HttpServl
.body(processPaymentResponse);
}

/**
* Handles various requests which are sent by Stripe
*
* @param stripeSignatureHeader - Stripe Signature which is used for authorization
* @param paymentPayload - serialized event: Stripe sends many events, we're interested only in Session events
*/
@Hidden
@PostMapping("/stripe/webhook")
public ResponseEntity<Void> processStripeWebhook(@RequestHeader("Stripe-Signature") final String stripeSignatureHeader,
@RequestBody final String paymentPayload){
Expand All @@ -48,6 +57,7 @@ public ResponseEntity<Void> processStripeWebhook(@RequestHeader("Stripe-Signatur
return ResponseEntity.ok().build();
}

@Override
@GetMapping("/order")
public ResponseEntity<PaymentConfirmationEmail> processRedirectEvent(@RequestParam final String sessionId) throws StripeSessionRetrievalException {
log.info("Received request to create order after redirect, session id {}", sessionId);
Expand Down
53 changes: 16 additions & 37 deletions src/main/resources/api-specs/payment-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,6 @@ tags:
description: "An API for managing and retrieving payment information"

paths:
/api/v1/payment:
post:
tags:
- "Payment"
summary: "Creates Stripe Session for an authorized user"
operationId: "processPayment"
responses:
"200":
description: "Session created successfully"
content:
application/json:
schema:
$ref: "#/components/schemas/SessionWithClientSecretDto"
"400":
description: "Cannot create session"
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorHandler"

/api/v1/payment/order:
get:
tags:
Expand All @@ -61,10 +41,22 @@ paths:
$ref: "#/components/schemas/PaymentConfirmationEmail"
"400":
description: "Cannot create order"

/:
get:
tags:
- "Payment"
summary: "Creates Stripe Session for an authorized user and returns its id and client secret"
operationId: "processPayment"
responses:
"200":
description: "Session created successfully"
content:
application/json:
schema:
$ref: "#/components/schemas/ErrorHandler"
$ref: "#/components/schemas/SessionWithClientSecretDto"
"400":
description: "Cannot create session"

components:
schemas:
Expand All @@ -78,6 +70,9 @@ components:

SessionWithClientSecretDto:
type: "object"
required:
- sessionId
- clientSecret
properties:
sessionId:
type: "string"
Expand All @@ -89,19 +84,3 @@ components:
properties:
customerEmail:
type: "string"

ErrorHandler:
type: "object"
properties:
messages:
type: "array"
items:
format: "string"
description:
type: "string"
httpStatusCode:
type: "integer"
format: "int32"
timestamp:
type: "string"
format: "date-time"
Loading