Skip to content

Commit

Permalink
Merge pull request #376 from Sunagatov/bug/payment-doc-fix
Browse files Browse the repository at this point in the history
Fixed Swagger Docs for payment module
  • Loading branch information
Sunagatov authored Sep 12, 2024
2 parents 5397a30 + 213d322 commit b3244d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
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"

0 comments on commit b3244d0

Please sign in to comment.