spacejewel-ipn-communication/source/dbtools/Customer.php
2018-06-07 10:56:13 +00:00

97 lines
2.7 KiB
PHP

<?php
class Customer extends Application
{
private $Virtualmin;
public function __construct()
{
parent::_construct();
$this->Virtualmin = new VirtualminHandler();
}
// By default, this function sets the customer as inactive (e.g. newly created, awating payment)
// Returns the customer's hosting password
public function newCustomer($Domain, $Name, $Email, $CheckoutID, $SubscriptionStatus, $Package, $PaddleSubscriptionID, $SystemStatus, $GDPRConsent, $hasVirtualServer = false, $attachedVServerID = null)
{
$passwordFactory = new RandomLib\Factory();
$pGen = $passwordFactory->getLowStrengthGenerator();
$this->db->insert('Customers', [
'CustomerName' => $Name,
'CustomerEmail' => $Email,
'CustomerCheckoutID' => $CheckoutID,
'Package' => $Package,
'SubscriptionStatus' => $SubscriptionStatus,
'PaddleSubscriptionID' => $PaddleSubscriptionID,
'SystemStatus' => $SystemStatus,
'GDPRConsent' => $GDPRConsent,
'hasVirtualServer' => $hasVirtualServer,
'attachedVServerID' => $attachedVServerID,
'PAC' => $pGen->generate(4)
]);
$cPassword = $pGen->generate(16);
$this->Virtualmin->CreateVirtualServer($Domain, $cPassword);
return $cPassword;
}
public function updateCustomerInformation($CustomerID, $UpdateField, $NewValue)
{
$db->update('Customers', [
$UpdateField => $NewValue
], [
'ID' => $CustomerID
]);
}
public function eraseCustomer($CustomerID)
{
// Virtualmin: Delete virutal server attached to customer
$db->delete('Customers', [
'ID' => $CustomerID
]);
}
public function listCustomersByEmail($CEmail)
{
$Customer = $this->db->row(
"SELECT * FROM Customers WHERE CustomerEmail = ?",
$CEmail
);
return $Customer
}
public function translateEmailToID($Email)
{
$Customer = $this->listCustomersByEmail($Email);
return $Customer['ID'];
}
public function customerExists($CustomerEmail)
{
return $this->Exists("Customers", "CustomerEmail", $CustomerEmail);
}
public function getCustomerGDPRConsent($CustomerEmail)
{
$Customer = $this->listCustomersByEmail($CustomerEmail);
// assume this returns an array. do var_dump($Customer) if not
return $Customer['GDPRConsent'];
}
public function populate
}