Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
174
Issues
174
List
Boards
Labels
Service Desk
Milestones
Merge Requests
43
Merge Requests
43
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
8ec1fcb2
Commit
8ec1fcb2
authored
17 minutes ago
by
Ben Hayward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated to add spec tests
parent
51618b7d
feat/plus-tiers-578
1 merge request
!279
WIP: [Sprint/JollyJellyfish](feat): Added plus tiers to endpoint and passed through #578
Pipeline
#72115278
canceled with stages
in 1 minute and 4 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
10 deletions
+49
-10
Plus.php
Core/Wire/Delegates/Plus.php
+38
-8
Manager.php
Core/Wire/Manager.php
+2
-1
PlusSpec.php
Spec/Core/Wire/Delegates/PlusSpec.php
+9
-1
No files found.
Core/Wire/Delegates/Plus.php
View file @
8ec1fcb2
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Manager.php
View file @
8ec1fcb2
...
...
@@ -315,8 +315,9 @@ class Manager
'description' => 'Wire',
'user' => $wire->getReceiver(),
]);*/
$this
->
plusDelegate
->
onWire
(
$wire
,
$data
[
'receiver_address'
],
$tier
);
->
onWire
(
$wire
,
$data
[
'receiver_address'
],
$t
his
->
t
ier
);
$this
->
sendNotification
(
$wire
);
...
...
This diff is collapsed.
Click to expand it.
Spec/Core/Wire/Delegates/PlusSpec.php
View file @
8ec1fcb2
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment