-
Notifications
You must be signed in to change notification settings - Fork 7
/
handlePaymentTransaction.php
134 lines (116 loc) · 5.43 KB
/
handlePaymentTransaction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*==============================================================================
* (C) Copyright 2020 John J Kauflin, All rights reserved.
*----------------------------------------------------------------------------
* DESCRIPTION: Handle transactions from payment merchant - insert a payment
* transaction record, update paid flags, and send an email to
* the payer. Executed as part of the payment reconciliation
* process where you download an activity data file from Paypal,
* display transaction lines in a web page, and allow admin to
* record a payment transaction (should no longer be needed with
* the new handlePayment process, but keeping this in case it
* is ever needed)
*----------------------------------------------------------------------------
* Modification History
* 2020-09-26 JJK Initial version from handlePaymentNotification.php
* 2020-12-21 JJK Re-factored to use jjklogin package
* 2023-02-17 JJK Refactor for non-static jjklogin class and settings from DB
*============================================================================*/
require_once 'vendor/autoload.php';
// Define a super global constant for the log file (this will be in scope for all functions)
define("LOG_FILE", "./php.log");
// Figure out how many levels up to get to the "public_html" root folder
$webRootDirOffset = substr_count(strstr(dirname(__FILE__),"public_html"),DIRECTORY_SEPARATOR) + 1;
// Get settings and credentials from a file in a directory outside of public_html
// (assume a settings file in the "external_includes" folder one level up from "public_html")
$extIncludePath = dirname(__FILE__, $webRootDirOffset+1).DIRECTORY_SEPARATOR.'external_includes'.DIRECTORY_SEPARATOR;
require_once $extIncludePath.'hoadbSecrets.php';
require_once $extIncludePath.'jjkloginSettings.php';
// Common functions
require_once 'php_secure/commonUtil.php';
// Common database functions and table record classes
require_once 'php_secure/hoaDbCommon.php';
use \jkauflin\jjklogin\LoginAuth;
$adminRec = new AdminRec();
try {
$loginAuth = new LoginAuth($hostJJKLogin, $dbadminJJKLogin, $passwordJJKLogin, $dbnameJJKLogin);
$userRec = $loginAuth->getUserRec();
if ($userRec->userName == null || $userRec->userName == '') {
throw new Exception('User is NOT logged in', 500);
}
if ($userRec->userLevel < 1) {
throw new Exception('User is NOT authorized (contact Administrator)', 500);
}
$adminRec->result = "Not Valid";
$adminRec->message = "";
$adminRec->userName = $userRec->userName;
$adminRec->userLevel = $userRec->userLevel;
$adminLevel = $userRec->userLevel;
if ($adminLevel < 2) {
$adminRec->message = "You do not have permissions for this function.";
$adminRec->result = "Not Valid";
exit(json_encode($adminRec));
}
header("Content-Type: application/json; charset=UTF-8");
# Get JSON as a string
$json_str = file_get_contents('php://input');
# Decode the string to get a JSON object
$param = json_decode($json_str);
$conn = getConn($host, $dbadmin, $password, $dbname);
updAssessmentPaid(
$conn,
$param->parcelId,
$param->ownerId,
$param->fy,
$param->txn_id,
$param->payment_date,
$param->fromEmail,
$param->gross,
$param->fee);
// After the update, re-query to get the flag values
$paymentRec = new PaymentRec();
$paymentRec->TransLogged = false;
$paymentRec->MarkedPaid = false;
$paymentRec->EmailSent = false;
// Get the HOADB data by Parcel Id
$hoaRec = getHoaRec($conn,$param->parcelId,'',$param->fy);
if ($hoaRec != null) {
//error_log(date('[Y-m-d H:i:s] ') . '$hoaRec->Parcel_ID = ' . $hoaRec->Parcel_ID . ', $hoaRec->ownersList[0]->OwnerID = ' . $hoaRec->ownersList[0]->OwnerID . PHP_EOL, 3, LOG_FILE);
// Use the Owner Id of the current owner when recording the payment
$paymentRec->OwnerID = $hoaRec->ownersList[0]->OwnerID;
// Get Assessment PAID flag for the given fiscal year (FY)
$paymentRec->MarkedPaid = $hoaRec->assessmentsList[0]->Paid;
}
// Get payment record by the Transaction Id
$hoaPaymentRec = getHoaPaymentRec($conn,$param->parcelId,$param->txn_id);
if ($hoaPaymentRec != null) {
$paymentRec->TransLogged = true;
// Check the paidEmailSent flag on the transaction record to check if an email was sent to the payee member
// to confirm that the payment was recorded in the HOADB
if ($hoaPaymentRec->paidEmailSent == 'Y') {
$paymentRec->EmailSent = true;
}
}
// Add the payment display record to the list to send back for the display
$adminRec->paymentList = array();
array_push($adminRec->paymentList,$paymentRec);
// Close db connection
$conn->close();
$adminRec->message = "(Payment transactions processed successfully)";
$adminRec->result = "Valid";
echo json_encode($adminRec);
} catch(Exception $e) {
//error_log(date('[Y-m-d H:i] '). "in " . basename(__FILE__,".php") . ", Exception = " . $e->getMessage() . PHP_EOL, 3, LOG_FILE);
$adminRec->message = $e->getMessage();
$adminRec->result = "Not Valid";
/*
echo json_encode(
array(
'error' => $e->getMessage(),
'error_code' => $e->getCode()
)
);
*/
echo json_encode($adminRec);
}
?>