AFFiNE icon indicating copy to clipboard operation
AFFiNE copied to clipboard

feat(paywall): implement requestApplySubscription mutation for transaction verification

Open hwangdev97 opened this issue 1 month ago • 2 comments

  • Added a new GraphQL mutation to request and apply a subscription using a transaction ID.
  • Enhanced the ViewModel to handle transaction verification and call the mutation upon successful purchase.
  • Improved error handling for GraphQL responses and network issues during subscription requests.

Summary by CodeRabbit

  • New Features
    • Added transaction verification flow for subscription purchases to enhance purchase reliability.
    • Improved subscription application handling to ensure transactions are properly processed and verified before completion.

hwangdev97 avatar Oct 31 '25 12:10 hwangdev97

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

A new GraphQL mutation for applying subscriptions is generated with transaction ID support. The iOS paywall view model is updated to integrate transaction verification, executing the mutation upon successful purchase and handling verification results before transaction completion.

Changes

Cohort / File(s) Summary
GraphQL Mutation Generation
packages/frontend/apps/ios/App/Packages/AffineGraphQL/Sources/Operations/Mutations/RequestApplySubscriptionMutation.graphql.swift
New generated Swift class defining RequestApplySubscriptionMutation with transactionId variable, mutation operation, and nested Data and RequestApplySubscription structures mapping subscription fields (status, plan, recurring, dates, variant) to strongly typed properties.
Paywall Transaction Verification
packages/frontend/apps/ios/App/Packages/AffinePaywall/Sources/AffinePaywall/Model/ViewModel+Action.swift
Adds transaction verification flow for purchases; replaces immediate completion with verification step via new requestApplySubscription(transactionId:) helper method; executes RequestApplySubscriptionMutation, processes results/errors, and finishes transaction accordingly. Imports AffineGraphQL and Intelligents.

Sequence Diagram

sequenceDiagram
    participant User
    participant PayWall as Paywall ViewModel
    participant GraphQL as GraphQL Client
    participant Backend
    
    User->>PayWall: Purchase Complete
    PayWall->>PayWall: Detect Verified Transaction
    PayWall->>PayWall: Extract transactionId
    PayWall->>GraphQL: Execute RequestApplySubscriptionMutation
    GraphQL->>Backend: POST mutation(transactionId)
    
    alt Success
        Backend-->>GraphQL: Subscription Confirmed
        GraphQL-->>PayWall: Result with subscription data
        PayWall->>PayWall: Log subscription
        PayWall->>PayWall: Finish Transaction
        PayWall->>PayWall: Dismiss View
    else Verification Failed
        Backend-->>GraphQL: Error/Unverified
        GraphQL-->>PayWall: Error response
        PayWall->>PayWall: Finish Transaction (no authorize)
        PayWall->>PayWall: Log error
    end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Generated mutation file is straightforward but requires validation that schema mappings are accurate (nested SelectionSet structures, optional/deprecated fields)
  • ViewModel integration involves async/await logic with multiple error paths (success, GraphQL errors, network errors) and continuation handling that should be verified for correctness
  • Pay close attention to error propagation semantics and whether webhook fallback behavior is properly documented

Poem

🐰 A transaction hops through verification gates, With GraphQL whispers, the mutation awaits. Subscriptions bloom when the payload's just right, While async handlers guide logic through flight. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat(paywall): implement requestApplySubscription mutation for transaction verification" directly reflects the core changes in the changeset. The title specifically names the new GraphQL mutation being introduced (requestApplySubscription) and clearly articulates its purpose (transaction verification), which aligns with both major modifications: the addition of the new mutation class and its integration into the ViewModel's purchase flow. The title is concise, specific, and uses conventional commit formatting without vague language or noise, making it clear to anyone reviewing the git history what was implemented.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch hwang/iap-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 31 '25 12:10 coderabbitai[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 56.65%. Comparing base (89cc9b0) to head (2d0b03d). :warning: Report is 10 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #13841      +/-   ##
==========================================
- Coverage   57.20%   56.65%   -0.56%     
==========================================
  Files        2755     2755              
  Lines      137353   137353              
  Branches    21108    20993     -115     
==========================================
- Hits        78569    77813     -756     
- Misses      56568    57828    +1260     
+ Partials     2216     1712     -504     
Flag Coverage Δ
server-test 77.52% <ø> (-1.21%) :arrow_down:
unittest 31.95% <ø> (-0.01%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Oct 31 '25 13:10 codecov[bot]