You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
4.3 KiB
108 lines
4.3 KiB
<?php
|
|
namespace app\core\auth;
|
|
|
|
|
|
class Subscription {
|
|
|
|
public function __construct() {
|
|
}
|
|
|
|
public function formatSubscriberData(array $userDetails, array $userPreInfo, array $cookieData, int $subscriber) {
|
|
$subscriber = array(
|
|
'subscriber' => $subscriber,
|
|
'address' => $userDetails['address'],
|
|
'email_address' => $userDetails['email_address'],
|
|
'civility' => $userDetails['civil_status'],
|
|
'birthday' => $userDetails['birthday'],
|
|
'postal_code' => $userDetails['postal_code'],
|
|
'country' => $userDetails['country'],
|
|
'city' => $userDetails['city'],
|
|
'profession' => $userDetails['profession'],
|
|
'phone' => $userDetails['phone_number'],
|
|
|
|
'sponsorship' => $userDetails['sponsorship'],
|
|
'company' => $userDetails['company'],
|
|
'news_subscription' => (int)$userDetails['news_subscription']
|
|
);
|
|
$preInfo = $this->formatPreInfoData($userPreInfo, $cookieData);
|
|
if(!is_null($preInfo)) {
|
|
$subscriber = array_merge($subscriber, $preInfo);
|
|
}
|
|
return array_filter($subscriber);
|
|
}
|
|
|
|
private function formatPreInfoData(array $userPreInfo, array $cookieData) {
|
|
switch($cookieData['name']) {
|
|
case 'Student':
|
|
return array(
|
|
'id_no' => $userPreInfo['student_id'],
|
|
'id_file' => array_key_exists('student_file', $userPreInfo) ? $userPreInfo['student_file'] : ''
|
|
);
|
|
case 'Shareholder':
|
|
return array(
|
|
'id_no' => $userPreInfo['shareholder_id']
|
|
);
|
|
case 'Sponsored':
|
|
return array(
|
|
'sponsor_name' => $userPreInfo['sponsored_name'],
|
|
'sponsor_email' => $userPreInfo['sponsored_email'],
|
|
'sponsor_company' => $userPreInfo['sponsored_company'],
|
|
'isSponsor' => 1
|
|
);
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function formatUserData(array $userDetails, array $cookieData) {
|
|
return array(
|
|
'first_name' => $userDetails['firstname'],
|
|
'last_name' => $userDetails['lastname'],
|
|
'email_address' => $userDetails['email_address'],
|
|
'password' => hash_password($userDetails['password']),
|
|
'role_id' => $cookieData['role_id'],
|
|
'status' => 1
|
|
);
|
|
|
|
}
|
|
|
|
public function formatSubscriptionData(array $userDetails, array $userPreInfo, array $cookieData, int $userId, array $receipt = null) {
|
|
$subscription = array(
|
|
'user_id' => $userId,
|
|
'subscriptionId' => $cookieData['price_id'],
|
|
'payment_mode' => $userDetails['mode_of_payment'],
|
|
'amount' => $cookieData['price'],
|
|
'status' => $userDetails['mode_of_payment'] == 'card' ? 'ACTIVE' : 'UNVERIFIED'
|
|
);
|
|
$payment = $this->formatPaymentData($userDetails['mode_of_payment'], $cookieData, $receipt);
|
|
return array_filter(array_merge($subscription, $payment));
|
|
}
|
|
|
|
private function formatPaymentData(string $paymentMode, array $cookieData, array $receipt = null) {
|
|
$payment = array();
|
|
if($paymentMode == 'card' && !is_null($receipt)) {
|
|
$payment = array(
|
|
'transactionDateTime' => date("Y-m-d", strtotime($receipt['transactionDateTime'])),
|
|
'transactionReference' => $receipt['transactionReference'],
|
|
'expirationDate' => date("Y-m-d", strtotime(date("Y-m-d", strtotime($receipt['transactionDateTime'])) . " + 1 year")),
|
|
'PCNr' => $receipt['PCNr'],
|
|
'payId' => $receipt['payId'],
|
|
'CCBrand' => $receipt['CCBrand']
|
|
);
|
|
}
|
|
return $payment;
|
|
}
|
|
|
|
public function filterPaymentReceipt($receipt) {
|
|
$props = ['transactionDateTime','transactionReference','authorisationId','customerIpAddress','responseCode'];
|
|
$receiptData = explode("|", $receipt);
|
|
$paymentReceipt = [];
|
|
foreach($receiptData as $item) {
|
|
$arrayItem = explode("=", $item);
|
|
if(in_array($arrayItem[0],$props)) {
|
|
$paymentReceipt[$arrayItem[0]] = $arrayItem[1];
|
|
}
|
|
}
|
|
return $paymentReceipt;
|
|
}
|
|
}
|