feat(payment): route FlatRender plan purchases through the broker
- identity: when FlatPay (broker) is configured, InitiateZarinPalAsync routes through pay.flatrender.ir instead of calling ZarinPal directly; new HandleBrokerCallbackAsync confirms the payment via the broker inquiry API (authoritative, not trusting the redirect) and activates the plan. New public endpoint GET /v1/payments/callback/broker (already public at the gateway via /callback/*). Env-gated — empty FlatPay__ApiKey keeps the legacy direct-ZarinPal path. - broker: deliver webhooks inline on enqueue (best-effort) in addition to the retry loop, so clients credit near-instantly (db.GetWebhook + goroutine kick). - compose + ENV_FILE: FlatPay__* for identity (FLATPAY_FLATRENDER_*). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -292,6 +292,20 @@ func (s *Store) EnqueueWebhook(ctx context.Context, txnID uuid.UUID, url string,
|
||||
return id, err
|
||||
}
|
||||
|
||||
// GetWebhook loads a single delivery row (used for the inline immediate attempt).
|
||||
func (s *Store) GetWebhook(ctx context.Context, id uuid.UUID) (*WebhookDelivery, error) {
|
||||
var w WebhookDelivery
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
SELECT id, transaction_id, url, payload, signature, attempts
|
||||
FROM payment.webhook_deliveries
|
||||
WHERE id = $1 AND delivered = FALSE`, id).Scan(
|
||||
&w.ID, &w.TransactionID, &w.URL, &w.Payload, &w.Signature, &w.Attempts)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return &w, err
|
||||
}
|
||||
|
||||
// ClaimDueWebhooks returns undelivered webhooks whose next_attempt_at has passed.
|
||||
func (s *Store) ClaimDueWebhooks(ctx context.Context, limit int) ([]*WebhookDelivery, error) {
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user