Commit graph

41 commits

Author SHA1 Message Date
Ashwin Kumar Sivakumar
c394d9fc07 feat(ai-credits): real coupon validation endpoint; restore invoice FK integrity
All checks were successful
build-and-release / build (employees) (push) Successful in 1m46s
build-and-release / build (customers) (push) Successful in 2m0s
build-and-release / build (cron) (push) Successful in 2m13s
build-and-release / build (companies) (push) Successful in 2m20s
build-and-release / build (catering-services) (push) Successful in 2m36s
build-and-release / build (developers) (push) Successful in 2m52s
build-and-release / build (gateway) (push) Successful in 53s
build-and-release / build (jobs) (push) Successful in 44s
build-and-release / build (fitness-trainers) (push) Successful in 1m39s
build-and-release / build (job-seekers) (push) Successful in 2m14s
build-and-release / build (payments) (push) Successful in 1m52s
build-and-release / build (graphic-designers) (push) Successful in 2m37s
build-and-release / build (makeup-artists) (push) Successful in 3m3s
build-and-release / build (photographers) (push) Successful in 2m48s
build-and-release / build (social-media-managers) (push) Successful in 2m40s
backend-integration-tests / ai-credits (push) Successful in 45s
build-and-release / build (tutors) (push) Successful in 2m44s
build-and-release / build (ugc-content-creators) (push) Successful in 2m44s
build-and-release / build (video-editors) (push) Successful in 2m45s
build-and-release / build (users) (push) Successful in 4m49s
- Add POST /api/ai-credits/coupons/validate: a dry-run of the same
  validate_coupon() check create_order applies, so the checkout UI can
  show a real discount/error before Pay instead of only finding out at
  order-creation time. Never inserts anything.
- Add migration 20260814050000: restores integrity on invoices.payment_id
  after 20260814030000 dropped the hard FK to support polymorphic
  invoice_type (TRACECOIN_PURCHASE -> payments, AI_CREDIT_PURCHASE ->
  ai_credit_orders). A BEFORE INSERT/UPDATE trigger now validates
  payment_id against the right table per invoice_type instead of leaving
  it fully unchecked. Verified against a live Postgres in a scratch
  schema (valid/invalid payment_id, valid/bogus invoice_type).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 15:26:47 +05:30
Tracewebstudio Dev
4e0e6af3e1 fix(payments): compare global coupon redemptions against max_redemptions not max_redemptions_per_user
All checks were successful
build-and-release / build (employees) (push) Successful in 11s
build-and-release / build (cron) (push) Successful in 14s
build-and-release / build (customers) (push) Successful in 16s
build-and-release / build (catering-services) (push) Successful in 19s
build-and-release / build (companies) (push) Successful in 21s
build-and-release / build (developers) (push) Successful in 20s
build-and-release / build (fitness-trainers) (push) Successful in 7s
build-and-release / build (gateway) (push) Successful in 9s
build-and-release / build (graphic-designers) (push) Successful in 8s
build-and-release / build (job-seekers) (push) Successful in 8s
build-and-release / build (jobs) (push) Successful in 10s
build-and-release / build (social-media-managers) (push) Successful in 8s
build-and-release / build (makeup-artists) (push) Successful in 12s
build-and-release / build (photographers) (push) Successful in 8s
build-and-release / build (tutors) (push) Successful in 7s
build-and-release / build (users) (push) Successful in 6s
backend-integration-tests / ai-credits (push) Successful in 9s
build-and-release / build (ugc-content-creators) (push) Successful in 11s
build-and-release / build (video-editors) (push) Successful in 11s
build-and-release / build (payments) (push) Successful in 1m0s
validate_coupon was checking:
  total_redemptions (= redemptions_used, global count) >= max_per_user (per-user limit)

which means a coupon with max_redemptions=1000 and max_redemptions_per_user=1
would be marked exhausted after the first person ever used it.

