-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
42 lines (35 loc) · 1.8 KB
/
config.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
<?php
function insert_response($jsonMpesaResponse){
# 1.1. Config Section
$dbName = 'vlm_system';
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = '';
# 1.1.1 establish a connection
try{
$con = new PDO("mysql:dbhost=$dbHost;dbname=$dbName", $dbUser, $dbPass);
echo "Connection was successful";
}
catch(PDOException $e){
die("Error Connecting ".$e->getMessage());
}
# 1.1.2 Insert Response to Database
try{
$insert = $con->prepare("INSERT INTO `mobile_payments`(`TransactionType`, `TransID`, `TransTime`, `TransAmount`, `BusinessShortCode`, `BillRefNumber`, `InvoiceNumber`, `OrgAccountBalance`, `ThirdPartyTransID`, `MSISDN`, `FirstName`, `MiddleName`, `LastName`) VALUES (:TransactionType, :TransID, :TransTime, :TransAmount, :BusinessShortCode, :BillRefNumber, :InvoiceNumber, :OrgAccountBalance, :ThirdPartyTransID, :MSISDN, :FirstName, :MiddleName, :LastName)");
$insert->execute((array)($jsonMpesaResponse));
# 1.1.2o Optional - Log the transaction to a .txt or .log file(May Expose your transactions if anyone gets the links, be careful with this. If you don't need it, comment it out or secure it)
$Transaction = fopen('Transaction.txt', 'a');
fwrite($Transaction, json_encode($jsonMpesaResponse));
fclose($Transaction);
}
catch(PDOException $e){
# 1.1.2b Log the error to a file. Optionally, you can set it to send a text message or an email notification during production.
$errLog = fopen('error.txt', 'a');
fwrite($errLog, $e->getMessage());
fclose($errLog);
# 1.1.2o Optional. Log the failed transaction. Remember, it has only failed to save to your database but M-PESA Transaction itself was successful.
$logFailedTransaction = fopen('failedTransaction.txt', 'a');
fwrite($logFailedTransaction, json_encode($jsonMpesaResponse));
fclose($logFailedTransaction);
}
}