-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: authorize and capture payment #26
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
- Hold amount first and capture later
WalkthroughThis pull request introduces an authorization and capture payment workflow to the payment library. Three new abstract methods are added to the Adapter interface (authorize, capture, cancelAuthorization), implemented in the Stripe adapter class, exposed through the Pay facade with delegation, and covered by comprehensive test cases. Documentation is updated with usage examples demonstrating the new payment hold-and-charge pattern. No existing code is modified, only new functionality is added following established patterns. Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Areas requiring attention:
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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 (1)
src/Pay/Adapter/Stripe.php (1)
94-101: Consider simplifying the empty array merge.Line 97 merges an empty array with
$additionalParams, which is redundant. You can simplify this to:- $requestBody = array_merge([], $additionalParams); + $requestBody = $additionalParams;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md(1 hunks)src/Pay/Adapter.php(1 hunks)src/Pay/Adapter/Stripe.php(1 hunks)src/Pay/Pay.php(1 hunks)tests/Pay/Adapter/StripeTest.php(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/Pay/Adapter/Stripe.php (2)
src/Pay/Adapter.php (3)
authorize(93-93)capture(104-104)cancelAuthorization(114-114)src/Pay/Pay.php (3)
authorize(101-104)capture(116-119)cancelAuthorization(130-133)
src/Pay/Pay.php (2)
src/Pay/Adapter.php (3)
authorize(93-93)capture(104-104)cancelAuthorization(114-114)src/Pay/Adapter/Stripe.php (3)
authorize(54-71)capture(76-89)cancelAuthorization(94-101)
tests/Pay/Adapter/StripeTest.php (3)
src/Pay/Adapter.php (6)
createPaymentMethod(164-164)createCustomer(213-213)authorize(93-93)capture(104-104)cancelAuthorization(114-114)deleteCustomer(248-248)src/Pay/Adapter/Stripe.php (6)
createPaymentMethod(191-208)createCustomer(289-305)authorize(54-71)capture(76-89)cancelAuthorization(94-101)deleteCustomer(349-355)src/Pay/Pay.php (6)
createPaymentMethod(205-208)createCustomer(284-287)authorize(101-104)capture(116-119)cancelAuthorization(130-133)deleteCustomer(321-324)
🔇 Additional comments (11)
README.md (1)
43-124: Excellent documentation structure!The new Features section provides clear, practical examples for all major payment operations. The authorization/capture flow example effectively demonstrates the hold-and-charge pattern with proper error handling.
src/Pay/Pay.php (1)
89-134: LGTM! Clean facade delegation.The three new methods (
authorize,capture,cancelAuthorization) follow the established delegation pattern perfectly. The PHPDoc comments are clear and describe the business purpose of each operation.src/Pay/Adapter.php (1)
83-114: LGTM! Well-defined adapter contract.The three new abstract methods establish a clear interface for authorization/capture workflows. The optional
$amountparameter incapture()enables partial capture scenarios, and$additionalParamsacross all methods provides good extensibility.src/Pay/Adapter/Stripe.php (2)
54-71: LGTM! Correct Stripe authorization implementation.The
authorize()method correctly creates a payment intent withcapture_methodset to'manual', which is the proper way to hold funds in Stripe. The inclusion ofoff_sessionandconfirmparameters ensures the authorization happens immediately.
76-89: LGTM! Partial capture support implemented correctly.The
capture()method properly handles both full and partial captures using Stripe'samount_to_captureparameter. The conditional logic ensures the parameter is only sent when needed.tests/Pay/Adapter/StripeTest.php (6)
593-619: LGTM! Good test setup pattern.The
testAuthorizeCaptureCancelFlow()method properly sets up the test data (customer and payment method) for the authorization/capture test chain using PHPUnit's@dependsannotation.
621-646: LGTM! Comprehensive authorization test.The test verifies all critical aspects of the authorization: object type, amount, status (
requires_capture), and capture method (manual). The assertions confirm the payment is held correctly.
648-669: LGTM! Full capture test validates the workflow.The test confirms that capturing a held payment succeeds and the full amount is received. The status transition from
requires_capturetosucceededis verified.
671-697: LGTM! Partial capture test ensures flexibility.This test validates that Stripe's partial capture functionality works correctly—authorizing 15000 but only capturing 10000. This is crucial for use cases where the final charge amount may be less than the authorization.
699-726: LGTM! Cancellation test validates the void flow.The test confirms that authorized payments can be properly cancelled, releasing the hold on funds. The status transition to
canceledis verified.
728-765: LGTM! Metadata test with proper cleanup.This test validates that additional parameters (metadata and description) are correctly passed through to Stripe's API. The cleanup at lines 763-764 properly releases resources by cancelling the authorization and deleting the customer.
| } | ||
| ``` | ||
|
|
||
| See the [Payment Authorization and Capture Guide](docs/tutorials/payment-authorization-capture.md) for detailed examples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if the referenced guide file exists
fd -t f "payment-authorization-capture.md" docs/Repository: utopia-php/pay
Length of output: 40
Verify the linked guide exists.
The documentation references docs/tutorials/payment-authorization-capture.md, but this file does not exist in the repository. Either add this file or update the link to an existing guide.
🤖 Prompt for AI Agents
In README.md around line 86, the link targets
docs/tutorials/payment-authorization-capture.md which is missing from the repo;
either add that markdown file with the referenced payment authorization and
capture tutorial to docs/tutorials/, or update the README to point to an
existing guide (e.g., correct path or alternate filename) and ensure the link is
valid and committed so it does not 404.
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.