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:
@@ -57,9 +57,20 @@ func (d *Dispatcher) Enqueue(ctx context.Context, client *models.ClientApp, t *m
|
||||
}
|
||||
body, _ := json.Marshal(payload)
|
||||
sig := signing.Sign(client.Secret, body)
|
||||
if _, err := d.store.EnqueueWebhook(ctx, t.ID, *client.WebhookURL, body, sig); err != nil {
|
||||
id, err := d.store.EnqueueWebhook(ctx, t.ID, *client.WebhookURL, body, sig)
|
||||
if err != nil {
|
||||
log.Printf("webhook enqueue failed for txn %s: %v", t.ID, err)
|
||||
return
|
||||
}
|
||||
// Best-effort immediate delivery so the client credits near-instantly; the
|
||||
// retry loop (Run) still covers it if this attempt fails.
|
||||
go func() {
|
||||
bg, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
if w, err := d.store.GetWebhook(bg, id); err == nil && w != nil {
|
||||
d.deliver(bg, w)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Run starts the delivery loop until ctx is cancelled.
|
||||
|
||||
Reference in New Issue
Block a user