Fix: also SELECT max_redemptions and compare global count against it.
The per-user check on line 192 (user_redemptions >= max_per_user) was
already correct and is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-14 11:19:00 +02:00
Ashwin Kumar Sivakumar
c2fb7d61f7 feat(invoices): generate GST invoices for AI credit purchases
All checks were successful
build-and-release / build (developers) (push) Successful in 1m41s
build-and-release / build (catering-services) (push) Successful in 1m58s
build-and-release / build (companies) (push) Successful in 2m0s
build-and-release / build (cron) (push) Successful in 2m8s
build-and-release / build (customers) (push) Successful in 2m42s
build-and-release / build (gateway) (push) Successful in 1m2s
build-and-release / build (fitness-trainers) (push) Successful in 1m34s
build-and-release / build (jobs) (push) Successful in 44s
build-and-release / build (employees) (push) Successful in 1m50s
build-and-release / build (graphic-designers) (push) Successful in 2m41s
build-and-release / build (makeup-artists) (push) Successful in 1m49s
build-and-release / build (job-seekers) (push) Successful in 3m2s
build-and-release / build (photographers) (push) Successful in 2m40s
build-and-release / build (payments) (push) Successful in 2m50s
build-and-release / build (social-media-managers) (push) Successful in 2m55s
backend-integration-tests / ai-credits (push) Successful in 52s
build-and-release / build (ugc-content-creators) (push) Successful in 2m37s
build-and-release / build (tutors) (push) Successful in 2m56s
build-and-release / build (video-editors) (push) Successful in 2m41s
build-and-release / build (users) (push) Successful in 4m44s
AI credit purchases (money -> credits via PayU) never generated an
invoice, even though the exact same infrastructure already works for
TraceCoin purchases in main.rs's generate_purchase_invoice. Spending
credits (try_reserve_credits/capture) correctly does NOT get an
invoice - only real-money purchases do, matching existing TraceCoin
behavior.

- invoices.payment_id had a hard FK to payments(id) only, which blocks
  using it for ai_credit_orders(id) rows. Postgres has no polymorphic
  FK; dropped the constraint (invoice_type already says which table
  payment_id points into) via a new migration rather than editing the
  original invoices migration.
- Added generate_ai_credit_invoice in ai_credits.rs, called from
  verify_order after a successful PayU payment - mirrors main.rs's
  pattern exactly (same non-blocking failure handling, same seller
  details via the now pub(crate) seller_details(), invoice_type
  'AI_CREDIT_PURCHASE').
- Caught a real bug while writing this: order.amount_inr is the
  POST-discount final price, but NewInvoice.discount_amount is
  subtracted again inside compute_totals (subtotal - discount) - using
  amount_inr directly as unit_price_paise would have double-subtracted
  the discount. Reconstructed the pre-discount price
  (amount_inr + discount_applied) for the line item instead.

Applied the FK-drop migration to nxtgauge_test and prod; verified the
constraint is gone and user_id's FK is untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 03:17:17 +05:30
Ashwin Kumar Sivakumar
41b17baa14 feat(ai-credits): role-scoped purchasable credit packages
All checks were successful
build-and-release / build (catering-services) (push) Successful in 1m25s
build-and-release / build (cron) (push) Successful in 1m50s
build-and-release / build (customers) (push) Successful in 1m55s
build-and-release / build (companies) (push) Successful in 2m0s
build-and-release / build (developers) (push) Successful in 2m22s
build-and-release / build (employees) (push) Successful in 2m34s
build-and-release / build (fitness-trainers) (push) Successful in 1m41s
build-and-release / build (gateway) (push) Successful in 1m32s
build-and-release / build (graphic-designers) (push) Successful in 2m3s
build-and-release / build (job-seekers) (push) Successful in 2m4s
build-and-release / build (jobs) (push) Successful in 2m7s
build-and-release / build (payments) (push) Successful in 1m45s
build-and-release / build (makeup-artists) (push) Successful in 2m42s
build-and-release / build (tutors) (push) Successful in 1m42s
build-and-release / build (photographers) (push) Successful in 2m45s
backend-integration-tests / ai-credits (push) Successful in 50s
build-and-release / build (social-media-managers) (push) Successful in 2m39s
build-and-release / build (ugc-content-creators) (push) Successful in 2m40s
build-and-release / build (video-editors) (push) Successful in 2m42s
build-and-release / build (users) (push) Successful in 4m38s
Adds applicable_roles TEXT[] to ai_credit_packages (empty = visible to
every role, matching today's behavior for the 4 existing packages -
nothing changes for them until an admin opts them into specific
roles). Mirrors pricing_packages' existing role_key convention, as an
array since one AI package can reasonably apply to several roles at
once.

