-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtigopesa.php
171 lines (145 loc) · 6.07 KB
/
tigopesa.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
// Define module related meta data.
function tigopesa_MetaData(){
return array(
'DisplayName' => 'TigoPesa Payment',
'APIVersion' => '1.1', // Use API Version 1.1
'DisableLocalCreditCardInput' => true,
'TokenisedStorage' => false,
);
}
// Define gateway configuration options.
function tigopesa_config() {
global $CONFIG;
copyTigopesaTemplates();
$configArray = array(
// the friendly display name for a payment gateway should be
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'TigoPesa Payment',
),
// Text Field for TIGOPESA API KEY
'apiKey' => array(
'FriendlyName' => 'API KEY',
'Type' => 'text',
'Size' => '50',
'Description' => 'Enter your account API KEY here',
),
// Text Field for TIGOPESA SECRET KEY
'secretKey' => array(
'FriendlyName' => 'Secret Key',
'Type' => 'password',
'Size' => '25',
'Default' => '',
'Description' => 'Enter secret key here',
),
// A customer MSISDN
'customerMSISDN' => array(
'FriendlyName' => 'customer MSISDN',
'Type' => 'text',
'Size' => '25',
'Default' => '',
'Description' => 'Enter customer MSISDN here',
),
// Customer PIN
'customerPIN' => array(
'FriendlyName' => 'Customer PIN',
'Type' => 'password',
'Size' => '25',
'Default' => '',
'Description' => 'Enter customer PIN here',
),
// Account ID
'accountID' => array(
'FriendlyName' => 'Account ID',
'Type' => 'text',
'Size' => '25',
'Default' => '',
'Description' => 'Enter account ID here',
),
// Generate accessToken URL
'access_token_url' => array(
'FriendlyName' => 'Generate AccessToken Url',
'Type' => 'text',
'Size' => '50',
'Default' => '',
'Description' => 'Enter url here',
),
// Generate Validate MFS URL
'validate_MFS_url' => array(
'FriendlyName' => 'Validate MFS url',
'Type' => 'text',
'Size' => '50',
'Default' => '',
'Description' => 'Enter url here',
),
// Generate Payment url
'paymentURL' => array(
'FriendlyName' => 'Make Payment URL',
'Type' => 'text',
'Size' => '50',
'Default' => '',
'Description' => 'Enter url here',
),
);
return $configArray;
}
// Payment link.
function tigopesa_link($data) {
global $CONFIG;
$systemurl = ($CONFIG['SystemSSLURL']) ? $CONFIG['SystemSSLURL'] . '/' : $CONFIG['SystemURL'] . '/';
$data = serialize($data);
$data = base64_encode($data);
$gatewayConfigs = getGatewayVariables("tigopesa");
$baseUrl = ($gatewayConfigs['basedomainurl']) ? $gatewayConfigs['basedomainurl'] : $systemurl;
$processPaymentLink = $baseUrl . 'modules/gateways/tigopesa/processPayment.php';
$code = '<form method="POST" action="' . $processPaymentLink . '">
<input type="hidden" name="order" value="' . $data . '" />
<input class="btn btn-primary btn-lg" type="submit" value="Pay Now" />
</form>';
return $code;
}
// Copy templates files to /templates/template_name/ directory
function copyTigopesaTemplates() {
global $CONFIG;
try {
if (!isset($CONFIG['Template'])) {
throw new Exception("Template not set. Cannot discover Template Name", 1);
}
$templateName = $CONFIG['Template'];
$templatePath = __DIR__ . '/../../templates/' . $templateName . '/';
if (!file_exists($templatePath) || !$templateName) {
throw new Exception("Template \"$templateName\" doesn't exist.", 1);
}
$tigopesaFinalTemplatePaths = array(
__DIR__ . '/../../templates/' . $templateName . '/tigopesa_payment.tpl',
__DIR__ . '/../../templates/' . $templateName . '/tigopesa_callback.tpl'
);
$sourceDirectory = __DIR__ . '/tigopesa/templates/';
$destinationDirectory = __DIR__ . '/../../templates/' . $templateName . '/';
$templatesToCopy = array(
'tigopesa_payment.tpl',
'tigopesa_callback.tpl'
);
foreach ($templatesToCopy AS $templateToCopy) {
$sourceTemplatePath = $sourceDirectory . $templateToCopy;
$destinationTemplatePath = $destinationDirectory . $templateToCopy;
if (!file_exists($destinationTemplatePath)) {
if (!file_exists($sourceTemplatePath)) {
throw new Exception("TigoPesa Source Template ('$templateToCopy') Not Found. Please ensure to copy all the files correctly", 2);
}
$copySuccess = copy($sourceTemplatePath, $destinationTemplatePath);
if (!$copySuccess) {
throw new Exception("Copy $sourceTemplatePath to $destinationTemplatePath Failed", 3);
}
// show here message to log for success copy
}
}
} catch (Exception $ex) {
// show here message to log for error copy
}
}
?>