Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/AdCredits.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ public static function check_if_coupon_was_redeemed() {
$redeem_status = $account_data['coupon_redeem_info']['redeem_status'] ?? false;
$error_id = $account_data['coupon_redeem_info']['error_id'] ?? false;

if ( PinterestApiException::OFFER_ALREADY_REDEEMED === $error_id ) {
// Advertiser has already redeemed the coupon.
return true;
}

if ( PinterestApiException::OFFER_ALREADY_REDEEMED_BY_ANOTHER_ADVERTISER === $error_id ) {
// Different advertiser id has already redeemed the coupon.
if ( in_array( $error_id, PinterestApiException::TERMINAL_REDEEM_ERRORS, true ) ) {
// A prior attempt hit a terminal error from Pinterest (e.g., the
// offer has already been redeemed). Do not retry.
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions src/PinterestApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ class PinterestApiException extends \Exception {
*/
public const OFFER_ALREADY_REDEEMED_BY_ANOTHER_ADVERTISER = 2318;

/**
* Offer already redeemed — additional Pinterest error code observed for
* the same condition.
*
* 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.
*/
public const OFFER_ALREADY_REDEEMED_VARIANT = 2322;

/**
* Pinterest error codes that indicate a terminal, non-retryable failure of
* the `ads_credit/redeem` endpoint. All of these mean the offer cannot be
* redeemed again from this plugin's perspective.
*/
public const TERMINAL_REDEEM_ERRORS = array(
self::OFFER_ALREADY_REDEEMED,
self::OFFER_ALREADY_REDEEMED_BY_ANOTHER_ADVERTISER,
self::OFFER_ALREADY_REDEEMED_VARIANT,
);

/**
* Merchant has been disapproved.
* Some feeds, when deleting, may fail to delete due to the merchant has been disapproved.
Expand Down
Loading