-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #309 from liberu-billing/sweep/Enhanced-Subscripti…
…on-Management-and-Billing-System Enhanced Subscription Management and Billing System
- Loading branch information
Showing
4 changed files
with
162 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
|
||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Subscription; | ||
use App\Services\BillingService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProcessSubscriptionBilling implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function handle(BillingService $billingService) | ||
{ | ||
Subscription::query() | ||
->where('status', 'active') | ||
->where('auto_renew', true) | ||
->get() | ||
->each(function ($subscription) use ($billingService) { | ||
if ($subscription->needsBilling()) { | ||
$invoice = $billingService->generateInvoice($subscription); | ||
$billingService->processAutomaticPayment($invoice); | ||
$subscription->renew(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters