-
Notifications
You must be signed in to change notification settings - Fork 4
Implement comprehensive Stripe integration with payment services and API endpoints #67
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Trubador <9870550+Trubador@users.noreply.github.com>
… tests Co-authored-by: Trubador <9870550+Trubador@users.noreply.github.com>
Co-authored-by: Trubador <9870550+Trubador@users.noreply.github.com>
|
} | ||
catch (ArgumentException ex) | ||
{ | ||
_logger.LogWarning(ex, "Invalid subscription ID: {SubscriptionId}", subscriptionId); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the problem, sanitize the subscriptionId
before logging it. Specifically, remove any newline (\n
, \r
) or other control characters from the string before passing it to the logger. This can be done using String.Replace
or a regular expression. The change should be made in the catch (ArgumentException ex)
block on line 169, where the log entry is created. Only the logging statement needs to be updated; the rest of the code can remain unchanged. No new dependencies are required.
-
Copy modified lines R12-R19 -
Copy modified line R177
@@ -9,6 +9,14 @@ | ||
|
||
namespace AppBlueprint.Presentation.ApiModule.Controllers.Baseline; | ||
|
||
// Helper method to sanitize user input before logging | ||
private static string SanitizeForLog(string input) | ||
{ | ||
if (input == null) return null; | ||
// Remove carriage returns and newlines | ||
return input.Replace("\r", "").Replace("\n", ""); | ||
} | ||
|
||
[ApiController] | ||
[Route("api/payment")] | ||
[Produces("application/json")] | ||
@@ -166,7 +174,7 @@ | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
_logger.LogWarning(ex, "Invalid subscription ID: {SubscriptionId}", subscriptionId); | ||
_logger.LogWarning(ex, "Invalid subscription ID: {SubscriptionId}", SanitizeForLog(subscriptionId)); | ||
return BadRequest(new ProblemDetails | ||
{ | ||
Title = "Invalid Request", |
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
_logger.LogError(ex, "Failed to retrieve subscription: {SubscriptionId}", subscriptionId); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the problem, sanitize the subscriptionId
before logging it. Specifically, remove any newline or carriage return characters from the user input before passing it to the logger. This can be done using String.Replace
to replace \r
and \n
with empty strings. The change should be made in the catch block for InvalidOperationException
(line 178), where subscriptionId
is logged. The sanitized value should be used in the log entry instead of the raw user input. No changes to the rest of the method or its functionality are required.
-
Copy modified lines R178-R179
@@ -175,7 +175,8 @@ | ||
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
_logger.LogError(ex, "Failed to retrieve subscription: {SubscriptionId}", subscriptionId); | ||
var sanitizedSubscriptionId = subscriptionId?.Replace("\r", "").Replace("\n", ""); | ||
_logger.LogError(ex, "Failed to retrieve subscription: {SubscriptionId}", sanitizedSubscriptionId); | ||
return NotFound(new ProblemDetails | ||
{ | ||
Title = "Subscription Not Found", |
} | ||
catch (ArgumentException ex) | ||
{ | ||
_logger.LogWarning(ex, "Invalid customer ID: {CustomerId}", customerId); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the problem, we need to sanitize the customerId
before logging it. Specifically, we should remove or replace any newline (\n
, \r
) characters from the customerId
string before passing it to the logger. This can be done using String.Replace
or a regular expression. The fix should be applied directly in the logging statements that use user input. In this case, we need to update the log statements on lines 226 and 235 to use a sanitized version of customerId
. No new methods or imports are required, as string.Replace
is available by default.
-
Copy modified line R226 -
Copy modified line R235
@@ -223,7 +223,7 @@ | ||
} | ||
catch (ArgumentException ex) | ||
{ | ||
_logger.LogWarning(ex, "Invalid customer ID: {CustomerId}", customerId); | ||
_logger.LogWarning(ex, "Invalid customer ID: {CustomerId}", customerId?.Replace("\r", "").Replace("\n", "")); | ||
return BadRequest(new ProblemDetails | ||
{ | ||
Title = "Invalid Request", | ||
@@ -232,7 +232,7 @@ | ||
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
_logger.LogError(ex, "Failed to retrieve customer subscriptions: {CustomerId}", customerId); | ||
_logger.LogError(ex, "Failed to retrieve customer subscriptions: {CustomerId}", customerId?.Replace("\r", "").Replace("\n", "")); | ||
return StatusCode(StatusCodes.Status500InternalServerError, new ProblemDetails | ||
{ | ||
Title = "Failed to Retrieve Subscriptions", |
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
_logger.LogError(ex, "Failed to retrieve customer subscriptions: {CustomerId}", customerId); |
Check failure
Code scanning / CodeQL
Log entries created from user input High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
To fix the problem, we should sanitize the customerId
before logging it. Specifically, we should remove any newline (\n
, \r
) characters from the customerId
string before passing it to the logger. This can be done using Replace
calls on the string. The best place to do this is immediately before logging, so that the log entry cannot be forged regardless of how the logger handles structured data. Only the log statement on line 235 needs to be changed; the rest of the code can remain as is. No new methods or external dependencies are required.
-
Copy modified line R235
@@ -232,7 +232,7 @@ | ||
} | ||
catch (InvalidOperationException ex) | ||
{ | ||
_logger.LogError(ex, "Failed to retrieve customer subscriptions: {CustomerId}", customerId); | ||
_logger.LogError(ex, "Failed to retrieve customer subscriptions: {CustomerId}", customerId?.Replace("\r", "").Replace("\n", "")); | ||
return StatusCode(StatusCodes.Status500InternalServerError, new ProblemDetails | ||
{ | ||
Title = "Failed to Retrieve Subscriptions", |
This PR implements a complete Stripe integration for the AppBlueprint application, providing full customer and subscription management capabilities through a well-structured service layer and RESTful API.
What was implemented
Service Layer (
StripeSubscriptionService
)API Layer (
PaymentController
)POST /api/payment/create-customer
- Create Stripe customersPOST /api/payment/create-subscription
- Create subscriptionsGET /api/payment/subscription/{id}
- Get subscription detailsGET /api/payment/customer/{id}/subscriptions
- List customer subscriptionsPOST /api/payment/cancel-subscription
- Cancel subscriptionsProblemDetails
Data Models
CreateCustomerRequest
,CreateSubscriptionRequest
,CancelSubscriptionRequest
CustomerResponse
,SubscriptionResponse
,SubscriptionListResponse
Testing
StripeSubscriptionService
covering validation and error scenariosPaymentController
covering main workflowsInfrastructure
PaymentServiceExtensions
Documentation
Configuration Required
Add your Stripe API key to the connection strings:
Key Features
The integration follows the existing codebase patterns and maintains compatibility with the current architecture while providing a robust foundation for payment processing.
Fixes #59.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.