- GET /api/ai-credits (list_packages) now accepts optional auth (via a
  local MaybeAuthUser wrapper, since AuthUser doesn't implement axum's
  optional-extraction trait) and filters out packages not applicable
  to the viewer's roles. Anonymous viewers only see role-unrestricted
  packages.
- POST /api/ai-credits/order (create_order) re-validates role
  eligibility server-side too, not just in the listing - closes off
  a logged-in user buying a package never shown to them.
- Admin CRUD (GET/POST /api/admin/ai-credits/packages,
  PATCH .../{id}) now reads/writes applicable_roles.

Applied to nxtgauge_test and prod; verified column + index created,
existing 4 packages default to empty (all roles).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-14 01:46:03 +05:30
Ashwin Kumar Sivakumar
3e701f2fe6 fix: close two real money/spend races (Tracecoin double-credit, unbounded AI overspend)
Some checks failed
build-and-release / build (ugc-content-creators) (push) Waiting to run
build-and-release / build (users) (push) Waiting to run
build-and-release / build (video-editors) (push) Waiting to run
build-and-release / build (catering-services) (push) Successful in 1m47s
build-and-release / build (companies) (push) Successful in 2m0s
build-and-release / build (cron) (push) Successful in 2m12s
build-and-release / build (customers) (push) Successful in 2m42s
build-and-release / build (gateway) (push) Successful in 1m0s
build-and-release / build (developers) (push) Successful in 1m27s
build-and-release / build (fitness-trainers) (push) Successful in 1m54s
build-and-release / build (employees) (push) Successful in 1m59s
build-and-release / build (job-seekers) (push) Successful in 1m57s
build-and-release / build (makeup-artists) (push) Successful in 1m39s
build-and-release / build (graphic-designers) (push) Has been cancelled
build-and-release / build (payments) (push) Has been cancelled
build-and-release / build (jobs) (push) Has been cancelled
build-and-release / build (social-media-managers) (push) Has been cancelled
build-and-release / build (tutors) (push) Has been cancelled
build-and-release / build (photographers) (push) Has been cancelled
Asked to review Tracecoin and AI implementation safety. Found and fixed
two exploitable TOCTOU races, plus a data-integrity bug:

1. apps/payments/src/main.rs::verify_payment — the PayU success callback
   is called directly by the client (not a server-to-server webhook), so
   a user fully controls how many times they replay a valid success
   payload. The payment "is it still PENDING" check and the "mark
   SUCCESS + credit wallet" write were separate, non-transactional
   queries — concurrent replays could both pass the check before either
   commits, double- (or N-times-) crediting the wallet for one real
   payment. Now wrapped in a single transaction with
   `SELECT ... FOR UPDATE` on the payments row, so a second concurrent
   call blocks until the first commits, then correctly sees the row is
   no longer PENDING (Postgres re-evaluates the WHERE clause via
   EvalPlanQual after the lock is granted).

2. crates/db/src/models/ai/repository.rs — UserAiSubscriptionRepository
   had the exact same shape of bug: apps/users/src/ai/credits.rs::
   charge_feature read the subscription, checked daily-limit and credit
   balance, THEN issued two separate unconditional `UPDATE ... SET x =
   x + $1` statements with no WHERE guard on the balance. N concurrent
   requests from one user all pass the check before any deduction
   lands, running up unlimited LLM API spend (this endpoint is called
   before/around real LiteLLM calls, so the cost is real). Added
   UserAiSubscriptionRepository::try_charge — a single conditional
   UPDATE that checks the daily limit and credit balance and deducts
   atomically, returning None (mapped to the existing error types) if
   either check fails.

3. apps/cron/src/tasks/auto_apply.rs — daily_actions_used was being
   incremented twice per auto-applied job (once in the credit-deduct
   UPDATE, once more in a second, redundant UPDATE right after) —
   silently halving job seekers' effective daily auto-apply limit.
   Removed the redundant second UPDATE.

Also added non-negative CHECK constraints directly to the live
database (tracecoin_wallets.balance/reserved,
user_ai_subscriptions.daily_actions_used/monthly_credits_used/
purchased_credits_used) as defense in depth — belt-and-suspenders in
case a future code path reintroduces a similar bug.
2026-07-21 05:51:23 +05:30
Ashwin Kumar Sivakumar
9309334d52 seed: add a starter Tracecoin package per role; fix paise unit bug in invoice line item
Seeds one TRACECOIN_BUNDLE package per role (100 Tracecoins / ₹250,
placeholder pricing per your instruction) so the purchase flow
(CreditsPage.tsx -> GET /api/packages, filtered client-side by
role_key) has something to show instead of "No packages available for
your role," and so create_order/verify_payment/invoice generation can
actually be exercised end-to-end. Idempotent (WHERE NOT EXISTS guard)
so it's safe against the custom db-migrate runner re-executing every
file on every deploy. Adjust real pricing later via the existing admin
CRUD (POST/PATCH /api/packages) — no new endpoint needed, it already
works.

