| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Services\Payment; |
| 4 |
|
| 5 |
/** |
| 6 |
* Deduplicates inbound payment webhooks by provider event id. |
| 7 |
*/ |
| 8 |
class WebhookEventDedupeStore |
| 9 |
{ |
| 10 |
private const TTL = DAY_IN_SECONDS; |
| 11 |
|
| 12 |
/** |
| 13 |
* Returns true when this event should be processed (first sighting, or no id to key on). |
| 14 |
*/ |
| 15 |
public static function claim(string $provider, string $eventId): bool |
| 16 |
{ |
| 17 |
$provider = sanitize_key($provider); |
| 18 |
$eventId = sanitize_text_field($eventId); |
| 19 |
if ($provider === '' || $eventId === '') { |
| 20 |
return true; |
| 21 |
} |
| 22 |
|
| 23 |
$name = 'ivyforms_wh_' . $provider . '_' . md5($eventId); |
| 24 |
if (get_transient($name) !== false) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
set_transient($name, 1, self::TTL); |
| 29 |
|
| 30 |
return true; |
| 31 |
} |
| 32 |
} |
| 33 |
|