Commit 56d97028 authored by Ben Hayward's avatar Ben Hayward

Updated for feedback

1 merge request!279[Sprint/JollyJellyfish](feat): Added plus tiers to endpoint and passed through #578
Pipeline #72560318 failed with stages
in 4 minutes and 23 seconds
......@@ -70,7 +70,7 @@ class wire implements Interfaces\Api
$manager = Core\Di\Di::_()->get('Wire\Manager');
$tier = $_POST['tier'] ?? '';
$tier = $_POST['tier'] ?? MONTHLY;
$payload = (array) $_POST['payload'] ?? [];
try {
......
......@@ -6,9 +6,12 @@ namespace Minds\Core\Wire\Delegates;
use Minds\Core\Config;
use Minds\Core\Di\Di;
use Minds\Core\Wire\Manager;
class Plus
{
{
/* @var const LIFETIME_TIMESTAMP */
const LIFETIME_TIMESTAMP = 9999999999;
/** @var Config $config */
private $config;
......@@ -62,11 +65,11 @@ class Plus
// check the users tier if passed in. If not, it's a standard monthly subscription.
switch ($tier) {
case 'lifetime':
$user->setPlusExpires(9999999999); //life
case Manager::LIFETIME:
$user->setPlusExpires(static::LIFETIME_TIMESTAMP); //life
break;
case 'yearly':
case Manager::YEARLY:
$user->setPlusExpires($this->calculatePlusExpires('+1 year', $wire->getTimestamp(), $user->plus_expires));
break;
......@@ -91,7 +94,7 @@ class Plus
*/
public function calculatePlusExpires($timespan, $wireTimestamp, $previousTimestamp = null)
{
if ($previousTimestamp === 9999999999) {
if ($previousTimestamp === static::LIFETIME_TIMESTAMP) {
throw new \Exception('Already existing lifetime subscription');
}
......
......@@ -17,6 +17,7 @@ use Minds\Core\Wire\Subscriptions\Manager as SubscriptionsManager;
use Minds\Common\Urn;
use Minds\Entities;
use Minds\Entities\User;
use Twilio\Rest\Api\V2010\Account\Usage\Record\YearlyInstance;
class Manager
{
......@@ -80,6 +81,15 @@ class Manager
/** @var Core\Blockchain\Wallets\OffChain\Transactions */
protected $offchainTxs;
/** @var const MONTHLY **/
const MONTHLY = 'month';
/** @var const YEARLY **/
const YEARLY = 'year';
/** @var const LIFETIME **/
const LIFETIME = 'lifetime';
public function __construct(
$cache = null,
$repository = null,
......@@ -160,7 +170,13 @@ class Manager
return $this;
}
public function setTier($tier = '')
/**
* Sets the tier of the wire e.g. 'monthly', 'yearly', 'lifetime
*
* @param string $tier - the tier
* @return $this
*/
public function setTier($tier = MONTHLY)
{
$this->tier = $tier;
......
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