Skip to content

Conversation

@lohanidamodar
Copy link
Contributor

@lohanidamodar lohanidamodar commented Aug 3, 2025

Summary by CodeRabbit

  • New Features
    • Added the ability to retry a purchase for an existing payment intent using a new method.
  • Tests
    • Introduced new tests to verify the retry purchase functionality, including handling failed and successful retry attempts.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Walkthrough

A new retryPurchase method was introduced across the payment processing abstraction, including the abstract adapter, the Stripe adapter implementation, and the main Pay class. Corresponding unit tests were added to verify the new retry logic for Stripe payment intents.

Changes

Cohort / File(s) Change Summary
Abstract Adapter Update
src/Pay/Adapter.php
Added abstract retryPurchase method to define the interface for retrying payment purchases.
Stripe Adapter Implementation
src/Pay/Adapter/Stripe.php
Implemented retryPurchase method to handle retrying a Stripe payment intent via API call.
Pay Facade Update
src/Pay/Pay.php
Added retryPurchase method delegating to the adapter's implementation.
Stripe Adapter Test
tests/Pay/Adapter/StripeTest.php
Added testRetryPurchase to verify retry logic for Stripe payment intents.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Pay
    participant Adapter
    participant StripeAPI

    Client->>Pay: retryPurchase(paymentId, paymentMethodId, additionalParams)
    Pay->>Adapter: retryPurchase(paymentId, paymentMethodId, additionalParams)
    Adapter->>StripeAPI: POST /payment_intents/{paymentId}/confirm
    StripeAPI-->>Adapter: Response (payment intent status)
    Adapter-->>Pay: Result array
    Pay-->>Client: Result array
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A hop and a skip, a retry anew,
Payments can stumble, but now they push through.
With Stripe in the loop and tests standing by,
Each intent gets a second try.
Rabbits rejoice, for purchases mend—
Onward we bounce, to the very end!
🐇💳✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b936e59 and 0365399.

📒 Files selected for processing (1)
  • tests/Pay/Adapter/StripeTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Pay/Adapter/StripeTest.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-update-payment-intent

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/Pay/Adapter/StripeTest.php (1)

295-314: LGTM! Good basic test coverage.

The test method properly verifies the retry purchase functionality with appropriate assertions. The dependency on testPurchase ensures a valid payment intent exists for retrying. The comment about status variability is a good acknowledgment of Stripe's behavior.

Consider adding additional test cases for edge scenarios:

  • Retrying with a different payment method
  • Testing with additional parameters
  • Error handling for invalid payment IDs
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b253d95 and 7244ecb.

📒 Files selected for processing (4)
  • src/Pay/Adapter.php (1 hunks)
  • src/Pay/Adapter/Stripe.php (1 hunks)
  • src/Pay/Pay.php (1 hunks)
  • tests/Pay/Adapter/StripeTest.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/Pay/Adapter.php (2)
src/Pay/Adapter/Stripe.php (1)
  • retryPurchase (58-72)
src/Pay/Pay.php (1)
  • retryPurchase (97-100)
src/Pay/Pay.php (2)
src/Pay/Adapter.php (1)
  • retryPurchase (91-91)
src/Pay/Adapter/Stripe.php (1)
  • retryPurchase (58-72)
tests/Pay/Adapter/StripeTest.php (3)
src/Pay/Adapter.php (1)
  • retryPurchase (91-91)
src/Pay/Adapter/Stripe.php (1)
  • retryPurchase (58-72)
src/Pay/Pay.php (1)
  • retryPurchase (97-100)
src/Pay/Adapter/Stripe.php (2)
src/Pay/Adapter.php (1)
  • retryPurchase (91-91)
src/Pay/Pay.php (1)
  • retryPurchase (97-100)
🔇 Additional comments (3)
src/Pay/Adapter.php (1)

83-91: LGTM! Well-designed abstract method.

The abstract method declaration is well-structured with clear documentation, appropriate parameter types, and consistent naming. The optional parameters with sensible defaults provide good flexibility for implementations.

src/Pay/Pay.php (1)

89-100: LGTM! Proper facade delegation.

The method correctly implements the facade pattern by delegating to the adapter. The signature matches the abstract declaration and follows the established pattern used by other methods in this class.

src/Pay/Adapter/Stripe.php (1)

50-72: LGTM! Correct Stripe API implementation.

The implementation properly follows Stripe's payment intent confirmation API:

  • Uses the correct endpoint /payment_intents/{paymentId}/confirm
  • Conditionally includes payment method only when provided
  • Properly merges additional parameters
  • Follows the established pattern of using the execute method

The empty check for $paymentMethodId correctly handles both null and empty string cases.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/Pay/Adapter/StripeTest.php (2)

307-312: Inconsistent card number format.

The failing payment method uses a string for the card number ('4000000000000341') while other test methods use integers. This inconsistency could lead to confusion and potential issues.

Apply this diff to maintain consistency:

-        $failingPm = $this->stripe->createPaymentMethod($customerId, 'card', [
-            'number' => '4000000000000341',
-            'exp_month' => 8,
-            'exp_year' => 2030,
-            'cvc' => 123,
-        ]);
+        $failingPm = $this->stripe->createPaymentMethod($customerId, 'card', [
+            'number' => 4000000000000341,
+            'exp_month' => 8,
+            'exp_year' => 2030,
+            'cvc' => 123,
+        ]);

334-339: Maintain card number format consistency.

Similar to the failing payment method, the succeeding payment method should use an integer for the card number to maintain consistency.

Apply this diff:

-        $succeedingPm = $this->stripe->createPaymentMethod($customerId, 'card', [
-            'number' => '4242424242424242', // Stripe test card: always succeeds
-            'exp_month' => 8,
-            'exp_year' => 2030,
-            'cvc' => 123,
-        ]);
+        $succeedingPm = $this->stripe->createPaymentMethod($customerId, 'card', [
+            'number' => 4242424242424242, // Stripe test card: always succeeds
+            'exp_month' => 8,
+            'exp_year' => 2030,
+            'cvc' => 123,
+        ]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7244ecb and b936e59.

📒 Files selected for processing (1)
  • tests/Pay/Adapter/StripeTest.php (1 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
tests/Pay/Adapter/StripeTest.php

319-319: Avoid unused local variables such as '$purchase'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (2)
tests/Pay/Adapter/StripeTest.php (2)

295-356: Overall test implementation looks solid.

The test correctly validates the retry purchase functionality by:

  1. Creating a payment method that will fail
  2. Attempting a purchase and catching the expected exception
  3. Creating a succeeding payment method
  4. Retrying the purchase with the new payment method
  5. Asserting the payment intent ID remains the same and status is succeeded

This comprehensive test covers the core retry functionality well.


351-355: No downstream tests depend on testRetryPurchase
I searched for any @depends testRetryPurchase and found none—overwriting paymentMethodId/paymentId in testRetryPurchase is scoped to that test and does not affect other tests. No changes needed.

stnguyen90
stnguyen90 previously approved these changes Aug 3, 2025
Copy link
Contributor

@stnguyen90 stnguyen90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code rabbit has a good suggestion

@lohanidamodar lohanidamodar merged commit dcf1dba into main Aug 3, 2025
7 checks passed
@lohanidamodar lohanidamodar deleted the feat-update-payment-intent branch August 3, 2025 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants