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
14fab30c
Commit
14fab30c
authored
18 minutes ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): ability to subscribe to pro package
parent
aa593067
epic/pro-affiliate-launch
1 merge request
!368
WIP: Epic/pro affiliate launch
Pipeline
#88940523
pending with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
7 deletions
+206
-7
Controllers/api/v1/minds/config.php
Controllers/api/v1/minds/config.php
+5
-0
Core/Wire/Delegates/UpgradesDelegate.php
Core/Wire/Delegates/UpgradesDelegate.php
+163
-0
Core/Wire/Manager.php
Core/Wire/Manager.php
+12
-7
settings.example.php
settings.example.php
+26
-0
No files found.
Controllers/api/v1/minds/config.php
View file @
14fab30c
...
...
@@ -39,6 +39,11 @@ class config implements Interfaces\Api, Interfaces\ApiIgnorePam
"plus"
=>
Minds\Core\Config
::
_
()
->
get
(
'plus'
),
"report_reasons"
=>
Minds\Core\Config
::
_
()
->
get
(
'report_reasons'
),
"last_tos_update"
=>
(
Minds\Core\Config
::
_
()
->
get
(
'last_tos_update'
)
?:
time
()),
'handlers'
=>
[
'plus'
=>
Minds\Core\Di\Di
::
_
()
->
get
(
'Config'
)
->
get
(
'plus'
)[
'handler'
]
??
null
,
'pro'
=>
Minds\Core\Di\Di
::
_
()
->
get
(
'Config'
)
->
get
(
'pro'
)[
'handler'
]
??
null
,
],
'upgrades'
=>
Minds\Core\Di\Di
::
_
()
->
get
(
'Config'
)
->
get
(
'upgrades'
),
];
return
Factory
::
response
(
$minds
);
...
...
This diff is collapsed.
Click to expand it.
Core/Wire/Delegates/UpgradesDelegate.php
0 → 100644
View file @
14fab30c
<?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 @
14fab30c
...
...
@@ -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.
settings.example.php
View file @
14fab30c
...
...
@@ -380,6 +380,7 @@ $CONFIG->set('blockchain_override', [
]);
$CONFIG
->
set
(
'plus'
,
[
'handler'
=>
''
,
'tokens'
=>
[
'month'
=>
5
,
'year'
=>
50
...
...
@@ -575,7 +576,32 @@ $CONFIG->set('gitlab', [
]);
$CONFIG
->
set
(
'pro'
,
[
'handler'
=>
''
,
'root_domains'
=>
[
'minds.com'
,
'www.minds.com'
,
'localhost'
],
'subdomain_suffix'
=>
'minds.com'
,
'dynamodb_table_name'
=>
'traefik'
,
]);
$CONFIG
->
set
(
'upgrades'
,
[
'pro'
=>
[
'monthly'
=>
[
'tokens'
=>
240
,
'usd'
=>
60
,
],
'yearly'
=>
[
'tokens'
=>
2400
,
'usd'
=>
600
,
]
],
'plus'
=>
[
'monthly'
=>
[
'tokens'
=>
28
,
'usd'
=>
7
,
],
'yearly'
=>
[
'tokens'
=>
240
,
'usd'
=>
60
,
]
],
]);
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