Invitation Code
A new user enters a friend's ID within 48 hours of signing up, and the friend earns a commission, in coins, on everything that user tops up with real money. You set the percentage, the period and the withdrawal limit.
By هبة الله ماهرFirst published Nov 29, 2026
About this feature
A new user enters a friend's ID within 48 hours of signing up, and the friend earns a commission, in coins, on everything that user tops up with real money. You set the percentage, the period and the withdrawal limit.
What it does
- How it works: every user's invitation code is simply their own ID (the special ID if they wear one). A new user opens the invitation screen, taps Enter Code, types the friend's ID and the two accounts are linked as inviter and invited. It works only during the first 48 hours after the account was created, only once per account, never with your own ID, and never from a phone that another account has already used to sign in. Entering the code pays nobody anything (this stops fake accounts from minting coins); the inviter earns only a commission on what the invited user later buys.
- What earns a commission: only real money. A top-up through a payment gateway (including Google Play) and a purchase from a recharge agent count. Transfers between users, converting earnings into coins, BD top-ups and admin top-ups never earn a commission. A recharge agent's own sale to a user the agent invited does not earn the agent a commission either. Each top-up books the commission as whole coins, unclaimed, in the inviter's invitation ledger and sends the inviter a notification. If your app has no wallet nothing is booked.
- How the inviter collects: on the invitation screen the inviter sees the income available to withdraw now and presses "Extract Coins"; the coins go straight into the balance. Each request pays up to the withdrawal limit you set ("You can extract up to N coins per request"); a request above it, or with nothing to take, is refused with a clear sentence and nothing moves. Every amount is a whole number of coins. The invited user has nothing to claim.
- What you set in the control panel: the "Invitation Code" menu with two screens. Invitations Log: the list of inviters with how many users each invited and what each earned, a search by ID, then the invited users of one inviter, then the operation log of one invited user (each top-up and the commission it gave). Invitation Code Settings, in two tabs. Tab one: Inviter commission (%), from 0 to 100 with two decimals; Commission period (days), from 0 to 36,500, where 0 means no time limit; Withdrawal limit (coins), a whole number. Tab two: the Invitation rules text shown inside the app (written once in the panel's default language, the other languages come from the translations page). Only a platform administrator also sees the "Close invitation code for all" switch, which stops every redemption at once. The permissions are: view the log, view the settings, edit the settings, and two to switch the invitation entry on or off for users and for hosts from their profile in the panel, given to the admin position by default. You can also replace the menu icon.
- Files: nothing is uploaded; the only file setting is the optional menu icon (WebP or PNG).
- What the user sees in the app: an "Invitation" row in the profile menu (it shows only for users whose invitation entry is on), and the invitation screen: "Invite your friends now" with the commission percentage, "Share & Invite Friends" with the user's own ID and a share link that opens the app straight at the code, "My Invitation Income" (earned today, total earned, invited today, total invited, and what is available to withdraw now) with the Extract Coins button, "My Invitations" with the list of invited friends and what each earned (or "No earnings yet"), the rules text, and "Enter Code" for a new user. Every refusal is explained in the user's own language: device already used, no user owns this code, your own code, already used a code, outside the first 48 hours, or codes are turned off right now.
- Works with all themes: the screens take their colours from the active theme, so they read well on light and dark themes.
- Why it is worth it for you: it turns your users into your marketing. Each person who brings a friend keeps earning as long as the friend tops up, which is a reason to invite more, while the rules (real money only, 48 hours, one code per account and per phone) protect you from fake accounts. You decide how generous it is with one percentage, a time limit and a withdrawal cap.
- Requirements: the base users and the Wallet (the commission is paid in coins). Nothing else. Other features can listen to an "invitation accepted" event when a code is redeemed.
Add-ons
Depends on
Base users and the Wallet (for the coin commission and the withdrawal).
In the app
Swipe for more
Install and remove
After you buy, you'll also find these commands in My purchases.
Install
php artisan feature:install invite_code --applyRemove (your data stays)
Disable the feature in the base with one command (shown on this page). The invitation row and screen disappear, the panel menu closes, and no new commission is booked. The links and the earnings ledger stay, and the commission already earned is not lost.
php artisan feature:remove invite_codeRemove its add-ons first: removing a feature while its add-ons are installed is refused.
No add-ons for this feature yet.
Required features
This has no requirements: you can install it on its own.
Install and remove
The command sets up the feature's tables, admin panel pages, permissions, settings, and base data. In the app, the feature appears in its place on its own. The feature disappears from the app and the admin panel, and your data stays. Install it again and everything comes back as it was.
After you buy, you'll also find these commands in My purchases.
Install
php artisan feature:install invite_code --applyRemove (your data stays)
Disable the feature in the base with one command (shown on this page). The invitation row and screen disappear, the panel menu closes, and no new commission is booked. The links and the earnings ledger stay, and the commission already earned is not lost.
php artisan feature:remove invite_codeRemove its add-ons first: removing a feature while its add-ons are installed is refused.
Use this feature inside yours
الخلاصة بصراحة: كود الدعوة بتنفّذ port من البيس (للعمولة) وبتقدّم لميزتك حدث واحد: InvitationAccepted + قراية جدولين + علاقات User + مفتاح التشغيل. مفيش port ولا slot تاني بتقدّمه. اللي مش موجود مكتوب إنه مش موجود.
الـports (سيرفر)
- اللي الميزة بتقدّمه للغير: مفيش. مفيش
interfaceفيModules/Invitationتقدر تربط عليه. - اللي الميزة بتنفّذه (مش بتقدّمه):
Modules\Wallet\Support\Recharge\RechargeCommission(book(userId, amount, chargeId)وdispatchForCharge(...)) بتاع البيس، والتنفيذInvitationCommissionبيتربط منInvitationServiceProvider::register(). من غير الميزة البيس بيربطNullRechargeCommission: مفيش عمولة وبيتكتبLog::warning، والشحن بيكمّل عادي. ماتربطش تنفيذ تاني على نفس الـport (الميزة هي صاحبته). - تقدّم حاجة للـport ده من ميزتك؟ لأ. هو للشحن بس: «شحنة اتحجزت للمستخدم» وبيدفع عمولة الداعي.
الأحداث اللي الميزة بتطلّعها
معلنة في feature.json تحت slots.events.emits:
| الاسم | الإصدار | الكلاس | الـpayload |
|---|---|---|---|
invite_code.invitation_accepted | 1 | Modules\Invitation\Events\InvitationAccepted | inviterId (int، الداعي)، inviteeId (int، المدعو)، code (string، الكود اللي اتكتب) |
- بيتبعت مرة واحدة لكل ربط، بعد الـcommit (
DB::afterCommitجوّهInvitationRedeemer::redeem)، فمستمعك مايشوفش ربط اتعمله rollback، ولو الربط التاني لنفس المدعو اترفض (already_invited) مفيش حدث. - فشل مستمعك مابيفشّلش الدعوة: الاستثناء بيتسجّل (
report) والمدعو بياخد نجاح. - مش متزامن مع الكيو: ده
event()عادي، يعني مستمعك بيتنفّذ في نفس الطلب؛ لو شغلك تقيل ابعته لجوب. - ماتقرّرش فلوس من الـpayload لوحده: اقرا الصف (
user_code_invitations.invited_id = inviteeId) وخلّي الـidempotency بتاعك علىinviteeId(ربط واحد لكل مدعو). - مش موجود (مفيش حدث له): «الداعي كسب عمولة» و«الداعي سحب». لو محتاجهم اطلبهم كارت؛ ماتخترعهمش.
- من البيس كمان:
Modules\Wallet\Events\CoinsRecharged(userId, amount, type, source, ledgerId, idempotencyKey, balanceAfter) لما مستخدم يشحن.
الداتا اللي تقدر تقراها
Modules\Invitation\Entities\UserCodeInvitation(جدولuser_code_invitations):user_id= الداعي،invited_id= المدعو،invited_charge= مجموع شحن المدعو،user_percentage= مجموع عمولة الداعي (الاسم مضلل).created_atوقت الربط. صف واحد لكل مدعو. (العمودcodeاتشال في 1.1.0: مفيش كود بيتخزّن؛ الكود هوuidالداعي ويوصلك في الحدث.)Modules\Invitation\Entities\UserEarnInvitation(جدولuser_earn_invitations):parent_idالداعي،user_idالمدعو،source_type(charge_percentageهو الوحيد اللي بيتكتب؛first_join_reward_hostوfirst_join_reward_inviteeصفوف قديمة من قبل 1.3.0: تاريخ، ومحدش بيصرفها)،amount،is_claimed.- علاقات على
User(بتتسجّل من الـprovider، يعني موجودة بس والميزة شغّالة):$user->userCodeInvite(اللي دعاهم)،$user->codeInvitationsEarn(أرباحه)،$user->codeInvitations. - اقرا بس. ماتكتبش في الجدولين ولا ترصد فلوس من محفظة الدعوة؛ الكتابة بس من
InvitationRedeemer/InvitationCommission/InvitationEarnings(فيها قفل وUNIQUE). - مفيش علاقة «مين دعاني» على المدعو؛ استعلم بـ
invited_id.
Slots (التطبيق)
- اللي الميزة بتقدّمه: مفيش slot جديد.
- اللي بتسجّله في slots البيس:
profileMenuEntries(صف «الدعوة»id: invite_code، ظاهر لو المفتاح مفتوح وshowInvitationCode == trueللمستخدم) وDeepLinkProvider(رابطinvitation_code_<base64url(json(code))>) وراوتينRoutes.inviteBonusوRoutes.inviteUser. - اللي تقدر تستخدمه من ميزتك: الثابت
inviteCodeFeature = 'invite_code'وinviteCodeMenuEntryIdمنlib/src/features/invitation/invitation_module.dart، وNavigator.pushNamed(context, Routes.inviteBonus)لفتح شاشة الدعوة (لو المفتاح مقفولgenerateRouteبيرجعnullفالراوت مش بيتحل).
مثال سيرفر: ميزة تكافئ الداعي
أ) لما المدعو يستخدم الكود (بالحدث). في provider ميزتك. اسم الحدث نص مش use، عشان لو كود الدعوة مش متركّبة ماتقعش:
use App\Models\User;
use Modules\Wallet\Services\Ledger\CoinCredit;
use Illuminate\Support\Facades\Event;
// MyFeatureServiceProvider::boot()
Event::listen('Modules\Invitation\Events\InvitationAccepted', function (object $e) {
$inviter = User::find($e->inviterId);
if (! $inviter) {
return;
}
// المفتاح بيمنع التكرار لو المستمع اتنفّذ تاني: نفس المفتاح مرة واحدة بس
CoinCredit::credit($inviter, 50, UserCoinLogType::FEATURE_REWARD /* شوف الملاحظة تحت */, 'my_feature:inviter_bonus', "my_feature:invite_accepted:{$e->inviteeId}");
});ب) لما المدعو يعمل حاجة تانية بعدين (مفيش حدث ليها، فاسأل الجدول):
use App\Services\AppFeatureService;
use Illuminate\Support\Facades\Schema;
use Modules\Invitation\Entities\UserCodeInvitation;
function rewardInviterFor(int $inviteeId, int $taskId): void
{
// المفتاح مقفول من اللوحة (مفيش صف = مفتوح) أو الجدول مش موجود ⇒ مفيش مكافأة
if (! AppFeatureService::isEnable('invite_code') || ! Schema::hasTable('user_code_invitations')) {
return;
}
$inviterId = UserCodeInvitation::where('invited_id', $inviteeId)->value('user_id');
$inviter = $inviterId ? \App\Models\User::find($inviterId) : null;
if (! $inviter) {
return; // المدعو ماجاش بكود دعوة
}
\Modules\Wallet\Services\Ledger\CoinCredit::credit($inviter, 50, \Modules\Wallet\Enum\UserCoinLogType::FEATURE_REWARD, 'my_feature:inviter_bonus', "my_feature:task:{$taskId}");
}- المكافأة من ميزتك (محفظتك وميزانيتك)، مش من محفظة الدعوة. تحذير (11-16): الكود نفسه شال مكافآت قبول الدعوة لأن حسابات وهمية بتكتب كود وتاخد كوينز ببلاش؛ ماتصرفش كوينز على «قبول دعوة» لوحده في ميزتك، اربط الصرف بحاجة بتتكلف فلوس (شحنة).
- نوع الدفتر:
UserCoinLogType::FEATURE_REWARD(feature_reward) مش موجود لسه في البيس، جون هيضيفه (كارت عنده)، واسمه لسه بيتراجع معاه قبل ما يتثبّت؛ ماتشغّلش المثال قبل ما ينزل.itemName=<slug>:<سبب>وkeyللـidempotency. ميزة خارجية ماتقدرش تضيف case للـenum، وممنوع تستخدمINVITATION_CODE(بتاع الدعوة) ولاADMIN_REWARD(للأدمن). - المثالين ماتشغّلوش، مبنيين على توقيع
CoinCredit::creditوعلى تست الحدثtests/Feature/Invitation/InvitationSwitchGuardAndAcceptedEventTest.php. - لازم تعلن في
feature.jsonبتاعك"optional": ["invite_code"]عشان مايبقاش اعتماد مخفي (الصيغة فيdocs/feature-contract/contract-naming-map.md).
مثال تطبيق: شاشة في ميزتك تفتح الدعوة
import 'package:general/src/core/base/app_features.dart';
import 'package:general/src/core/routes/routes.dart';
import 'package:general/src/features/invitation/invitation_module.dart' show inviteCodeFeature;
Widget inviteShortcut(BuildContext context) {
// المفتاح مقفول أو الميزة مش متركّبة ⇒ ماترسمش الزرار
if (!AppFeatures.isEnabled(inviteCodeFeature)) return const SizedBox.shrink();
return TextButton(
onPressed: () => Navigator.pushNamed(context, Routes.inviteBonus),
child: const Text('ادعُ صاحبك'),
);
}الـimport المباشر لملف invitation_module.dart تماسّ مؤقت: لما الميزة تتفصل كباكدج هيبقى الثابت 'invite_code' نصًا، والمفتاح بيتفحص بـAppFeatures.isEnabled('invite_code'). مفيش API تطبيق تاني للميزة، والتطبيق مابيستقبلش InvitationAccepted (حدث سيرفر بس؛ مفيش حدث لحظي ليها).
لو الميزة مش متركّبة (أو مقفولة)
- السيرفر: الـ5 راوتات بتختفي (404)؛ الشحن بيكمّل ومفيش عمولة (
NullRechargeCommission+Log::warning)؛ علاقاتUserالثلاث مش موجودة (استدعاؤها =Error)؛ الكلاساتModules\Invitation\...ممكن تفضل قابلة للتحميل بس (الـautoload على الفولدر) فماتعتمدش علىclass_existsلوحدها، والجدولين بيفضلوا بداتاهم. مفتاحapp_features.invite_codeالمقفول من اللوحة بيرجّع 403 على الـ5 راوتات (FeatureRouteGuard، مفيش صف = مفتوح) وبيوصل للتطبيق (app-check). لو الميزة متركّبة والمفتاح مقفول: الحدثInvitationAcceptedما بيتبعتش لأن مفيش راوت يربط. العمولة بتوقف بـstop_invite_code(غيابه = موقوف). - التطبيق:
AppFeatures.isEnabled('invite_code') == false⇒ الصف والراوتان والـdeep link بيختفوا (الراوت بيرجعnull). - ميزتك لازم تشتغل كاملة من غيرها: اعمل
returnبدري زي المثال، ماترميش استثناء ولا تفترض إن الداعي موجود.
اعمل إضافة جوّه كود الدعوة
الحالة بصراحة: كود الدعوة مفيهاش إضافات النهارده، الإضافة الحقيقية الوحيدة اللي تقدر تعملها دلوقتي تبقى مبنية على الحدث InvitationAccepted وعلى قراية الجدولين (فوق)، لحد ما نعلن نقاط تمديد بكارت.
- شكل
feature.jsonلإضافة: في العقد الحالي (app/Features/FeatureRegistry.php) الخانة اللي بتربط الإضافة بالأب اسمهاparent(مشof):kind: "addon"وparent: "invite_code"، والـrequiresلازم يشمل الأب. من غيرparentصحيح الـvalidator بيرفض (an addon needs a valid parent slug). مثال صغير (متبني علىModules/ChargeAgency/feature.json، مش متركّب عندنا):
{
"contract": "2.1",
"slug": "invite_streak_bonus",
"kind": "addon",
"parent": "invite_code",
"version": "1.0.0",
"name": {"key": "invite_streak_bonus::feature.name"},
"app_switch": "invite_streak_bonus",
"requires": ["base:users@1", "invite_code@^1"],
"slots": {"routes": {"api": {"file": "Routes/api.php"}}, "data": {"tables": ["invite_streak_bonuses"]}},
"namespace": "Modules\\InviteStreakBonus"
}- الملفات: موديول في
Modules/<الاسم>/فيهfeature.jsonوmodule.json(providers) وRoutes/api.phpومايجريشن إضافية بس، وProvider بيسجّل المستمع بنص الاسمEvent::listen('Modules\Invitation\Events\InvitationAccepted', ...)(زي المثال فوق). ماتعدّلش في ملفاتModules/Invitationولا تكتب في جدوليها. - المسموح: مستمع على
InvitationAccepted، وقرايةuser_code_invitations/user_earn_invitations، وصرف مكافأتك من محفظتك أنت. مش مسموح: تغيّر نسبة العمولة، ولا تكتب في جدولين الدعوة. - التركيب والشيل (سيرفر):
php artisan feature:install <slug>(بدون--applyتقرير تجريبي؛ مع--applyبينفّذ مايجريشن الإضافة وبينشئ صفapp_featuresمقفول)، وبعدهاphp artisan feature:open <slug>. الشيل:php artisan feature:remove <slug>(تقرير تجريبي،--applyينفّذ). شيل الأبinvite_codeبيرفض لو فيه إضافة معتمدة عليه إلا بـ--cascade. الداتا مابتتمسحش. - التطبيق:
python3 tools/apply_features.py --set <feature> on|off(بيركّب أو يشيل الميزة من التطبيق)، و--analyze-without <feature>لتحليل اللي هيتأثر. مفيش slot تطبيق في كود الدعوة تسجّل عليه (فوق). - التوقيع: أي تعديل جوّه
Modules/Invitation(حتى هذا الملف) بيغيّر الهاش؛ التوقيع (feature:catalogue invite_code --sign) شغل سليم بس، مش إضافتك.
الإعدادات والصلاحيات والمنيو
الإعدادات (كلها من اللوحة، شاشة invitation-code/settings):
| المفتاح | مكانه | تأثيره |
|---|---|---|
earn_from_invitation | configs | نسبة عمولة الداعي من كل شحنة للمدعو |
invitation_code_date | configs (وpanel_settings بقيمة افتراضية 0) | عدد أيام العمولة؛ 0 = من غير حد زمني |
invitation_withdrawal_limit | configs | حد السحب في الطلب (افتراضي 50000 لو مفيش قيمة) |
stop_invite_code | settings (مفتاح فلوس محمي) | إيقاف العمولة والسحب؛ غيابه = موقوف |
f_invite_code__rules.content | جدول f_invite_code__rules (صف واحد) | نص شرح الدعوة: مكتوب مرة واحدة باللغة الافتراضية، وباقي اللغات من صفحة الترجمة؛ الـAPI بيرجّعه بلغة المستخدم مع fallback. (الصفّين القدام invitation_content_ar/en في settings ما بيتقرواش ومابيتمسحوش) |
النسبة وحد السحب فلوس، فالميزة ماتزرعهاش في panel_settings؛ بتتكتب من الشاشة بس. حد السحب وأيام العمولة أعداد صحيحة (الفورم بيرفض الكسر)، والنسبة بتقبل خانتين عشريتين. المفتاح app_switch: invite_code (جدول app_features) هو مفتاح التشغيل العام: مقفول ⇒ 403 على الـ5 راوتات.
الصلاحيات (panel_permissions، كلها legacy: true، الوضع الافتراضي admin): browse-user-parent (سجل الدعوات)، browse-invitation-code، browse-invitation-code-setting وedit-invitation-code-setting (الإعدادات)، invite-switch-users وinvite-switch-hosts (زرار إيقاف الدعوة للمستخدم/المضيف).
المنيو (panel_menu): قسم «Invitation Code» (أيقونة fa-ticket، بعد «Achievements») وتحته صفّين: «Invitations Log» (parent-users، صلاحية browse-user-parent) و«Invitation Code Settings» (invitation-code/settings، صلاحية browse-invitation-code-setting).
شاشات اللوحة (panel_screens): parent-users (للأدمن والـpreview)، وinvitation-code/settings (الإعدادات)، وinvitation-code (العنوان القديم: بيحوّل 301 للإعدادات، ما بقاش ليه فورم)، ومسار القفل send-request-invite-code.
What's new
1.4.4Released Nov 29, 2026By هبة الله ماهر
- Release 1.4.4 (signed build 4e869de)