{{ __('Admin') }} {{ __('Wallet rules') }}
{{ __('Message pricing & wallet') }}

{{ __('What you') }} {{ __('charge') }} {{ __('per message') }}.

{{ __('Set the price your customers pay for each WhatsApp message — one price per destination country, so a message to the US can cost more than one to India (that is exactly how WhatsApp bills you). Scroll to') }} {{ __('Per-message pricing') }} {{ __('to set it. The affiliate & top-up settings below are optional.') }}

@php $credPerSignup = (int) ($settings['referral_signup_credits'] ?? 100); $credPerMessage = (int) ($settings['credits_per_message'] ?? 1); $credPerRupee = (float) ($settings['credits_per_currency_minor'] ?? 0.1); $rupeeForCredits100 = $credPerRupee > 0 ? round(100 / $credPerRupee, 2) : 0; $msgsFor100Credits = $credPerMessage > 0 ? intdiv(100, $credPerMessage) : 0; $referrerWorth = $credPerSignup * $credPerMessage; $walletSym = \App\Support\FormatSettings::currencyFor()?->symbol ?? ''; // `referral_signup_credits` stores MONEY in minor units. Two values // come out of it and they are NOT the same number: // $signupMoney - the money amount, for display // $signupCredits - what that money actually converts to, via the // SAME helper top-ups use // They used to be conflated: the stored minor figure was shown as // money AND spent as credits, which is what made a Rp900 reward pay // out 90,000 credits instead of 9. $signupMoney = number_format($credPerSignup / 100, 2); // Plain, ungrouped value for . number_format() // emits a thousands comma ("1,000.00") which a number input rejects // outright, so the field rendered EMPTY for every reward >= 1000. $signupMoneyRaw = number_format($credPerSignup / 100, 2, '.', ''); $signupCredits = app(\App\Services\WalletService::class)->creditsForMinor($credPerSignup); $signupMessages = $credPerMessage > 0 ? intdiv($signupCredits, $credPerMessage) : 0; // Refer & Earn (two-sided). Both rewards are MONEY; shown as plain // ungrouped values for the number inputs. $referralEnabled = (bool) ($settings['referral_enabled'] ?? true); $referrerMinor = (int) ($settings['referral_referrer_reward_minor'] ?? $credPerSignup); $refereeMinor = (int) ($settings['referral_referee_reward_minor'] ?? 0); $referrerRewardRaw = number_format($referrerMinor / 100, 2, '.', ''); $refereeRewardRaw = number_format($refereeMinor / 100, 2, '.', ''); $referralWindow = (int) ($settings['referral_window_days'] ?? 30); @endphp {{-- KPI strip --}}
{{ __('Referrer reward') }}
{{ $walletSym }}{{ number_format($referrerMinor / 100, 2) }}
{{ __('to the referrer when a friend makes a first paid top-up') }}@if ($refereeMinor > 0) · {{ $walletSym }}{{ number_format($refereeMinor / 100, 2) }} {{ __('to the friend') }}@endif
{{ __('Cost per message') }}
{{ $credPerMessage }} credit{{ $credPerMessage > 1 ? 's' : '' }}
{{ __('charged from wallet on every outbound send') }}
@php // Symbol of the platform's default currency — what one major // unit of credit-conversion is denominated in. INR ⇒ ₹, USD ⇒ $. $defaultCur = \App\Support\FormatSettings::currencyFor(); $defaultSym = $defaultCur?->symbol ?? ($defaultCur?->code ?? ''); @endphp
{{ __('Top-up rate') }}
{{ rtrim(rtrim(number_format($credPerRupee, 2), '0'), '.') }} cred / {{ $defaultSym }}
{{ $defaultSym }}{{ $rupeeForCredits100 }} buys 100 credits
{{ __('Real spending') }}
{{ number_format($msgsFor100Credits) }}
{{ __('messages a customer can send for 100 credits') }}
{{-- Settings form — full width --}}
@csrf
{{ __('Rules') }}

{{ __('Adjust credit economics') }}