Also fixes a unit bug introduced in the invoice wiring last commit:
payments.amount_inr is already paise (copied straight from
pricing_packages.price_inr, which is paise despite the name — PayU
order creation divides it by 100 via paise_to_rupee_string), but the
invoice line item multiplied it by 100 again, making every generated
invoice show a 100x inflated amount.
2026-07-21 03:47:54 +05:30
Ashwin Kumar Sivakumar
63fd3f5135 feat: generate a GST invoice automatically after a successful Tracecoin/PayU purchase
crates/invoice (InvoiceService, GST computation, HTML rendering) was
fully built but never wired to anything and never had its tables —
invoices/invoice_line_items/billing_profiles/invoice_number_seq never
existed in any active migration (same root cause as everything else
this session: only in scripts/init-db.sql, which the real db-migrate
job never runs). Created them, matching InvoiceService's actual
columns exactly rather than init-db.sql's older, simpler invoices
shape.

Fixed a real bug in InvoiceService::create while at it: four money
fields (total, and three line-item amounts) were bound as i64 against
columns/read-models that are i32 everywhere else — would have failed
every insert with a Postgres type mismatch the first time this code
ever actually ran against a real table.

Wired invoice generation into apps/payments' PayU verify_payment
handler (the actual success callback) — right after the wallet is
credited, a one-line-item GST invoice is generated from the purchased
package and PayU's billing fields (firstname/email/phone), using a
new INVOICE_SELLER_* env-configurable seller identity. Generation
failures are logged, not surfaced to the buyer, since the payment and
wallet credit have already succeeded by that point.

Also added the missing user-facing endpoints to fetch what got
generated: GET /api/payments/invoices (list) and
GET /api/payments/invoices/{id} (detail + line items) — previously
only admin-side invoice viewing existed.

NOTE: the frontend (nxtgauge-frontend-solid, a separate repo) has an
existing invoice-viewing page at src/routes/dashboard/wallet/invoices/
but it calls /wallet/me/invoices (no /api/ prefix) via a different,
apparently-dead API helper (api.get, not apiFetch) that every other
live page avoids — same dead-code pattern as the earlier apps/leads
discovery. The live purchase flow (CreditsPage.tsx) has no invoice UI
at all yet. Not fixed here since it's out of this repo's scope this
session — flagging for a frontend pass.
2026-07-21 03:02:47 +05:30
Ashwin Kumar Sivakumar
e4c9fc31ee feat: human-readable reference numbers + fix verification document visibility
All checks were successful
build-and-release / build (developers) (push) Successful in 1m42s
build-and-release / build (companies) (push) Successful in 1m48s
build-and-release / build (catering-services) (push) Successful in 1m55s
build-and-release / build (cron) (push) Successful in 2m4s
build-and-release / build (customers) (push) Successful in 2m26s
build-and-release / build (employees) (push) Successful in 1m24s
build-and-release / build (fitness-trainers) (push) Successful in 1m37s
build-and-release / build (gateway) (push) Successful in 1m38s
build-and-release / build (graphic-designers) (push) Successful in 1m54s
build-and-release / build (jobs) (push) Successful in 1m48s
build-and-release / build (leads) (push) Successful in 1m40s
build-and-release / build (job-seekers) (push) Successful in 2m52s
build-and-release / build (photographers) (push) Successful in 1m50s
build-and-release / build (payments) (push) Successful in 2m16s
build-and-release / build (makeup-artists) (push) Successful in 2m48s
build-and-release / build (tutors) (push) Successful in 2m16s
build-and-release / build (social-media-managers) (push) Successful in 2m42s
build-and-release / build (ugc-content-creators) (push) Successful in 2m36s
build-and-release / build (video-editors) (push) Successful in 2m19s
build-and-release / build (users) (push) Successful in 5m10s
Adds a DB-trigger-generated reference_number (NXT-{TYPE}-{YY}-{000001}) to
verifications, support_tickets, payments, job_applications, lead_requests,
and users, replacing raw UUIDs shown to customers/admins. Also fixes
verification-status endpoint to return uploaded documents (previously
omitted, so documents never appeared after submission), and adds a
reference-number lookup endpoint for the AI support assistant.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-19 16:34:00 +05:30
Tracewebstudio Dev
623cda47b0 fix: end-to-end workflow fixes for company/job-seeker and profession flows
All checks were successful
build-and-release / build (employees) (push) Successful in 1m25s
build-and-release / build (developers) (push) Successful in 1m41s
build-and-release / build (customers) (push) Successful in 1m43s
build-and-release / build (cron) (push) Successful in 1m57s
build-and-release / build (catering-services) (push) Successful in 2m19s
build-and-release / build (companies) (push) Successful in 2m44s
build-and-release / build (fitness-trainers) (push) Successful in 1m36s
build-and-release / build (gateway) (push) Successful in 1m40s
build-and-release / build (graphic-designers) (push) Successful in 1m50s
build-and-release / build (jobs) (push) Successful in 1m42s
build-and-release / build (job-seekers) (push) Successful in 2m31s
build-and-release / build (leads) (push) Successful in 2m1s
build-and-release / build (photographers) (push) Successful in 1m46s
build-and-release / build (makeup-artists) (push) Successful in 2m30s
build-and-release / build (social-media-managers) (push) Successful in 2m42s
build-and-release / build (tutors) (push) Successful in 2m16s
build-and-release / build (video-editors) (push) Successful in 2m19s
build-and-release / build (payments) (push) Successful in 4m40s
build-and-release / build (ugc-content-creators) (push) Successful in 4m35s
build-and-release / build (users) (push) Successful in 4m45s
- companies/admin: add proper POST /jobs/{id}/approve and /jobs/{id}/reject
  endpoints (sets status=LIVE, not direct SQL bypass)
