2018-06-07 10:56:13 +00:00
|
|
|
<?php
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
use \Slim\Http\Request as Request;
|
|
|
|
use \Slim\Http\Response as Response;
|
|
|
|
|
2018-06-07 10:56:13 +00:00
|
|
|
// The hookmanager is the web-exposed class that allows you to manage a user within the billing system.
|
|
|
|
// This system takes care of CRUD operations on customers. It doesn't keep track of order but it does suspend
|
|
|
|
// you if you don't pay.
|
|
|
|
|
|
|
|
class Hookmanager
|
|
|
|
{
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
private $Customer;
|
|
|
|
|
|
|
|
private $Renderview;
|
|
|
|
|
|
|
|
private $APITools;
|
|
|
|
|
|
|
|
private $Mailer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
$this->Customer = new Customer();
|
|
|
|
$this->Renderview = new EmailRenderer();
|
|
|
|
$this->APITools = new ApplicationAPI();
|
|
|
|
|
|
|
|
// Create mailer when needed
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return POST variable list in a structured array, DRY
|
|
|
|
private function getStructuredVariableList(Request $request)
|
|
|
|
{
|
|
|
|
$PDATA = $request->getParsedBody();
|
|
|
|
$dArr = [];
|
|
|
|
|
|
|
|
foreach($PDATA as $key => $param)
|
|
|
|
{
|
|
|
|
$dArr[$key => $param]; // Turn parsed body into an array.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function EventSubscriptionCreated(Request $request, Response $response)
|
|
|
|
{
|
|
|
|
// Create customer with data from Paddle
|
|
|
|
// Send email with customer information
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-07 10:56:13 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
public function EventSubscriptionUpdated(Request $request, Response $response)
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
// Update user information if necessary
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
public function EventSubscriptionCancelled(Request $request, Response $response)
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// Suspend user's domain name as stated on DB
|
|
|
|
// Delete after 30 days
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
public function EventSubscriptionPaymentSuccess(Request $request, Response $response)
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// Renew user's subscription within billing system
|
|
|
|
// Install hosting account if this is the user's first time and send out instructions email
|
|
|
|
|
|
|
|
}
|
|
|
|
// TODO: Lenient business logic
|
2018-06-07 14:14:25 +00:00
|
|
|
public function EventSubscriptionPaymentFailed(Request $request, Response $response)
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// Add payment strike to user account
|
|
|
|
// After three strikes, warn user that the system has waived further attempts. Suspend their account
|
|
|
|
// Give user an ultimatum: Pay or remain suspended
|
|
|
|
// If user fails to pay during the next 7 days, permanently suspend their account (Reject further payments. Remove user from paddle first)
|
|
|
|
// If payment is successful afterwards, remove all payment strikes (Success logic should execute automatically)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:14:25 +00:00
|
|
|
public function EventSubscriptionPaymentRefunded(Request $request, Response $response)
|
2018-06-07 10:56:13 +00:00
|
|
|
{
|
|
|
|
// Ban customer from billing system
|
|
|
|
// Delete all customer data
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|