spacejewel-ipn-communication/source/dbtools/Customer.php

104 lines
2.9 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 passwords
public function newCustomer($Domain, $Name, $Email, $CheckoutID, $SubscriptionStatus, $Package, $PaddleSubscriptionID, $SystemStatus, $GDPRConsent, $hasVirtualServer = false, $attachedVServerID = null)
{
$passwordFactory = new RandomLib\Factory();
$pGen = $passwordFactory->getLowStrengthGenerator();
$PAC_Ptext = $pGen->generate(4);
$PAC = password_hash($PAC_Ptext, PASSWORD_BCRYPT);
$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' => $PAC
]);
$PanelPassword = $pGen->generate(16);
$this->Virtualmin->CreateVirtualServer($Domain, $PanelPassword);
return
[
"PanelPassword" => $PanelPassword,
"PersonalAuthenticationCode" => $PAC_Ptext
];
}
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'];
}
}