Simple Membership Plugin › Forums › Simple Membership Plugin › PAYMENT.SALE.COMPLETED is lost permanently when the PayPal API call fails
- This topic has 1 reply, 2 voices, and was last updated 1 month ago by
admin.
-
AuthorPosts
-
October 16, 2026 at 10:43 am #32382
freetiermorioka555
Participant## Summary
When a
PAYMENT.SALE.COMPLETEDwebhook arrives, the plugin makes an additional PayPal API call to fetch subscription details. If that call fails, the payment is not recorded, and because the webhook endpoint still returns HTTP 200, PayPal does not retry. The payment record is then lost permanently. The same pattern applies to webhook signature verification.## Environment
– Plugin: Simple Membership
– Versions checked: 4.4.3 (in production) and 4.7.2 (source reviewed; the same code is present)
– Gateway: PayPal, PPCP subscriptions (button typepp_subscription_new), REST webhooks## What happens
1.
handle_subscription_payment_received()receives the webhook, then calls the PayPal API (get_paypal_subscription_details()) and builds the payment data from that response.
2. If this API call fails, the code logs one line and returns. Nothing is written to the payments table.
3.handle_paypal_webhook()always ends withstatus_header(200), so PayPal considers the event delivered and does not resend it.
4. Signature verification has a similar issue.verify_webhook_event_for_given_mode()returnsfalseboth when PayPal answers with averification_statusother than SUCCESS, and when the verification API call could not be completed at all. The caller returns 200 and discards the event in both cases. The second case is likely a legitimate notification, and it loses its chance of being redelivered.
5.SWPM_PayPal_Request_API::get()andpost()do not set atimeout, so the WordPress default of 5 seconds applies. By contrast,send_request_by_url_and_args()sets 30 seconds explicitly for token requests. This difference makes the failures above more likely when the PayPal API is slow.
6. In my observation, during periods when the PayPal API was degraded, signature verification failures and subscription-detail failures occurred together within the same minutes, and payment notifications received in those periods were left unrecorded. This happened on several occasions.
7. One more point:create_ipn_data_from_paypal_api_subscription_details_data()returnsfalsefor invalid data, but I could not find a check of that return value in the caller. I may be missing something, but it looks unchecked.## Where in the code (line numbers are for 4.7.2)
–
lib/paypal/class-swpm-paypal-webhook-event-handler.php,handle_subscription_payment_received()— early return after a failed API call (around lines 203-205).
–lib/paypal/class-swpm-paypal-webhook-event-handler.php,handle_paypal_webhook()— the verification failure path (lines 38-41) and the finalstatus_header(200).
–lib/paypal/class-swpm-paypal-webhook-event-handler.php,verify_webhook_event_for_given_mode()— both outcomes collapse tofalse.
–lib/paypal/class-swpm-paypal-request-api.php—get()(line 172) andpost()(line 237) set notimeout;send_request_by_url_and_args()(line 378) uses 30 seconds.
–create_ipn_data_from_paypal_api_subscription_details_data()— return value not checked by the caller.## Why this matters
A temporary network or PayPal API problem is enough to make a real payment disappear from the site’s records, with no retry. This affects payment history and anything that depends on it, including any logic that looks at the date of the last successful payment.
## Suggested fix
– Set an explicit
timeoutinget()andpost(). 30 seconds, as already used for token requests, seems a natural choice.
– As a fallback when the API lookup fails, it may be possible to store the transaction from the webhook data alone. TheresourceofPAYMENT.SALE.COMPLETEDcontainsid(the transaction ID),amount.total, andbilling_agreement_id, which looks sufficient to record the payment. Member name and email could be filled in by looking up the member record via the subscriber ID.
– For signature verification, consider distinguishing “PayPal rejected the event” from “verification could not be performed”, and returning a 5xx status in the second case so that PayPal retries delivery.
– Check the return value ofcreate_ipn_data_from_paypal_api_subscription_details_data()before using it.Happy to share sanitized log excerpts if useful. Thank you for your work on the plugin, and I would be glad to help test a fix.
October 17, 2026 at 6:49 am #32388admin
KeymasterThank you. I have applied a fix. It will go out with the next release.
-
AuthorPosts
- You must be logged in to reply to this topic.