{{ __('live · 3 keys') }}
{{-- Refer & Earn on/off + qualifying window --}}
{{ __('With current values,') }} {{ $walletSym }}{{ $signupMoney }} {{ __('is added to the referrer\'s wallet. At') }} {{ rtrim(rtrim(number_format($credPerRupee, 4), '0'), '.') }} {{ __('credits per') }} {{ $walletSym ?: __('unit') }}{{ __(', that converts to') }} {{ number_format($signupCredits) }} {{ __('credits — enough for') }} {{ number_format($signupMessages) }} {{ __('messages.') }} @if ($credPerSignup > 0 && $signupCredits <= 0) {{ __('That is worth less than one credit, so referrers receive nothing. Raise the reward or the conversion rate.') }} @endif
{{-- Quick guide — 3 cards in a row BELOW the form so it never leaves a gap --}}
{{ __('Quick guide') }}

{{ __('How wallet credits work') }}

{{ __('The wallet:') }} every workspace has a credit balance (column workspaces.wallet_credits). Credits are debited on sends, topped up by payments or referrals.

{{ __('Cost per message:') }} the price tag on every outbound WhatsApp send — chat reply, campaign, broadcast, scheduled, auto-reply. Higher value = each send burns more credit.

{{ __('Top-up conversion:') }} "Credits per {{ $defaultSym }}" decides how many credits each unit of the platform currency buys. 0.01 = {{ $defaultSym }}100/credit · 0.1 = {{ $defaultSym }}10/credit · 1.0 = {{ $defaultSym }}1/credit · 10 = {{ $defaultSym }}0.10/credit. {{-- 0.01 leads the list deliberately: it is the sensible setting for a high-denomination currency (IDR, VND, KRW) and its absence here is part of why the unit mismatch went unnoticed. --}}

{{ __('Refer & Earn:') }} {{ __('when an invited friend makes their FIRST paid top-up, the referrer earns') }} {{ $walletSym }}{{ number_format($referrerMinor / 100, 2) }}@if ($refereeMinor > 0) {{ __('and the friend earns') }} {{ $walletSym }}{{ number_format($refereeMinor / 100, 2) }}@endif, {{ __('both as wallet money. Nothing is paid at signup (prevents free-account farming).') }}

{{ __('Lifecycle') }}

{{ __('When credits move') }}

  1. {{ __('Refer & Earn:') }} {{ __("Friend joins with a referral link, then makes a first paid top-up → both wallets are credited.") }}
  2. {{ __('Workspace Top-Up:') }} {{ __('Workspace adds funds → credits are added at the top-up rate below.') }}
  3. {{ __('Message Sent:') }} {{ __('Workspace sends a message → Credits are deducted per message.') }}
  4. {{ __('Zero Balance:') }} {{ __('Wallet hits 0 → Subsequent messages fail with an "insufficient credits" error until a top-up is completed.') }}
{{ __('Strategy tip') }}

{{ __('Break-even math') }}

{{ __('Lower "cost per message" during promotional periods. The referral reward + cost-per-message together set the actual') }} {{ __('break-even point') }} for affiliate marketing — too generous and your wallet drains, too stingy and nobody refers.

