[Sprint/JollyJellyfish](feat): Added plus tiers to endpoint and passed through #578
0/5 threads resolved
unmarked as a Work In Progress
193 194 $this->calculatePlusExpires("+1 year", $wireTimestamp, $previousTimestamp) 195 ->shouldEqualApproximately(strtotime('+1 year', time()), 1.0e-9); 196 } 197 198 function it_should_return_expiry_time_for_existing_1_year_plus_a_new_month() 199 { 200 $wireTimestamp = time(); 201 $previousTimestamp = strtotime('+11 months', time()); //already subbed for the next 11 momths 202 203 $this->calculatePlusExpires("+1 month", $wireTimestamp, $previousTimestamp) 204 ->shouldEqualApproximately(strtotime('+1 year', time()), 1.0e-9); 205 } 206 207 function it_should_return_expiry_time_for_existing_monthly_subscription_upgrade_to_year() 208 { - Maintainer
Yay, tests!
69 69 } 70 70 71 71 $manager = Core\Di\Di::_()->get('Wire\Manager'); 72 73 $tier = $_POST['tier'] ?? ''; - Maintainer
Let's change this to a constant exposed in the Plus namesspace,
60 60 return $wire; 61 61 } 62 62 63 $user->setPlusExpires(strtotime('+30 days', $wire->getTimestamp())); 63 // check the users tier if passed in. If not, it's a standard monthly subscription. 64 switch ($tier) { 65 case 'lifetime': 66 $user->setPlusExpires(9999999999); //life 67 break; - Maintainer
Let's make these constants in the wire namespace
65 79 66 80 //$wire->setSender($user); 67 81 return $wire; 68 82 } 69 83 84 /** 85 * Calculates a user's plus expirey date - factoring in upgrades to existing subscriptions. 86 * 87 * @param [String] $timespan - first param of strtotime(). 88 * @param [Integer] $wireTimestamp - the unix timestamp on the wire transaction. 89 * @param [Integer] $previousTimestamp - the users previous subscription unix timestamp. 90 * @return [Integer] the new unix expiry date. 91 */ 92 public function calculatePlusExpires($timespan, $wireTimestamp, $previousTimestamp = null) 93 { 94 if ($previousTimestamp === 9999999999) { - Maintainer
While this won't be a problem to 2286, let's make this a constant called LIFETIME
156 159 157 160 return $this; 158 161 } 162 163 public function setTier($tier = '') 164 { - Maintainer
Let's use some of the php doc decorators and set the default to one of the exposed constants