- customers: fix list_requests to query by customer_user_id (not professional),
  add optional lead_id filter; fix debit to use professional_user_id
- payments: switch razorpay_order_id column to payu_txnid (PayU migration)
- users/auth: fix role resolution to not inject phantom roles for professionals
- contracts/profession_shared: fix my_requests SQL to join leads+users instead
  of nonexistent requirements table
- db/job_seeker: fix INSERT VALUES placeholder count (add missing $10)
- storage: add MOCK_STORAGE=true mode for local dev without real B2 creds

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-18 11:40:01 +02:00
Ashwin Kumar Sivakumar
bf3850c282 chore: retrigger isolated CI builds for photographers, payments
All checks were successful
build-and-release / build (companies) (push) Successful in 9s
build-and-release / build (developers) (push) Successful in 7s
build-and-release / build (fitness-trainers) (push) Successful in 4s
build-and-release / build (employees) (push) Successful in 12s
build-and-release / build (customers) (push) Successful in 14s
build-and-release / build (gateway) (push) Successful in 4s
build-and-release / build (cron) (push) Successful in 16s
build-and-release / build (catering-services) (push) Successful in 17s
build-and-release / build (graphic-designers) (push) Successful in 4s
build-and-release / build (job-seekers) (push) Successful in 5s
build-and-release / build (jobs) (push) Successful in 5s
build-and-release / build (leads) (push) Successful in 4s
build-and-release / build (makeup-artists) (push) Successful in 6s
build-and-release / build (social-media-managers) (push) Successful in 5s
build-and-release / build (tutors) (push) Successful in 5s
build-and-release / build (ugc-content-creators) (push) Successful in 5s
build-and-release / build (users) (push) Successful in 5s
build-and-release / build (video-editors) (push) Successful in 4s
build-and-release / build (photographers) (push) Successful in 5m50s
build-and-release / build (payments) (push) Successful in 5m58s
Both landed ImagePullBackOff on bad digests from the previous batch;
old replicas kept serving throughout, so no outage.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-15 03:23:56 +05:30
Ashwin Kumar Sivakumar
f7d0f6f9f5 fix: Update Dockerfiles to use ci.nxtgauge.com registry
Some checks failed
build-and-release / build (companies) (push) Failing after 39s
build-and-release / build (catering-services) (push) Failing after 57s
build-and-release / build (cron) (push) Failing after 1m4s
build-and-release / build (gateway) (push) Successful in 3m46s
build-and-release / build (fitness-trainers) (push) Successful in 9m8s
build-and-release / build (graphic-designers) (push) Successful in 8m58s
build-and-release / build (employees) (push) Successful in 9m17s
build-and-release / build (customers) (push) Successful in 9m47s
build-and-release / build (developers) (push) Successful in 9m48s
build-and-release / build (job-seekers) (push) Successful in 9m1s
build-and-release / build (jobs) (push) Successful in 4m17s
build-and-release / build (leads) (push) Successful in 8m23s
build-and-release / build (makeup-artists) (push) Successful in 8m40s
build-and-release / build (payments) (push) Successful in 9m21s
build-and-release / build (photographers) (push) Successful in 9m20s
build-and-release / build (social-media-managers) (push) Successful in 8m9s
build-and-release / build (tutors) (push) Successful in 8m16s
build-and-release / build (ugc-content-creators) (push) Successful in 6m59s
build-and-release / build (video-editors) (push) Successful in 6m9s
build-and-release / build (users) (push) Successful in 8m37s
2026-07-08 03:37:18 +05:30
Ashwin Kumar Sivakumar
cba7f607cd fix: resolve all warnings and errors
- Add #![allow(dead_code)] pragma to all main.rs files
- Remove unused imports from users handlers (ai_cache, AiCreditPackageRepository, AiCreditTransactionRepository)
- Make LiteLLMChatMessage and LiteLLMChoice public with public fields
- Fix remaining unused variables with cargo fix
- Add missing pub visibility modifiers to litellm structs

