Skip to content

Integrate Payment Gateway (e.g., Stripe) #81

@aniebietafia

Description

@aniebietafia

Feature: Integrate Payment Gateway (e.g., Stripe)

Is your feature request related to a problem? Please describe.
To allow users to subscribe to paid plans, UnravelDocs needs to integrate with a payment gateway to securely process payments and manage subscriptions.

Describe the solution you'd like
Integrate a third-party payment gateway (Stripe is a common choice and will be assumed for this issue, but principles apply to others like PayPal, Braintree).

  1. Gateway Setup: Create an account with the chosen payment gateway and configure products/prices corresponding to the defined subscription plans.
  2. SDK/API Integration: Use the payment gateway's SDK (e.g., Stripe Java SDK) in the backend.
  3. Checkout Flow:
    • Implement an API endpoint to initiate a checkout session (e.g., Stripe Checkout). This endpoint will take the desired plan ID.
    • The frontend will redirect the user to the gateway's hosted checkout page.
  4. Securely Handle API Keys: Store payment gateway API keys securely (e.g., environment variables, secrets management).
  5. Customer Creation: Create customers in the payment gateway system and link them to UnravelDocs users.

User Stories:

  • As a User, I want to securely enter my payment details on a trusted platform to subscribe to a paid plan.
  • As a System, I want to integrate with a payment gateway to handle payment processing and subscription creation.

Acceptance Criteria:

  1. Payment gateway account is set up with products/prices matching subscription plans.
  2. Backend API endpoint exists to create a checkout session for a selected plan.
  3. Users are successfully redirected to the payment gateway's checkout page.
  4. Payment gateway API keys are securely managed.
  5. Customers are created in the payment gateway when a user initiates a subscription.

Proposed Technical Details (High-Level - Java/Spring Boot, Stripe context):

  • Libraries: stripe-java SDK.
  • Stripe Setup:
    • Define Products and Prices in the Stripe Dashboard.
    • Obtain API keys (publishable and secret).
  • Key Components:
    • PaymentGatewayService (e.g., StripeService) to encapsulate interactions with Stripe.
    • SubscriptionController with an endpoint like POST /api/subscriptions/checkout-session which takes a planId.
    • This controller calls StripeService to create a Session object using SessionCreateParams.
    • The response includes the Stripe Checkout session ID, which the frontend uses to redirect.
  • Configuration: Stripe API keys in application.properties or environment variables.

Tasks:

  • Choose and set up an account with a payment gateway (e.g., Stripe).
  • Define products and prices in the payment gateway dashboard corresponding to UnravelDocs plans.
  • Add the payment gateway SDK dependency (e.g., stripe-java) to pom.xml.
  • Securely configure API keys.
  • Implement PaymentGatewayService with methods to:
  • Create/retrieve customers in the gateway.
  • Create checkout sessions.
  • Implement the API endpoint to initiate the checkout flow.
  • Write unit and integration tests (mocking gateway interactions).
  • Document the checkout initiation process.

Open Questions/Considerations:

  • Payment Methods: Which payment methods will be supported (cards, bank transfers, etc.)? Configure in gateway.
  • Tax Collection: How will taxes be handled? (Many gateways offer tools for this).
  • Frontend Integration: How will the frontend trigger this and handle the redirect? (This issue focuses on backend).

Metadata

Metadata

Assignees

Labels

UD-ComplexMuch more difficult to implement, requires experience.in progressan issue is being implemented.new featureimplement a new feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions