-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCollect.php
More file actions
89 lines (59 loc) · 1.65 KB
/
testCollect.php
File metadata and controls
89 lines (59 loc) · 1.65 KB
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
<?php
# Run config file with API credentials
require_once ('config.php'); // replace 'config.php' with your file path
require_once ('mtn.php');
# Generate UUID
$uuid = gen_uuid();
# Set test payment parameters
$amount = 1;
$currency = "ZMW";
$number = substr($phoneNumber, 1);
$number = "260961234567";
$timestamp = date('Ymd_Gis');
# Create postDATA array for collection
$REQUEST_BODY = json_encode(array(
'amount' => $amount,
'currency' => $currency,
'externalId' => $timestamp,
'payer' => array(
'partyIdType' => "MSISDN",'partyId' => $number,),
'payerMessage' => "Payment of K" . $k . " from ".$number,
'payeeNote' => "Click yes to approve",
));
# Get access token from Collections API
mtnTokenCollect();
# Access token success
if ($tokenStatus == "success") {
# Submit collection request
mtnCollect($uuid, $bearer_token, $REQUEST_BODY);
# Collection request successfully submitted
if ($collectStatus == "success") {
# Check if collection was executed
mtnCheckCollect($uuid, $bearer_token);
# Check API gave a response
if ($checkStatus == "success") {
# Successful collection!
if ($withdrawStatus == 1) {
$finalResult = "success";
}
# Failed collection: user cancelled, insufficient funds, or other error
else {
$finalResult = "failed: withdrawStatus";
}
}
# Error calling checkCollection API
else {
$finalResult = "failed: checkStatus";
}
}
# Failed to submit collection request
else {
$finalResult = "failed: collectStatus";
}
}
# Failed to get access token
else {
$finalResult = "failed: tokenStatus";
}
echo $finalResult;
?>