The Subscription Plan Section of the AP Investment Platform API documentation provides detailed information on managing user subscription plans within the platform. This section is divided into the following key areas:
The Subscription Plan Section allows users to manage their subscription plans, including viewing current plans and accessing billing history. This section provides endpoints to retrieve the user's current subscription details and billing history. Once the page is accessed, data is fetched from the /api:g7w7gqaI/subscription/summary endpoint to display the user's current subscription plan. The endpoint runs the App\Http\Controllers\SubscriptionsController@summary method to retrieve subscription data.
{
"has_subscription": true,
"status": "active",
"subscription": {
"id": 3,
"title": "Premium Subscription",
"amount": {
"value": 10000,
"formatted": "10,000",
"currency": "KES"
},
"period": "Yearly",
"cycle": 365,
"is_premium": true
},
"started_at": {
"value": "2025-02-01T06:00:28.000000Z",
"formatted": "01-02-2025"
},
"ends_at": {
"value": "2026-01-09T13:48:53.000000Z",
"formatted": "09-01-2026"
},
"remaining_days": -306,
"total_days": -342.32528935185184,
"is_in_grace_period": false,
"renewal_link": "",
"is_active": true,
"expired_at": null,
"should_renew": false
}
The Current Subscription section displays the user's current subscription plan details, including the subscription title, amount, period, and cycle. The section also shows the subscription start date, end date, remaining days, and renewal status.
The Premimum Subscription plan is an exclusive plan that users get automatically after their portfolio value reaches 100,000.00 KES. The plan automatically renews yearly and provides users with premium features and benefits. The essence of this automation is the user's portfolio value can generate enough revenue to cover the subscription cost.
The $schedule->command('subscriptions:process-premium')->dailyAt('09:00'); command is used to check the user's portfolio value daily and automatically subscribe them to the Premium Subscription plan if the value reaches the threshold.
A list of the user's billing history is displayed in the Billing History section. The section provides details on past subscription payments, including the subscription title, amount, period, cycle, start date, and end date. The endpoint /api:g7w7gqaI/subscription/billing-history-summary?page=1, on page load, fetches the user's billing history data. The endpoint runs the App\Http\Controllers\SubscriptionsController@billingHistorySummary method to retrieve billing history data.
{
"current_page": 1,
"data": [
{
"id": 5794,
"date": "2025-01-09",
"subscription": {
"title": "Yearly Subscription",
"period": "yearly",
"cycle": "365"
},
"payment": {
"amount": {
"value": "10000.00",
"formatted": "10,000"
},
"currency": "KES",
"discount": {
"value": "0.00",
"formatted": "0"
},
"transaction_fee": {
"value": 0,
"formatted": "0"
}
},
"status": {
"is_fulfilled": true,
"label": "Fulfilled",
"processed_by": "M-Pesa"
},
"reference": {
"uuid": "1abad9e4-8718-4ca3-8cd5-abf0ff25d849",
"narration": null
}
},
{
"id": 3553,
"date": "2024-01-18",
"subscription": {
"title": "Yearly Subscription",
"period": "yearly",
"cycle": "365"
},
"payment": {
"amount": {
"value": "10000.00",
"formatted": "10,000"
},
"currency": "KES",
"discount": {
"value": "0.00",
"formatted": "0"
},
"transaction_fee": {
"value": 0,
"formatted": "0"
}
},
"status": {
"is_fulfilled": true,
"label": "Fulfilled",
"processed_by": "M-Pesa"
},
"reference": {
"uuid": "e8addfa3-9813-47fc-84c2-ea0d197a0c2a",
"narration": null
}
}
],
"first_page_url": "http://127.0.0.1:8080/api:g7w7gqaI/subscription/billing-history-summary?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://127.0.0.1:8080/api:g7w7gqaI/subscription/billing-history-summary?page=1",
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "http://127.0.0.1:8080/api:g7w7gqaI/subscription/billing-history-summary?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"next_page_url": null,
"path": "http://127.0.0.1:8080/api:g7w7gqaI/subscription/billing-history-summary",
"per_page": 10,
"prev_page_url": null,
"to": 2,
"total": 2
}
It is important to note that the billing history data is paginated to improve performance and user experience. The pagination allows users to view billing history data in manageable chunks, enhancing readability and navigation.
$schedule->command('send:subscriptionRenewalReminder')->dailyAt('09:00'); is a command used to send subscription renewal reminders to users daily. The command runs the App\Console\Commands\SubscriptionRenewalReminderCommand class to send reminders to users whose subscriptions are about to expire. The reminders prompt users to renew their subscriptions to avoid service interruptions.
public function handle()
{
if (!App::isProduction() || config('app.url') === 'http://localhost') {
return CommandAlias::FAILURE;
}
$adminIds = User::adminAccounts()->pluck('id');
$premiumId = Subscription::premium()->id;
$users = User::query()
->where('login->stage', '!=', 'email_verification')
->whereNotIn('id', $adminIds)
->whereHas('transactions', function ($query) {
$query->where('is_fulfilled', true)
->where('type', TransactionActionEnum::DEPOSIT);
})
->whereHas('subscriptions', function ($query) use ($premiumId) {
$query->whereIn('id', function ($subQuery) {
$subQuery->select(\DB::raw('MAX(id)'))
->from('user_subscriptions')
->groupBy('users_id');
})
->where('subscriptions_id', '!=', $premiumId);
});
foreach ($users as $user)
{
$activeSubscription = $user->getActiveSubscription();
if($activeSubscription && $user->getRemainingSubscriptionDays() === 7)
{
$renewalAmount = $activeSubscription->subscription->amount;
$subscriptionType = $activeSubscription->subscription->title;
$user->notify(new SubscriptionRenewalReminderNotification($user->getRemainingSubscriptionDays(), $renewalAmount, $subscriptionType));
}
}
return CommandAlias::SUCCESS;
}
The SubscriptionRenewalReminderCommand class fetches users who have active subscriptions and are not premium users. The command checks if the user has seven days remaining on their subscription and sends a renewal reminder notification to prompt the user to renew their subscription. The notification includes details such as the remaining days, renewal amount, and subscription type.
It is important to note that if a user has no active subscription, the user will be prompted to subscribe to a plan whnever they try to make an investment. The user chooses either the monthly or yearly subscription plan. The user is then redirected to the payment page to complete the subscription process.