- Customer cancels an order before shipment
- Item is out of stock after authorization
- Order fails fraud verification
- Customer requests cancellation during fulfillment
Prerequisites
- Complete the quick start PayPal integration.
- Implement an authorization and capture flow that doesn’t use immediate capture.
- Have an authorization ID from an order creation. Store authorization IDs in your database when creating orders. You’ll need them to void the authorization.
- Optional for production:
- Automated void triggers for inventory and fraud checks
- Customer notifications on voided payments
- Void reason tracking for analytics
Integrate server side
Add the following to your existing server file from the quick start integration.Test endpoint
Best practices
- Void promptly: Cancel authorizations immediately when an order won’t be fulfilled to release customer funds. Don’t let an authorization expire.
- Void before capture: Always void instead of refund when possible. Voiding can save up to 3% in processing fees.
- Automate cancellations: Trigger voids automatically for out-of-stock scenarios or fraud detection.
- Handle timing: Authorizations expire after 3 days (standard) or 29 days (honor period).
Important details
- Void vs. refund: Void cancels an authorization before capture. Refund returns money after a payment has been captured. Voiding saves processing fees.
- Finding authorization IDs: You need the authorization ID to void, not the order ID. The authorization ID is returned when you create an order with
AUTHORIZEintent. Store this value in your database immediately. - All-or-nothing operation: You cannot partially void an authorization. Voids cancel the entire authorized amount.
- Voided authorizations cannot be captured: Once voided, an authorization is permanently cancelled and cannot be captured. Attempting to capture will fail with an error.
- Fund release time: In sandbox mode, funds release immediately. In production, funds can take up to 24 hours depending on the customer’s bank.
Test your integration
- Create test authorizations with
AUTHORIZEintent. - Test at different intervals: immediately after authorization, after 1 day, and after 3 days.
- Verify funds are released in the sandbox buyer account after voiding.
Standard testing
| Test scenario | Setup | Expected result |
|---|---|---|
| Void fresh authorization | Default settings | Status: VOIDED returned |
| Void after capture | Capture first | Error: Already captured |
| Void already voided | Void twice | Error: Already voided |
| Void after 3 days | Wait 3 days post-authorization | Success if honor period enabled |
Negative testing
For negative testing:- Make sure to enable negative testing in your sandbox business account as described in the quick start prerequisites.
- In the
.envfile, setENABLE_NEGATIVE_TESTING=trueand setNEGATIVE_TEST_TYPEto one of the error codes in the table. - Restart the server after changing the
.envfile:node server.js.
| Test scenario | Error code | Expected result |
|---|---|---|
| Void expired authorization | AUTHORIZATION_EXPIRED | Error: Authorization expired |
| Void not found | RESOURCE_NOT_FOUND | Error: Authorization not found |
| Permission denied | PERMISSION_DENIED | Error: not authorized to void |
| Internal server error | INTERNAL_SERVER_ERROR | 500 error returned |
Go-live checklist
- Test void flow in sandbox with real authorization IDs.
- Implement void reason tracking.
- Set up customer cancellation notifications.
- Train support team on void vs refund scenarios.
- Configure automatic void triggers, such as out of inventory or a fraudulent transaction.
- Monitor void success rates.
- Test with real $1 authorization and void it.
Post-launch monitoring
These values are suggested monitoring thresholds for your integration, not performance guarantees from PayPal.| Metric | Target | Action if below target |
|---|---|---|
| Void success rate | 99% | Check for expired authorizations. |
| Time to void | <1 hour | Automate cancellation workflow. |
| Void vs refund ratio | 80% void | Train team to void before capture. |
| Failed void rate | <1% | Review error patterns. |
| API response time | <2 seconds | Check PayPal API status. |