-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirmation_url.php
45 lines (36 loc) · 1.73 KB
/
confirmation_url.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
<?php
# if this is your first time, you might need to check the directory 'Tutorial 1' File first.
require 'config.php';
header("Content-Type: application/json");
$response = '{
"ResultCode": 0,
"ResultDesc": "Confirmation Received Successfully"
}';
// Response from M-PESA Stream
$mpesaResponse = file_get_contents('php://input');
// log the response
$logFile = "M_PESAConfirmationResponse.txt";
$jsonMpesaResponse = json_decode($mpesaResponse, true); // We will then use this to save to database
$transaction = array(
':TransactionType' => $jsonMpesaResponse['TransactionType'],
':TransID' => $jsonMpesaResponse['TransID'],
':TransTime' => $jsonMpesaResponse['TransTime'],
':TransAmount' => $jsonMpesaResponse['TransAmount'],
':BusinessShortCode' => $jsonMpesaResponse['BusinessShortCode'],
':BillRefNumber' => $jsonMpesaResponse['BillRefNumber'],
':InvoiceNumber' => $jsonMpesaResponse['InvoiceNumber'],
':OrgAccountBalance' => $jsonMpesaResponse['OrgAccountBalance'],
':ThirdPartyTransID' => $jsonMpesaResponse['ThirdPartyTransID'],
':MSISDN' => $jsonMpesaResponse['MSISDN'],
':FirstName' => $jsonMpesaResponse['FirstName'],
':MiddleName' => $jsonMpesaResponse['MiddleName'],
':LastName' => $jsonMpesaResponse['LastName']
);
// write to file
$log = fopen($logFile, "a");
fwrite($log, $mpesaResponse);
fclose($log);
echo $response;
// this will insert to database.
insert_response($transaction);
?>