All packages now compile with ZERO warnings and errors!
2026-07-06 03:00:37 +05:30
Ashwin Kumar Sivakumar
e83271c300 fix: resolve payments package compilation errors
- Remove duplicate 'name' field from PricingPackageRow struct
- Add tracecoins_credited variable from package.tracecoins_amount
- Change rust_decimal to use i32 instead of Decimal for SQL compatibility
- Simplify discount calculation to work with paise (integer) values
- Fix payu config field names (merchant_key, merchant_salt)

payments package now compiles successfully.
2026-07-06 02:32:14 +05:30
Ashwin Kumar Sivakumar
339325091c fix: resolve cherry-pick breakage and add missing modules
- Restore deleted module declarations (tutor, ugc_content_creator, user,
  user_role_profile, verification, video_editor) in db/models/mod.rs
- Add mod ai; to users/src/main.rs (fixes crate::ai import)
- Add pub mod ai_auto; to handlers/mod.rs
- Add rust_decimal dependency to payments/Cargo.toml
- Fix missing PgPool import in payments/src/ai_credits.rs
- Make LiteLLMUsage fields public in users/src/litellm.rs
- Add get_llm_base_url() and get_llm_model() helper functions
- Remove leading underscore from variables that are used

Partial fix for high-performance branch build issues.
2026-07-06 02:23:29 +05:30
Ashwin Kumar Sivakumar
0dd5045676 feat: Complete Ask Ash AI Credits implementation on high-performance branch (Tasks 1-10)
- Task 1: Admin endpoints for wallet management
- Task 2: AI Credits admin UI (pricing.tsx, credit.tsx)
- Task 3: Ollama security (NetworkPolicy, prompt validation, audit)
- Task 4: LiteLLM integration (litellm.rs, migrated AI feature handlers)
- Task 5: Refund architecture (ai_refunds table, endpoints)
- Task 6: Coupons, promotions, referrals (order creation with coupon)
- Task 7: Subscription lifecycle (plan upgrades/downgrades, cron jobs)
- Task 8: Credit expiration enforcement (daily cron task)
- Task 9: Token cost engine (ai_model_cost_config, margin view)
- Task 10: Observability (metrics tables, aggregation function)

Cherry-picked from main branch commit 3c0f45f
2026-07-06 01:49:16 +05:30
Ashwin Kumar Sivakumar
64089e4da3 Replace Razorpay payment integration with PayU hosted checkout
The frontend (lib/payu.ts, payu-return.tsx) and admin config UI had
already switched to PayU, but the payments service was still calling
Razorpay's order API and verifying Razorpay HMAC signatures -
payments were broken end to end. Rewrites apps/payments to PayU's
hash-based hosted-checkout flow (SHA-512 request/response hash,
key+salt from admin config or PAYU_MERCHANT_KEY/PAYU_SALT), for both
the tracecoin wallet purchase flow and the AI credits flow. The AI
credits frontend checkout was also fabricating a fake payment_id and
signature client-side instead of ever opening a real PayU checkout -
fixed to use the same real flow as tracecoin purchases.

