-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayrequest.php
More file actions
307 lines (285 loc) · 10.1 KB
/
payrequest.php
File metadata and controls
307 lines (285 loc) · 10.1 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
/**
* WHMCS Sample Payment Gateway Module
*
* Payment Gateway modules allow you to integrate payment solutions with the
* WHMCS platform.
*
* This sample file demonstrates how a payment gateway module for WHMCS should
* be structured and all supported functionality it can contain.
*
* Within the module itself, all functions must be prefixed with the module
* filename, followed by an underscore, and then the function name. For this
* example file, the filename is "gatewaymodule" and therefore all functions
* begin "gatewaymodule_".
*
* If your module or third party API does not support a given function, you
* should not define that function within your module. Only the _config
* function is required.
*
* For more information, please refer to the online documentation.
*
* @see https://developers.whmcs.com/payment-gateways/
*
* @copyright Copyright (c) WHMCS Limited 2017
* @license http://www.whmcs.com/license/ WHMCS Eula
*/
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
/**
* Define module related meta data.
*
* Values returned here are used to determine module related capabilities and
* settings.
*
* @see https://developers.whmcs.com/payment-gateways/meta-data-params/
*
* @return array
*/
function gatewaymodule_MetaData()
{
return array(
'DisplayName' => 'PayRequest Payment Gateway Module',
'APIVersion' => '1.1', // Use API Version 1.1
'DisableLocalCreditCardInput' => true,
'TokenisedStorage' => false,
);
}
/**
* Define gateway configuration options.
*
* The fields you define here determine the configuration options that are
* presented to administrator users when activating and configuring your
* payment gateway module for use.
*
* Supported field types include:
* * text
* * password
* * yesno
* * dropdown
* * radio
* * textarea
*
* Examples of each field type and their possible configuration parameters are
* provided in the sample function below.
*
* @return array
*/
function gatewaymodule_config()
{
return array(
// the friendly display name for a payment gateway should be
// defined here for backwards compatibility
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'PayRequest Payment Gateway Module',
),
// a text field type allows for single line text input
'APIKey' => array(
'FriendlyName' => 'API Key',
'Type' => 'text',
'Size' => '25',
'Default' => '',
'Description' => 'Enter your API Key here',
),
// the yesno field type displays a single checkbox option
'testMode' => array(
'FriendlyName' => 'Test Mode',
'Type' => 'yesno',
'Description' => 'Tick to enable test mode',
),
// the dropdown field type renders a select menu of options
'dropdownField' => array(
'FriendlyName' => 'Dropdown Field',
'Type' => 'dropdown',
'Options' => array(
'option1' => 'Display Value 1',
'option2' => 'Second Option',
'option3' => 'Another Option',
),
'Description' => 'Choose one',
),
// the radio field type displays a series of radio button options
'radioField' => array(
'FriendlyName' => 'Radio Field',
'Type' => 'radio',
'Options' => 'First Option,Second Option,Third Option',
'Description' => 'Choose your option!',
),
// the textarea field type allows for multi-line text input
'textareaField' => array(
'FriendlyName' => 'Textarea Field',
'Type' => 'textarea',
'Rows' => '3',
'Cols' => '60',
'Description' => 'Freeform multi-line text input field',
),
);
}
/**
* Payment link.
*
* Required by third party payment gateway modules only.
*
* Defines the HTML output displayed on an invoice. Typically consists of an
* HTML form that will take the user to the payment gateway endpoint.
*
* @param array $params Payment Gateway Module Parameters
*
* @see https://developers.whmcs.com/payment-gateways/third-party-gateway/
*
* @return string
*/
function gatewaymodule_link($params)
{
// Gateway Configuration Parameters
$apikey = $params['APIKey'];
$testMode = $params['testMode'];
$dropdownField = $params['dropdownField'];
$radioField = $params['radioField'];
$textareaField = $params['textareaField'];
// Invoice Parameters
$invoiceId = $params['invoiceid'];
$description = $params["description"];
$amount = $params['amount'];
$currencyCode = $params['currency'];
// Client Parameters
$firstname = $params['clientdetails']['firstname'];
$lastname = $params['clientdetails']['lastname'];
$email = $params['clientdetails']['email'];
$address1 = $params['clientdetails']['address1'];
$address2 = $params['clientdetails']['address2'];
$city = $params['clientdetails']['city'];
$state = $params['clientdetails']['state'];
$postcode = $params['clientdetails']['postcode'];
$country = $params['clientdetails']['country'];
$phone = $params['clientdetails']['phonenumber'];
// System Parameters
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$returnUrl = $params['returnurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];
$url = 'https://payrequest.me/hostingwalk';
$postfields = array();
$postfields['username'] = $username;
$postfields['invoice_id'] = $invoiceId;
$postfields['description'] = $description;
$postfields['amount'] = $amount;
$postfields['currency'] = $currencyCode;
$postfields['first_name'] = $firstname;
$postfields['last_name'] = $lastname;
$postfields['email'] = $email;
$postfields['address1'] = $address1;
$postfields['address2'] = $address2;
$postfields['city'] = $city;
$postfields['state'] = $state;
$postfields['postcode'] = $postcode;
$postfields['country'] = $country;
$postfields['phone'] = $phone;
$postfields['callback_url'] = $systemUrl . '/modules/gateways/callback/' . $moduleName . '.php';
$postfields['return_url'] = $returnUrl;
$htmlOutput = '<form method="post" action="' . $url . '">';
foreach ($postfields as $k => $v) {
$htmlOutput .= '<input type="hidden" name="' . $k . '" value="' . urlencode($v) . '" />';
}
$htmlOutput .= '<input type="submit" value="' . $langPayNow . '" />';
$htmlOutput .= '</form>';
return $htmlOutput;
}
/**
* Refund transaction.
*
* Called when a refund is requested for a previously successful transaction.
*
* @param array $params Payment Gateway Module Parameters
*
* @see https://developers.whmcs.com/payment-gateways/refunds/
*
* @return array Transaction response status
*/
function gatewaymodule_refund($params)
{
// Gateway Configuration Parameters
$accountId = $params['accountID'];
$secretKey = $params['secretKey'];
$testMode = $params['testMode'];
$dropdownField = $params['dropdownField'];
$radioField = $params['radioField'];
$textareaField = $params['textareaField'];
// Transaction Parameters
$transactionIdToRefund = $params['transid'];
$refundAmount = $params['amount'];
$currencyCode = $params['currency'];
// Client Parameters
$firstname = $params['clientdetails']['firstname'];
$lastname = $params['clientdetails']['lastname'];
$email = $params['clientdetails']['email'];
$address1 = $params['clientdetails']['address1'];
$address2 = $params['clientdetails']['address2'];
$city = $params['clientdetails']['city'];
$state = $params['clientdetails']['state'];
$postcode = $params['clientdetails']['postcode'];
$country = $params['clientdetails']['country'];
$phone = $params['clientdetails']['phonenumber'];
// System Parameters
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];
// perform API call to initiate refund and interpret result
return array(
// 'success' if successful, otherwise 'declined', 'error' for failure
'status' => 'success',
// Data to be recorded in the gateway log - can be a string or array
'rawdata' => $responseData,
// Unique Transaction ID for the refund transaction
'transid' => $refundTransactionId,
// Optional fee amount for the fee value refunded
'fees' => $feeAmount,
);
}
/**
* Cancel subscription.
*
* If the payment gateway creates subscriptions and stores the subscription
* ID in tblhosting.subscriptionid, this function is called upon cancellation
* or request by an admin user.
*
* @param array $params Payment Gateway Module Parameters
*
* @see https://developers.whmcs.com/payment-gateways/subscription-management/
*
* @return array Transaction response status
*/
function gatewaymodule_cancelSubscription($params)
{
// Gateway Configuration Parameters
$accountId = $params['accountID'];
$secretKey = $params['secretKey'];
$testMode = $params['testMode'];
$dropdownField = $params['dropdownField'];
$radioField = $params['radioField'];
$textareaField = $params['textareaField'];
// Subscription Parameters
$subscriptionIdToCancel = $params['subscriptionID'];
// System Parameters
$companyName = $params['companyname'];
$systemUrl = $params['systemurl'];
$langPayNow = $params['langpaynow'];
$moduleDisplayName = $params['name'];
$moduleName = $params['paymentmethod'];
$whmcsVersion = $params['whmcsVersion'];
// perform API call to cancel subscription and interpret result
return array(
// 'success' if successful, any other value for failure
'status' => 'success',
// Data to be recorded in the gateway log - can be a string or array
'rawdata' => $responseData,
);
}