コード例 #1
0
 public function run()
 {
     $today = new Carbon();
     //Fetch and check over active users which have a status of leaving
     $users = User::paymentWarning()->get();
     foreach ($users as $user) {
         /** @var $user \BB\Entities\User */
         if ($user->subscription_expires->lt($today)) {
             //User has passed their expiry date
             echo $user->name . ' has a payment warning and has passed their expiry date' . PHP_EOL;
             //Check the actual expiry date
             //When did their last sub payment expire
             $paidUntil = MembershipPayments::lastUserPaymentExpires($user->id);
             //What grace period do they have - when should we give them to
             $cutOffDate = MembershipPayments::getSubGracePeriodDate($user->payment_method);
             //If the cut of date is greater than (sooner) than the last payment date "expire" them
             if ($paidUntil == false || $cutOffDate->subDays(2)->gt($paidUntil)) {
                 //set the status to left and active to false
                 $this->userRepository->memberLeft($user->id);
                 echo $user->name . ' marked as having left' . PHP_EOL;
             }
             //an email will be sent by the user observer
         } else {
             echo $user->name . ' has a payment warning but is within their expiry date' . PHP_EOL;
         }
     }
 }
コード例 #2
0
 public function run()
 {
     $users = User::active()->where('status', '=', 'active')->notSpecialCase()->get();
     foreach ($users as $user) {
         /** @var $user \BB\Entities\User */
         echo $user->name;
         $expired = false;
         $cutOffDate = MembershipPayments::getSubGracePeriodDate($user->payment_method);
         if (!$user->subscription_expires || $user->subscription_expires->lt($cutOffDate)) {
             $expired = true;
         }
         //Check for payments first
         if ($expired) {
             $paidUntil = MembershipPayments::lastUserPaymentExpires($user->id);
             //$paidUntil = $this->memberSubscriptionCharges->lastUserChargeExpires($user->id);
             if ($paidUntil) {
                 if ($user->subscription_expires && $user->subscription_expires->lt($paidUntil)) {
                     $user->extendMembership($user->payment_method, $paidUntil);
                     //This may not be true but it simplifies things now and tomorrows process will deal with it
                     $expired = false;
                 }
             }
         }
         if ($expired) {
             $user->setSuspended();
             echo ' - Suspended';
         }
         echo PHP_EOL;
     }
 }
<?php

use Carbon\Carbon;
$I = new UnitTester($scenario);
$I->wantTo('confirm the grace period dates are correct');
$paypalDate = \BB\Helpers\MembershipPayments::getSubGracePeriodDate('paypal');
//Make sure its a date that's returned
$I->assertEquals(get_parent_class($paypalDate), 'DateTime');
//Confirm the date is what we expect
$I->assertEquals(Carbon::now()->subDays(7)->setTime(0, 0, 0), $paypalDate);