如何取消PayPal v2 API中状态为CREATED且超过10分钟的订单?
Hey there, I’ve run into this exact issue before—let me break down the correct way to cancel those stale CREATED orders for you.
First off, you’re right that the DELETE method isn’t supported for the v2 Orders API. PayPal designed this API to use PATCH requests to modify order statuses instead of deleting them entirely. Here’s how to make it work for your use case:
Step 1: Target the Right Orders
First, filter your orders to only those that:
- Have a status of
CREATED - Were created more than 10 minutes ago (you’ll need to track creation timestamps on your end since PayPal doesn’t expose a "time since creation" filter directly)
Step 2: Use the PATCH Endpoint
Call the PATCH /v2/checkout/orders/{order_id} endpoint with a JSON Patch payload that updates the order’s status to CANCELLED.
Example Request Payload:
[ { "op": "replace", "path": "/status", "value": "CANCELLED" } ]
Step 3: Authentication & Headers
Just like other PayPal v2 API calls, you’ll need to include your valid OAuth 2.0 access token in the Authorization header (format: Bearer YOUR_ACCESS_TOKEN), and set Content-Type to application/json.
Important Notes:
- This only works for orders in
CREATEDorAPPROVEDstatus. Once an order isCOMPLETED, you can’t cancel it (you’d need to process a refund instead). - PayPal will automatically expire
CREATEDorders after a set period (usually 3 hours), but manually cancelling stale ones after 10 minutes is a good practice to keep your order list clean.
内容的提问来源于stack exchange,提问作者Erik Huzinecz

