hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
181 stars 105 forks source link

[FEAT] Subscriptions - Update Existing Subscriptions #100

Closed Benedict-arowo closed 1 month ago

Benedict-arowo commented 1 month ago

GitHub Issue: Develop API Endpoint to Update Existing Subscriptions through the Payment Gateway

Purpose

Allow users to upgrade or downgrade their subscription plans seamlessly.

Expected Outcome

Functional API endpoint for updating subscriptions with robust error handling.

Requirements

Acceptance Criteria

  1. Authentication

    • Only users with sufficient permissions (e.g., team admins) can change organization member roles.
  2. Design API Endpoint for Subscription Updates:

    • An API endpoint is designed to handle subscription update requests.
    • The endpoint follows RESTful conventions and is well-documented.
  3. Implement Validation for Input Parameters:

    • Validate input parameters, including subscription ID and new plan details, to ensure they are correct and complete before processing.
    • Handle invalid input data with appropriate error responses.
  4. Integrate with Payment Gateway API for Subscription Updates:

    • Implement the logic to update subscriptions through the payment gateway API.
    • Ensure that the integration handles both successful updates and potential errors from the payment gateway.
  5. Handle Errors Gracefully and Provide Appropriate Responses:

    • Implement robust error handling to manage different error scenarios (e.g., invalid subscription ID, payment gateway errors).
    • Provide clear and informative responses to the client in case of errors.
  6. Implement Payment Confirmation Service:

    • Develop a service that listens for payment confirmation events from the payment gateway.
    • Trigger the subscription update route whenever a new payment is successfully processed.

Endpoints

Subscription Update:

Testing

  1. Unit Tests:
    • Write unit tests to validate the endpoint's input data.
    • Test various scenarios, including valid and invalid subscription IDs and plan details.
  2. Integration Testing:
    • Test the integration with the payment gateway API to ensure subscription updates are processed correctly.
    • Verify that the endpoint handles errors from the payment gateway appropriately.
  3. Error Handling:

    • Test different error scenarios to ensure the endpoint provides clear and informative error messages.
    • Ensure that the endpoint handles and logs errors gracefully.

    Payment Confirmation Service

    • Service Description:

    • Implement a service that listens for payment confirmation events from the payment gateway (e.g., webhooks).

    • Ensure the service triggers the subscription update process when a new payment is confirmed.

    • Service Implementation Steps:

      1. Listen for Payment Events:
        • Configure the service to listen for webhook events from the payment gateway indicating successful payments.
      2. Process Payment Confirmation:
        • Validate the payment confirmation data received from the webhook.
        • Identify the corresponding user and subscription based on the payment data.
      3. Trigger Subscription Update:
        • Call the subscription update route with the necessary details to change the subscription plan.
      4. Handle Errors:
        • Implement error handling for cases where the payment confirmation cannot be processed or the subscription update fails.
markessien commented 1 month ago

this is not a clear ticket, because a subscription is not updated without a new payment.

Benedict-arowo commented 1 month ago

Will review accordingly.