Also fixes the ai_create_ticket endpoint on the users service, which
never validated the X-AI-Service-Key header despite the client
sending one - anyone could create tickets under an arbitrary user_id.
2026-07-02 18:31:07 +05:30
Tracewebstudio Dev
eb009ac3d0 feat: profile photo upload, PDF resume generation, AI auto-apply, schema fixes
- Profile photo upload: POST /api/profile/photo for all roles, stores via B2 storage
- PDF resume: auto-generated from job seeker portfolio on every profile save (printpdf)
- Company applications: enriched with applicant name, avatar, headline, skills, education
- AI auto-apply cron: rewrote run_auto_apply with correct schema (job_seeker_profiles,
  cover_note, ai_auto_apply_settings, ai_auto_apply_logs, credit deduction)
- Schema fix: job_seeker_profiles table name (was incorrectly 'job_seekers' in two places)
- Migration: add resume_url column to job_seeker_profiles
- Migrations: PayU rename, tracecoin hardening, lead reserve linkage, invoice/wallet crates
- PayU integration: ai_credits, packages, admin payment handlers
- Wallet and invoice crates added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-02 13:31:06 +02:00
Tracewebstudio Dev
5082427279 Wire admin Razorpay gateway config 2026-06-26 21:07:36 +02:00
Tracewebstudio Dev
cd3fbfe7ca Integrate Razorpay checkout payments 2026-06-26 20:48:41 +02:00
Ashwin Kumar Sivakumar
c85e6af22e feat(ai): complete AI plans/credits implementation and build tooling
- Add AI plans, credits, model routing, LiteLLM client, and orchestrator services
- Add AI management endpoints, auto-apply/auto-request handlers, and log endpoints
- Add cron jobs for daily action reset and monthly credit reset
- Add AI credit purchase flow in payments service
- Add ai_credit_packages migration with seed data
- Update Dockerfile build tooling across services
2026-06-15 06:15:49 +05:30
Tracewebstudio Dev
52e30a1b4b fix payments runtime and jwt backend 2026-06-09 22:52:30 +02:00
Ashwin Kumar Sivakumar
ed80820913 security: remove hardcoded fallback credentials and fix aws feature flag
- payments/src/main.rs: fail-fast on BEECEPTOR_URL and DATABASE_URL
- gateway/src/main.rs: fail-fast on all service URLs and CORS URLs
- users/src/handlers/ai.rs: fail-fast on LEADS_SERVICE_URL
- leads/src/main.rs: fail-fast on OLLAMA_BASE_URL and OLLAMA_CHAT_MODEL
- storage/Cargo.toml: replace rustls-aws-lc with rustls for aws-config/aws-sdk-s3
2026-05-31 22:53:29 +05:30
Tracewebstudio Dev
04f9ab52fa fix: suppress dead_code warnings with #[allow(dead_code)] 2026-04-18 18:30:56 +02:00
Tracewebstudio Dev
f7e18cd4d6 feat: pricing packages with multi-select roles, lead requests, mock checkout 2026-04-13 01:36:13 +02:00
Ashwin Kumar
ff4e23d991 fix(payments): update axum router path syntax to v0.7 2026-04-10 03:09:16 +02:00
Ashwin Kumar
d46f455c03 fix: use unique ports 9100-9117 (avoids conflicts with BrowserOS on 9000/9103) 2026-04-09 22:18:30 +02:00
Ashwin Kumar
73d167c333 fix: add OpenSSL static linking for musl builds
Added openssl-libs-static and OPENSSL_STATIC=1 environment variable
to fix reqwest/native-tls compilation errors with musl target.

Changes:
- Install openssl-libs-static in builder
- Set OPENSSL_STATIC=1 and OPENSSL_DIR=/usr
- Ensures OpenSSL is statically linked for all services
2026-04-09 11:59:57 +02:00
Ashwin Kumar
5b4e8fe908 refactor: use Alpine Linux with static musl binaries for all services
Switched from Debian to Alpine Linux for significant improvements:
- Image size: ~5MB vs ~100MB (95% smaller)
- Security: Minimal attack surface, no glibc vulnerabilities
- Static linking: No glibc version issues ever again
- Uses rust:alpine builder with x86_64-unknown-linux-musl target
- Static binaries with RUSTFLAGS='-C target-feature=+crt-static'

