Major changes - Ready app for initial testings
This commit is contained in:
parent
7403097008
commit
29735c60bb
|
@ -1,6 +1,25 @@
|
|||
<?php
|
||||
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
|
||||
|
||||
$App = new \Slim\App();
|
||||
$App = new \Slim\App([
|
||||
"settings" =>
|
||||
[
|
||||
"displayErrorDetails" => true
|
||||
]
|
||||
]);
|
||||
|
||||
$App->post("/api/paddle/{authkey}/hook");
|
||||
|
||||
|
||||
$App->post
|
||||
(
|
||||
"/api/paddle/{authkey}/detectIntent",
|
||||
Hookmanager::class, ':detectPayloadIntent'
|
||||
);
|
||||
|
||||
$App->post
|
||||
(
|
||||
"/api/paddle/{authkey}/hook",
|
||||
Hookmanager::class, ':EventSubscriptionCreatead'
|
||||
|
||||
);
|
|
@ -19,6 +19,20 @@ class Hookmanager
|
|||
private $Mailer;
|
||||
|
||||
|
||||
// Can be overloaded by child classes in order to add new features.W
|
||||
protected $alertTypes =
|
||||
[
|
||||
"subscription_created",
|
||||
"subscription_updated",
|
||||
"subscription_cancelled",
|
||||
"subscription_payment_succeeded",
|
||||
"subscription_payment_failed",
|
||||
"subscription_payment_refunded",
|
||||
"payment_refunded",
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -48,13 +62,50 @@ class Hookmanager
|
|||
}
|
||||
|
||||
|
||||
public function EventSubscriptionCreated(Request $request, Response $response)
|
||||
private function keyValidate($keyFromURI)
|
||||
{
|
||||
// Create customer with data from Paddle
|
||||
// Send email with customer information
|
||||
// FIXME: Theoretically, this method does not work.
|
||||
// TODO: Devise a new way to validate keys without user ID
|
||||
if($this->APITools->keysMatch($keyFromURI))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function detectPayloadIntent(Request $request, Response $response, $args)
|
||||
{
|
||||
if ($this->keyValidate($keyFromURI))
|
||||
{
|
||||
|
||||
$data = $this->getStructuredVariableList($Request);
|
||||
|
||||
foreach ($this->alertTypes as $types => $value)
|
||||
{
|
||||
if ($types == $data['alert_name'])
|
||||
{
|
||||
$sVal = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Redirect request to approriate route.
|
||||
// Use translator helper method to translate developer name to readable route name for redirect
|
||||
|
||||
|
||||
}
|
||||
|
||||
throw new LogicException("Illegal API key");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function EventSubscriptionCreated(Request $request, Response $response, $args)
|
||||
{
|
||||
|
||||
return $response->write($this->getStructuredVariableList($Request))->withStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue