Treat additional Pinterest redeem error codes as terminal#1170
Treat additional Pinterest redeem error codes as terminal#1170dikshaasinghh wants to merge 2 commits intodevelopfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Updates ad-credit redemption handling to treat an additional Pinterest “already redeemed” error code as terminal, preventing repeated non-actionable retry calls to the redeem endpoint.
Changes:
- Added Pinterest error code
2322as an “already redeemed” variant and grouped terminal redeem error codes into a single constant list. - Refactored
AdCredits::check_if_coupon_was_redeemed()to use the centralized terminal-error list via a strictin_arraycheck.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/PinterestApiException.php |
Adds 2322 constant and introduces TERMINAL_REDEEM_ERRORS to centralize terminal redeem error codes. |
src/AdCredits.php |
Uses TERMINAL_REDEEM_ERRORS to decide whether to short-circuit retries after terminal redeem errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Observed in customer ticket #11013264 (PIN4WOO-74). Pinterest returns | ||
| * this code alongside 2324 / 2318 for offer-redemption conflicts; the | ||
| * exact distinction is not documented in the public API, but it has the | ||
| * same terminal semantics as the other already-redeemed codes. |
There was a problem hiding this comment.
The docblock references an internal/customer support ticket number (#11013264). If this code is in a public plugin repo, this can be considered internal metadata and is hard to audit for sensitivity over time. Suggest removing the ticket number and referencing only the public engineering issue (PIN4WOO-74) or a generic “observed in support logs” note.
| * Observed in customer ticket #11013264 (PIN4WOO-74). Pinterest returns | |
| * this code alongside 2324 / 2318 for offer-redemption conflicts; the | |
| * exact distinction is not documented in the public API, but it has the | |
| * same terminal semantics as the other already-redeemed codes. | |
| * Observed during investigation for PIN4WOO-74. Pinterest returns this | |
| * code alongside 2324 / 2318 for offer-redemption conflicts; the exact | |
| * distinction is not documented in the public API, but it has the same | |
| * terminal semantics as the other already-redeemed codes. |
There was a problem hiding this comment.
Applied the suggestion in da96805 and also scrubbed two customer domain names from the PR description for the same reason.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
AdCredits::check_if_coupon_was_redeemed()only recognizes Pinterest error codes2324(OFFER_ALREADY_REDEEMED) and2318(OFFER_ALREADY_REDEEMED_BY_ANOTHER_ADVERTISER) as terminal. Support logs show Pinterest also returns2322for the same "already redeemed" condition. Because the check has no branch for2322,handle_redeem_credit()keeps firing the redeem API every hour, each call returning an identical 400, forever.Changes
src/PinterestApiException.php: addOFFER_ALREADY_REDEEMED_VARIANT = 2322with a docblock noting where it was observed, and introduce aTERMINAL_REDEEM_ERRORSlist holding all three already-redeemed codes.src/AdCredits.php: replace the two hard-coded===checks incheck_if_coupon_was_redeemed()with a singlein_array( $error_id, PinterestApiException::TERMINAL_REDEEM_ERRORS, true ). Behavior for2324and2318is unchanged;2322now short-circuits retries the same way.Bug
PIN4WOO-74: https://linear.app/a8c/issue/PIN4WOO-74
Context: relationship to PIN4WOO-73 / PR #1169
One of the reported sites shows the redeem API being hit every 6 seconds — far more often than the hourly heartbeat can account for. Tracing the code, this appears to be a downstream symptom of PIN4WOO-73:
Pinterest_For_Woocommerce::add_redeem_credits_info_to_account_data()(class-pinterest-for-woocommerce.php:1143) calls the redeem API, builds$redeem_informationwitherror_id => 2324, then callsself::record_event(...)on line 1165 — which fatals per PIN4WOO-73.$account_data['coupon_redeem_info'] = $redeem_information), so the terminalerror_idis never persisted. The nexthandle_redeem_credit()run still sees an emptycoupon_redeem_infoand fires the API again.Heartbeat::schedule_events()re-scheduling loop also described in PIN4WOO-73.Once #1169 merges, the
2324case will persist correctly and the hourly check will short-circuit as designed. This PR addresses the independent gap for2322, which would still retry forever (at hourly cadence) even after #1169 is in.Testing
vendor/bin/phpcs src/AdCredits.php src/PinterestApiException.php— no new violations. The errors that do show onsrc/AdCredits.phpall pre-date this change (verified by running phpcs againstdevelopat the same files).check_if_coupon_was_redeemed()today. A meaningful regression test would need to seedaccount_datawith acoupon_redeem_info.error_id = 2322and assert thatcheck_if_coupon_was_redeemed()returnstruewithout invoking the API. Happy to add one if a reviewer would like it.Follow-up (not in this PR)
The Linear issue mentions two related bugs:
v3_create_commerce_partner_merchant409 errors.Both look like the same class of issue (retry forever on responses that are in fact terminal) on different endpoints; each deserves its own fix.