Commit 8ec1fcb2 authored by Ben Hayward's avatar Ben Hayward

Updated to add spec tests

parent 51618b7d
Pipeline #72115278 canceled with stages
in 1 minute and 4 seconds
......@@ -23,16 +23,13 @@ class Plus
}
/**
* On Wire
* @param Wire $wire
* @param string $receiver_address
* @return Wire $wire
* To be called on an incoming wire.
* @param Wire $wire - the wire object.
* @param string $receiver_address - the recieving address.
* @return Wire $wire - the wire object.
*/
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']) {
return $wire; //not sent to plus
}
......@@ -62,12 +59,45 @@ class Plus
if (!$user) {
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();
//$wire->setSender($user);
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);
}
}
......@@ -315,8 +315,9 @@ class Manager
'description' => 'Wire',
'user' => $wire->getReceiver(),
]);*/
$this->plusDelegate
->onWire($wire, $data['receiver_address'], $tier);
->onWire($wire, $data['receiver_address'], $this->tier);
$this->sendNotification($wire);
......
......@@ -50,6 +50,10 @@ class PlusSpec extends ObjectBehavior
$sender->setPlusExpires(Argument::any())
->shouldBeCalled();
$sender->get('plus_expires')
->willReturn(222);
$sender->save()
->shouldBeCalled();
......@@ -124,6 +128,10 @@ class PlusSpec extends ObjectBehavior
$sender->setPlusExpires(Argument::any())
->shouldBeCalled();
$sender->get('plus_expires')
->willReturn(222);
$sender->save()
->shouldBeCalled();
......@@ -168,4 +176,4 @@ class PlusSpec extends ObjectBehavior
$wire->getSender()->isPlus()->shouldBe(false);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment