Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
232
Issues
232
List
Boards
Labels
Service Desk
Milestones
Merge Requests
40
Merge Requests
40
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
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
e61f43de
Commit
e61f43de
authored
4 hours ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): introduce pro billing for wire
parent
e9072cc6
epic/upgrades-page
1 merge request
!361
WIP: Marketing pages and Wire payments
Pipeline
#88940332
pending with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
175 additions
and
7 deletions
+175
-7
Core/Wire/Delegates/UpgradesDelegate.php
Core/Wire/Delegates/UpgradesDelegate.php
+163
-0
Core/Wire/Manager.php
Core/Wire/Manager.php
+12
-7
No files found.
Core/Wire/Delegates/UpgradesDelegate.php
0 → 100644
View file @
e61f43de
<?php
/**
* Upgrades Delegate
*/
namespace
Minds\Core\Wire\Delegates
;
use
Minds\Core\Config
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Wire\Wire
;
use
Minds\Core\Pro\Manager
as
ProManager
;
class
UpgradesDelegate
{
/** @var Config */
private
$config
;
/** @var EntitiesBuilder */
private
$entitiesBuilder
;
/** @var ProManager */
private
$proManager
;
public
function
__construct
(
$config
=
null
,
$entitiesBuilder
=
null
,
$proManager
=
null
)
{
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
$this
->
proManager
=
$proManager
??
Di
::
_
()
->
get
(
'Pro\Manager'
);
}
/**
* On Wire
* @param Wire $wire
* @param string $receiver_address
* @return Wire $wire
*/
public
function
onWire
(
$wire
,
$receiver_address
)
:
Wire
{
switch
(
$wire
->
getReceiver
()
->
guid
)
{
case
$this
->
config
->
get
(
'blockchain'
)[
'contracts'
][
'wire'
][
'plus_guid'
]
:
return
$this
->
onPlusUpgrade
(
$wire
,
$receiver_address
);
break
;
case
$this
->
config
->
get
(
'pro'
)[
'handler'
]
:
return
$this
->
onProUpgrade
(
$wire
,
$receiver_address
);
break
;
}
return
$wire
;
// Not expected
}
private
function
onPlusUpgrade
(
$wire
,
$receiver_address
)
:
Wire
{
if
(
!
(
$receiver_address
==
'offchain'
||
$receiver_address
==
$this
->
config
->
get
(
'blockchain'
)[
'contracts'
][
'wire'
][
'plus_address'
]
)
)
{
return
$wire
;
//not offchain or potential onchain fraud
}
// 20 tokens
if
(
$wire
->
getAmount
()
!=
"20000000000000000000"
)
{
return
$wire
;
//incorrect wire amount sent
}
//set the plus period for this user
$user
=
$wire
->
getSender
();
// rebuild the user as we can't trust upstream
$user
=
$this
->
entitiesBuilder
->
single
(
$user
->
getGuid
(),
[
'cache'
=>
false
,
]);
if
(
!
$user
)
{
return
$wire
;
}
$days
=
30
;
$monthly
=
$this
->
config
->
get
(
'upgrades'
)[
'plus'
][
'monthly'
];
$yearly
=
$this
->
config
->
get
(
'upgrades'
)[
'plus'
][
'yearly'
];
switch
(
$wire
->
getMethod
())
{
case
'tokens'
:
if
(
$monthly
[
'tokens'
]
==
$wire
->
getAmount
())
{
$days
=
30
;
}
elseif
(
$yearly
[
'tokens'
]
==
$wire
->
getAmount
())
{
$days
=
365
;
}
else
{
return
$wire
;
}
break
;
case
'usd'
:
if
(
$monthly
[
'usd'
]
==
$wire
->
getAmount
()
/
100
)
{
$days
=
30
;
}
elseif
(
$yearly
[
'usd'
]
==
$wire
->
getAmount
()
/
100
)
{
$days
=
365
;
}
else
{
return
$wire
;
}
break
;
default
:
return
$wire
;
}
$expires
=
strtotime
(
"+
{
$days
}
days"
,
$wire
->
getTimestamp
());
$user
->
setPlusExpires
(
$expires
);
$user
->
save
();
//$wire->setSender($user);
return
$wire
;
}
private
function
onProUpgrade
(
$wire
,
$receiver_address
)
:
Wire
{
//set the plus period for this user
$user
=
$wire
->
getSender
();
// rebuild the user as we can't trust upstream
$user
=
$this
->
entitiesBuilder
->
single
(
$user
->
getGuid
(),
[
'cache'
=>
false
,
]);
if
(
!
$user
)
{
return
$wire
;
}
$days
=
30
;
$monthly
=
$this
->
config
->
get
(
'upgrades'
)[
'pro'
][
'monthly'
];
$yearly
=
$this
->
config
->
get
(
'upgrades'
)[
'pro'
][
'yearly'
];
error_log
(
$wire
->
getMethod
());
switch
(
$wire
->
getMethod
())
{
case
'tokens'
:
error_log
(
$wire
->
getAmount
());
if
(
$monthly
[
'tokens'
]
==
$wire
->
getAmount
()
/
(
10
**
18
))
{
$days
=
30
;
}
elseif
(
$yearly
[
'tokens'
]
==
$wire
->
getAmount
()
/
(
10
**
18
))
{
$days
=
365
;
}
else
{
return
$wire
;
}
break
;
case
'usd'
:
if
(
$monthly
[
'usd'
]
==
$wire
->
getAmount
()
/
100
)
{
$days
=
30
;
}
elseif
(
$yearly
[
'usd'
]
==
$wire
->
getAmount
()
/
100
)
{
$days
=
365
;
}
else
{
return
$wire
;
}
break
;
default
:
return
$wire
;
}
$expires
=
strtotime
(
"+
{
$days
}
days"
,
$wire
->
getTimestamp
());
$this
->
proManager
->
setUser
(
$user
)
->
enable
(
$expires
);
return
$wire
;
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Manager.php
View file @
e61f43de
...
...
@@ -61,8 +61,8 @@ class Manager
/** @var Core\Blockchain\Wallets\OffChain\Cap $cap */
protected
$cap
;
/** @var Delegates\
Plus $plu
sDelegate */
protected
$
plu
sDelegate
;
/** @var Delegates\
Upgrade
sDelegate */
protected
$
upgrade
sDelegate
;
/** @var Delegates\RecurringDelegate $recurringDelegate */
protected
$recurringDelegate
;
...
...
@@ -87,7 +87,7 @@ class Manager
$client
=
null
,
$token
=
null
,
$cap
=
null
,
$
plu
sDelegate
=
null
,
$
upgrade
sDelegate
=
null
,
$recurringDelegate
=
null
,
$notificationDelegate
=
null
,
$cacheDelegate
=
null
,
...
...
@@ -101,7 +101,8 @@ class Manager
$this
->
client
=
$client
?:
Di
::
_
()
->
get
(
'Blockchain\Services\Ethereum'
);
$this
->
token
=
$token
?:
Di
::
_
()
->
get
(
'Blockchain\Token'
);
$this
->
cap
=
$cap
?:
Di
::
_
()
->
get
(
'Blockchain\Wallets\OffChain\Cap'
);
$this
->
plusDelegate
=
$plusDelegate
?:
new
Delegates\Plus
();
$this
->
upgradesDelegate
=
$upgradesDelegate
??
new
Delegates\UpgradesDelegate
();
;
$this
->
recurringDelegate
=
$recurringDelegate
?:
new
Delegates\RecurringDelegate
();
$this
->
notificationDelegate
=
$notificationDelegate
?:
new
Delegates\NotificationDelegate
();
$this
->
cacheDelegate
=
$cacheDelegate
?:
new
Delegates\CacheDelegate
();
...
...
@@ -248,8 +249,8 @@ class Manager
$wire
->
setAddress
(
'offchain'
);
// Notify plus
$this
->
plu
sDelegate
// Notify plus
/pro
$this
->
upgrade
sDelegate
->
onWire
(
$wire
,
'offchain'
);
// Send notification
...
...
@@ -287,6 +288,10 @@ class Manager
// Save the wire to the Repository
$this
->
repository
->
add
(
$wire
);
// Notify plus/pro
$this
->
upgradesDelegate
->
onWire
(
$wire
,
'usd'
);
// Send notification
$this
->
notificationDelegate
->
onAdd
(
$wire
);
...
...
@@ -330,7 +335,7 @@ class Manager
->
setCompleted
(
true
);
$this
->
txRepo
->
add
(
$transaction
);
$this
->
plu
sDelegate
$this
->
upgrade
sDelegate
->
onWire
(
$wire
,
$data
[
'receiver_address'
]);
$this
->
notificationDelegate
->
onAdd
(
$wire
);
...
...
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