const metadata = {
  queue: "payment-gateways-status-poller",
  id: "payment-gateways:status-poller",
  concurrency: 2
};
async function handle(job, ctx) {
  const service = ctx.resolve("paymentGatewayService");
  const integrationLogService = ctx.resolve("integrationLogService");
  const transactions = await service.listTransactionsForStatusPolling({
    organizationId: job.payload.scope?.organizationId,
    tenantId: job.payload.scope?.tenantId,
    providerKey: job.payload.scope?.providerKey,
    limit: job.payload.limit ?? 100
  });
  for (const transaction of transactions) {
    try {
      await service.getPaymentStatus(transaction.id, {
        organizationId: transaction.organizationId,
        tenantId: transaction.tenantId
      });
    } catch (error) {
      const message = error instanceof Error ? error.message : "Unknown polling error";
      await integrationLogService.write({
        integrationId: `gateway_${transaction.providerKey}`,
        scopeEntityType: "payment_transaction",
        scopeEntityId: transaction.id,
        level: "error",
        message: "Payment status polling failed",
        payload: {
          transactionId: transaction.id,
          message
        }
      }, {
        organizationId: transaction.organizationId,
        tenantId: transaction.tenantId
      });
    }
  }
}
export {
  handle as default,
  metadata
};
//# sourceMappingURL=status-poller.js.map
