Skip to content

Commit

Permalink
Update BTC support to take into account current role expiration date
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Jan 29, 2019
1 parent bae99b1 commit 8f37840
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
2019-01-29 DariusIII
* Chg: Update BTC support to take into account current role expiration date
2019-01-28 DariusIII
* Chg: Update nesbot/carbon (2.10.0 => 2.10.1)
* Fix: Fix safe backfill
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/BtcPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function callback()
// If order was paid in full (2) or overpaid (4)
if ((int) $order['status'] === 2 || (int) $order['status'] === 4) {
User::updateUserRole($callback_data['user_id'], $newRole);
User::updateUserRoleChangeDate($callback_data['user_id'], now()->addYears($addYear));
User::updateUserRoleChangeDate($callback_data['user_id'], null, $addYear);
}
}
}
Expand Down
15 changes: 11 additions & 4 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Blacklight\ColorCLI;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Jobs\SendInviteEmail;
Expand Down Expand Up @@ -368,13 +369,19 @@ public static function updateUserRole(int $uid, int $role): int
}

/**
* @param $uid
* @param int $uid
* @param $date
* @return int
* @param int $addYear
*/
public static function updateUserRoleChangeDate($uid, $date): int
public static function updateUserRoleChangeDate($uid, $date = '', $addYear = 0)
{
return self::whereId($uid)->update(['rolechangedate' => $date]);
$currRoleExp = self::whereId($uid)->select(['rolechangedate'])->first();
if (! empty($date)) {
self::whereId($uid)->update(['rolechangedate' => $date]);
}
if (empty($date) && ! empty($addYear)) {
self::whereId($uid)->update(['rolechangedate' => Carbon::createFromDate($currRoleExp['rolechangedate'])->addYears($addYear)]);
}
}

/**
Expand Down

0 comments on commit 8f37840

Please sign in to comment.