TshieldWebhookModel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Models;
  3. class TshieldWebhookModel
  4. {
  5. private \PDO $pdo;
  6. public function __construct()
  7. {
  8. if (!isset($GLOBALS['pdo']) || !($GLOBALS['pdo'] instanceof \PDO)) {
  9. throw new \RuntimeException('Database connection not initialized.');
  10. }
  11. $this->pdo = $GLOBALS['pdo'];
  12. }
  13. public function approveByExternalId(string $externalId): bool
  14. {
  15. return $this->approveByExternalIds([$externalId]);
  16. }
  17. public function approveByExternalIds(array $externalIds): bool
  18. {
  19. $externalIds = array_values(array_unique(array_filter(array_map(static function ($id) {
  20. if (is_numeric($id)) {
  21. $id = (string)$id;
  22. }
  23. if (!is_string($id)) {
  24. return null;
  25. }
  26. $id = trim($id);
  27. return $id === '' ? null : $id;
  28. }, $externalIds))));
  29. if (empty($externalIds)) {
  30. return false;
  31. }
  32. $params = [];
  33. $placeholders = [];
  34. foreach ($externalIds as $i => $id) {
  35. $key = 'id' . $i;
  36. $placeholders[] = ':' . $key;
  37. $params[$key] = $id;
  38. }
  39. $sql = 'UPDATE "user" SET user_kyc = 1 '
  40. . 'WHERE kyc_external_id IN (' . implode(',', $placeholders) . ') '
  41. . 'AND user_flag = \'a\'';
  42. $stmt = $this->pdo->prepare($sql);
  43. $stmt->execute($params);
  44. return $stmt->rowCount() > 0;
  45. }
  46. }