{{-- Every step is printed. The old line read "reward ÷ cost per message = N" while N came from a different figure entirely, so an admin checking the arithmetic by hand could never make it reconcile — which is how the unit mismatch stayed hidden. --}} {{ __('Example:') }} {{ $walletSym }}{{ $signupMoney }} × {{ rtrim(rtrim(number_format($credPerRupee, 4), '0'), '.') }} {{ __('credits per') }} {{ $walletSym ?: __('unit') }} = {{ number_format($signupCredits) }} {{ __('credits') }} ÷ {{ $credPerMessage }} {{ __('per message') }} = {{ number_format($signupMessages) }} {{ __('free sends per referral.') }}
{{-- ───────────── Per-country credit pricing ───────────── --}}
@csrf {{-- Implicit-submit default = SAVE. Without this, pressing Enter in a price cell fires the FIRST submit button on the page, which is "Sync Meta costs" (it carries its own formaction). Sync IGNORES the typed "You Charge" values and reloads them from the DB, so Authentication / Marketing appeared to "reset to ₹0" while Utility (already stored) survived. This off-screen submit — the form's own save action — is now the FIRST submit button, so Enter SAVES instead of syncing. The visible Sync button still works on click. --}}

{{ __('Per-country pricing & Meta cost') }}

{{ __('Charge fairly per message by recipient country and category — the way Meta prices (a US marketing message costs ~12× one to India; service-window replies are free). Add the Meta wholesale cost to see your margin. Leave OFF to keep the single flat rate above.') }}

{{-- Billing mode — the big switch: plan quota vs pure prepaid wallet --}}
{{-- Sync from Meta — fills the Meta-cost column for every country at once. --}}
{{ __('Cross-border note:') }} {{ __('WhatsApp bills by the RECIPIENT country. A message from India to a US number costs the US rate — so each destination country needs its own row.') }}
{{-- Import your OWN official rate card (from WhatsApp Manager) — the exact, commercial-safe source. Inputs post to the separate #rateImportForm below. --}}
{{ __('Official source:') }} {{ __('Download the official "rates by country" CSV (in your currency) from business.whatsapp.com → Pricing, or WhatsApp Manager, and upload it here. Meta\'s own wide CSV (a Marketing / Utility / Authentication column per country) works as-is, and is converted to your currency.') }}
@php $cats = ['' => __('Any category'), 'marketing' => 'Marketing', 'utility' => 'Utility', 'authentication' => 'Authentication', 'service' => 'Service (free window)']; @endphp {{-- Plain-words guide so nobody has to ask "how does this work?" --}}
{{ __('How this works — in simple words') }}
  1. {{ __('One message can cost more than one credit. You decide how many — per country.') }}
  2. {{ __('Leave the switch OFF and every message costs the single flat rate above. Nothing changes.') }}
  3. {{ __('Turn it ON to charge fairly: cheap countries (like India) cost a few credits, costly ones (like the US) cost more — because WhatsApp itself charges you more there.') }}
  4. {{ __('You do NOT need to add every country. Set the default once (blank country), then add only the few countries you want priced differently.') }}
  5. {{ __('"Service" = a reply within 24 hours of the customer messaging you. Keep it at 0 to send those free, just like WhatsApp does.') }}
{{ __('Example: India marketing = 1 credit · US marketing = 12 credits · any reply in the 24-hour window = 0.') }}

{{ __('Your customers never see this page — they only see "you have X credits left". This is just how you price each message behind the scenes.') }}

@php // Money value of ONE credit in the platform currency (major units). // credits_per_currency_minor = credits bought per 1 MAJOR unit (₹1), // so 1 credit = 1/(rate) major. Used to price the customer side of // the margin readout. 0 → unknown (hide margin). $moneyPerCredit = $credPerRupee > 0 ? (1 / $credPerRupee) : 0; $curSym = $defaultSym ?: ''; @endphp
@foreach (($messageRates ?? collect()) as $r) @endforeach @for ($i = 0; $i < 2; $i++) @endfor
{{ __('Country') }} {{ __('Category') }} {{ __('You charge') }}
{{ $curSym }} {{ __('/ msg') }}
{{ __('Meta cost') }}
{{ $curSym }} {{ __('/ msg') }}
{{ __('Your margin') }} {{ __('Remove') }}
{{-- Server-rendered fallback country (no JS). The backend uses this when the TomSelect widget desyncs and submits an empty country_code[] for a row that really has a country, so the per-country edit isn't dropped onto the "Any country" default. --}} {{ $curSym }} {{ $curSym }} —
{{ $curSym }} {{ $curSym }} —

{{ __('Most specific match wins: country + category → country (any category) → any country + category → the flat rate. A blank Country means "any country"; "Any category" sets a per-country default. Keeping Service = 0 leaves free-window replies free.') }}

{{-- Standalone upload target for "Import my rate card" (file inputs above reference this by form="rateImportForm"; kept outside the editor form because a multipart upload can't nest inside another form). --}}