This PR addresses the issue of large functions in the PaymentController.php file by breaking them down into smaller, more modular functions. This improves the readability and maintainability of the code.
The createSession and handlePaymentSuccess functions have been refactored. The request validation, Stripe API key setting, payment intent creation, transaction creation, and transaction saving logic have been extracted into separate private methods.
Summary of Changes
Extracted the request validation logic from createSession and handlePaymentSuccess into two new private methods: validateCreateSessionRequest and validateHandlePaymentSuccessRequest.
Created a new private method setStripeApiKey to encapsulate the Stripe API key setting logic.
Extracted the payment intent creation logic from createSession into a new private method createPaymentIntent.
Created a new private method createAndSaveTransaction that encapsulates the logic for creating a new transaction and saving it in handlePaymentSuccess.
Replaced the extracted logic in createSession and handlePaymentSuccess with calls to the newly created private methods.
Added comments to all new methods explaining their purpose and parameters.
These changes enhance the modularity of the PaymentController, making the code easier to understand, test, and reuse.
PR Feedback (click)
I created this PR to address this rule:
"Refactor large functions to be more modular."
Description
This PR addresses the issue of large functions in the
PaymentController.php
file by breaking them down into smaller, more modular functions. This improves the readability and maintainability of the code.The
createSession
andhandlePaymentSuccess
functions have been refactored. The request validation, Stripe API key setting, payment intent creation, transaction creation, and transaction saving logic have been extracted into separate private methods.Summary of Changes
createSession
andhandlePaymentSuccess
into two new private methods:validateCreateSessionRequest
andvalidateHandlePaymentSuccessRequest
.setStripeApiKey
to encapsulate the Stripe API key setting logic.createSession
into a new private methodcreatePaymentIntent
.createAndSaveTransaction
that encapsulates the logic for creating a new transaction and saving it inhandlePaymentSuccess
.createSession
andhandlePaymentSuccess
with calls to the newly created private methods.These changes enhance the modularity of the
PaymentController
, making the code easier to understand, test, and reuse.