Loading Core/Wire/Delegates/Plus.php +38 −8 Original line number Original line Diff line number Diff line Loading @@ -23,16 +23,13 @@ class Plus } } /** /** * On Wire * To be called on an incoming wire. * @param Wire $wire * @param Wire $wire - the wire object. * @param string $receiver_address * @param string $receiver_address - the recieving address. * @return Wire $wire * @return Wire $wire - the wire object. */ */ public function onWire($wire, $receiver_address, $tier = null) public function onWire($wire, $receiver_address, $tier = null) { { error_log("IN THE DELEGATE^^^^^^^"); error_log(var_export($tier, true)); die(); if ($wire->getReceiver()->guid != $this->config->get('blockchain')['contracts']['wire']['plus_guid']) { if ($wire->getReceiver()->guid != $this->config->get('blockchain')['contracts']['wire']['plus_guid']) { return $wire; //not sent to plus return $wire; //not sent to plus } } Loading Loading @@ -62,12 +59,45 @@ class Plus if (!$user) { if (!$user) { return $wire; return $wire; } } // error_log(var_export($wire->getTimestamp(), true)); // check the users tier if passed in. If not, it's a standard monthly subscription. switch ($tier) { case 'lifetime': $user->setPlusExpires(9999999999); //life break; case 'yearly': $user->setPlusExpires($this->calculatePlusExpires('+1 year', $wire->getTimestamp(), $user->plus_expires)); break; default: $user->setPlusExpires($this->calculatePlusExpires('+30 days', $wire->getTimestamp(), $user->plus_expires)); break; } $user->setPlusExpires(strtotime('+30 days', $wire->getTimestamp())); $user->save(); $user->save(); //$wire->setSender($user); //$wire->setSender($user); return $wire; return $wire; } } /** * Calculates a user's plus expirey date - factoring in upgrades to existing subscriptions. * * @param [String] $timespan - first param of strtotime(). * @param [Integer] $wireTimestamp - the unix timestamp on the wire transaction. * @param [Integer] $previousTimestamp - the users previous subscription unix timestamp. * @return [Integer] the new unix expiry date. */ public function calculatePlusExpires($timespan, $wireTimestamp, $previousTimestamp = null) { if ($previousTimestamp === 9999999999) { throw new \Exception('Already existing lifetime subscription'); } if($previousTimestamp === null || $previousTimestamp < time()) { return strtotime($timespan, $wireTimestamp); } return strtotime($timespan, $previousTimestamp); } } } Core/Wire/Manager.php +2 −1 Original line number Original line Diff line number Diff line Loading @@ -315,8 +315,9 @@ class Manager 'description' => 'Wire', 'description' => 'Wire', 'user' => $wire->getReceiver(), 'user' => $wire->getReceiver(), ]);*/ ]);*/ $this->plusDelegate $this->plusDelegate ->onWire($wire, $data['receiver_address'], $tier); ->onWire($wire, $data['receiver_address'], $this->tier); $this->sendNotification($wire); $this->sendNotification($wire); Loading Spec/Core/Wire/Delegates/PlusSpec.php +9 −1 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,10 @@ class PlusSpec extends ObjectBehavior $sender->setPlusExpires(Argument::any()) $sender->setPlusExpires(Argument::any()) ->shouldBeCalled(); ->shouldBeCalled(); $sender->get('plus_expires') ->willReturn(222); $sender->save() $sender->save() ->shouldBeCalled(); ->shouldBeCalled(); Loading Loading @@ -124,6 +128,10 @@ class PlusSpec extends ObjectBehavior $sender->setPlusExpires(Argument::any()) $sender->setPlusExpires(Argument::any()) ->shouldBeCalled(); ->shouldBeCalled(); $sender->get('plus_expires') ->willReturn(222); $sender->save() $sender->save() ->shouldBeCalled(); ->shouldBeCalled(); Loading Loading
Core/Wire/Delegates/Plus.php +38 −8 Original line number Original line Diff line number Diff line Loading @@ -23,16 +23,13 @@ class Plus } } /** /** * On Wire * To be called on an incoming wire. * @param Wire $wire * @param Wire $wire - the wire object. * @param string $receiver_address * @param string $receiver_address - the recieving address. * @return Wire $wire * @return Wire $wire - the wire object. */ */ public function onWire($wire, $receiver_address, $tier = null) public function onWire($wire, $receiver_address, $tier = null) { { error_log("IN THE DELEGATE^^^^^^^"); error_log(var_export($tier, true)); die(); if ($wire->getReceiver()->guid != $this->config->get('blockchain')['contracts']['wire']['plus_guid']) { if ($wire->getReceiver()->guid != $this->config->get('blockchain')['contracts']['wire']['plus_guid']) { return $wire; //not sent to plus return $wire; //not sent to plus } } Loading Loading @@ -62,12 +59,45 @@ class Plus if (!$user) { if (!$user) { return $wire; return $wire; } } // error_log(var_export($wire->getTimestamp(), true)); // check the users tier if passed in. If not, it's a standard monthly subscription. switch ($tier) { case 'lifetime': $user->setPlusExpires(9999999999); //life break; case 'yearly': $user->setPlusExpires($this->calculatePlusExpires('+1 year', $wire->getTimestamp(), $user->plus_expires)); break; default: $user->setPlusExpires($this->calculatePlusExpires('+30 days', $wire->getTimestamp(), $user->plus_expires)); break; } $user->setPlusExpires(strtotime('+30 days', $wire->getTimestamp())); $user->save(); $user->save(); //$wire->setSender($user); //$wire->setSender($user); return $wire; return $wire; } } /** * Calculates a user's plus expirey date - factoring in upgrades to existing subscriptions. * * @param [String] $timespan - first param of strtotime(). * @param [Integer] $wireTimestamp - the unix timestamp on the wire transaction. * @param [Integer] $previousTimestamp - the users previous subscription unix timestamp. * @return [Integer] the new unix expiry date. */ public function calculatePlusExpires($timespan, $wireTimestamp, $previousTimestamp = null) { if ($previousTimestamp === 9999999999) { throw new \Exception('Already existing lifetime subscription'); } if($previousTimestamp === null || $previousTimestamp < time()) { return strtotime($timespan, $wireTimestamp); } return strtotime($timespan, $previousTimestamp); } } }
Core/Wire/Manager.php +2 −1 Original line number Original line Diff line number Diff line Loading @@ -315,8 +315,9 @@ class Manager 'description' => 'Wire', 'description' => 'Wire', 'user' => $wire->getReceiver(), 'user' => $wire->getReceiver(), ]);*/ ]);*/ $this->plusDelegate $this->plusDelegate ->onWire($wire, $data['receiver_address'], $tier); ->onWire($wire, $data['receiver_address'], $this->tier); $this->sendNotification($wire); $this->sendNotification($wire); Loading
Spec/Core/Wire/Delegates/PlusSpec.php +9 −1 Original line number Original line Diff line number Diff line Loading @@ -50,6 +50,10 @@ class PlusSpec extends ObjectBehavior $sender->setPlusExpires(Argument::any()) $sender->setPlusExpires(Argument::any()) ->shouldBeCalled(); ->shouldBeCalled(); $sender->get('plus_expires') ->willReturn(222); $sender->save() $sender->save() ->shouldBeCalled(); ->shouldBeCalled(); Loading Loading @@ -124,6 +128,10 @@ class PlusSpec extends ObjectBehavior $sender->setPlusExpires(Argument::any()) $sender->setPlusExpires(Argument::any()) ->shouldBeCalled(); ->shouldBeCalled(); $sender->get('plus_expires') ->willReturn(222); $sender->save() $sender->save() ->shouldBeCalled(); ->shouldBeCalled(); Loading