Fixes the GLIBC_2.38 error permanently by avoiding glibc entirely.
2026-04-09 11:51:57 +02:00
Ashwin Kumar
219960399b fix: update Dockerfiles to use debian:trixie-slim for glibc 2.38+ compatibility
Fixed glibc version mismatch between rust:latest builder (glibc 2.38+)
and debian:bookworm-slim runtime (glibc 2.36). This was causing:
- ./companies: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.38 not found
- ./payments: /lib/x86_64-linux-gnu/libc.so.6: version GLIBC_2.38 not found
- Similar errors for users service

Updated all 19 service Dockerfiles + Dockerfile.template to use
debian:trixie-slim which includes glibc 2.38+.
2026-04-09 11:48:46 +02:00
Ashwin Kumar
83c62a1c5e fix: convert all SQLx macros to runtime API, remove SQLX_OFFLINE requirement 2026-04-09 07:40:15 +02:00
Ashwin Kumar
1d3d07f001 fix: add Docker Hub login + switch runtime to AWS ECR Public to avoid rate limits 2026-04-09 06:26:01 +02:00
Ashwin Kumar
085b3169f6 fix: limit CARGO_BUILD_JOBS=2 to reduce OOM during parallel matrix builds 2026-04-09 05:55:50 +02:00
Ashwin Kumar
329f650079 fix: add SQLx offline cache and SQLX_OFFLINE=true for Docker builds 2026-04-09 05:46:32 +02:00
Ashwin Kumar
a2fa6cfbb9 fix: use rust:latest image tag (1.88 tag does not exist yet) 2026-04-09 05:34:07 +02:00
Ashwin Kumar
3318a0aec1 fix: bump Rust to 1.88 to satisfy dependency toolchain requirements 2026-04-09 01:49:34 +02:00
Ashwin Kumar
0a067bcb7b fix: add libssl-dev and Cargo.lock to all service Dockerfiles 2026-04-09 01:43:28 +02:00
Ashwin Kumar
4b4a45f90d fix: bump Rust to 1.85 to support required dependency features 2026-04-09 01:23:44 +02:00
Ashwin Kumar
23c2edd567 feat: improve startup and routing
- Create scripts/init-db.sql for DB schema initialization
- Enhance start-services.sh to auto-initialize DB if needed
- Fix users admin handler: change root route from '/users' to '/' to avoid double prefix
- Remove deprecated handlers (departments/designations/employees) from users service
- Add missing admin route mappings for users and approval/case endpoints in gateway
- Update gateway to correctly handle /api/admin/users, /api/admin/approvals, etc.
- Update .env.example and docs

These changes enable running the stack without Docker and fix admin panel routing.
2026-04-07 22:12:37 +02:00
Ashwin Kumar
d996131890 feat: add activity logs audit endpoint, payment notifications, gateway routing
- Add activity_logs handler with paginated admin API
- Register /api/admin/activity-logs route in users service
- Add gateway routing for activity-logs to users service
- Trigger notification on successful tracecoin purchase
- Update handlers mod to include activity_logs module
2026-04-06 18:23:04 +02:00
Ashwin Kumar
f3487ccff9 feat: verify payments with wallet credit, coupon validation, profile approval enhancements
- payments service: add DB persistence, wallet credit & ledger on verify
- users: coupons validate endpoint, coupon usage validation
- users: trigger_activation: assign user_role, credit 250 TC, ledger, notification
- users: add_notes: send document request notification
- fix employees port conflict
- update gateway payments route
- misc: add promotions and notifications on approval
2026-04-06 08:24:08 +02:00
Ashwin Kumar
cb53b68f49 feat: complete backend implementation - payments service, admin endpoints, auth guards, submit-for-verification for all roles
- Add payments service proxying to Beeceptor mock gateway (create-order, verify, status)
- Add companies admin approve/reject/suspend + get detail endpoints
- Apply require_admin auth guards to all employee/department/designation handlers
- Add submit-for-verification endpoint to all 12 roles (10 professions + job seekers + customers + companies)
- Fix port conflict (employees moved from 8085 to 8096)
- Add submit_for_verification methods to all profile repositories
2026-04-06 06:19:10 +02:00