1. Go to this page and download the library: Download a2zwebltd/laravel-affiliate library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
a2zwebltd / laravel-affiliate example snippets
namespace App\Affiliate;
use A2ZWeb\Affiliate\Contracts\RevenueResolver;
use App\Models\Invoice;
use Illuminate\Support\Carbon;
class InvoiceRevenueResolver implements RevenueResolver
{
// Realised revenue, net of refunds, for a fully closed past month. Called by
// affiliate:close-month, including again for earlier months to pick up refunds.
public function revenueForUserInMonth(int $userId, int $year, int $month): int
{
$start = Carbon::create($year, $month, 1)->startOfMonth();
return $this->paidCents($userId, $start, $start->copy()->endOfMonth());
}
// Month-to-date revenue, shown as the in-progress estimate on the partner dashboard.
// Return 0 if you have no live data source.
public function currentMonthRunningRevenueCents(int $userId): int
{
return $this->paidCents($userId, Carbon::now()->startOfMonth(), Carbon::now());
}
private function paidCents(int $userId, Carbon $from, Carbon $to): int
{
return (int) Invoice::query()
->where('user_id', $userId)
->whereBetween('paid_at', [$from, $to])
->sum('amount_cents');
}
}