-
Notifications
You must be signed in to change notification settings - Fork 48
/
registrarmodule.php
1806 lines (1626 loc) · 55 KB
/
registrarmodule.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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WHMCS SDK Sample Registrar Module
*
* Registrar Modules allow you to create modules that allow for domain
* registration, management, transfers, and other functionality within
* WHMCS.
*
* This sample file demonstrates how a registrar module for WHMCS should
* be structured and exercises supported functionality.
*
* Registrar Modules are stored in a unique directory within the
* modules/registrars/ directory that matches the module's unique name.
* This name should be all lowercase, containing only letters and numbers,
* and always start with a letter.
*
* Within the module itself, all functions must be prefixed with the module
* filename, followed by an underscore, and then the function name. For
* example this file, the filename is "registrarmodule.php" and therefore all
* function begin "registrarmodule_".
*
* If your module or third party API does not support a given function, you
* should not define the function within your module. WHMCS recommends that
* all registrar modules implement Register, Transfer, Renew, GetNameservers,
* SaveNameservers, GetContactDetails & SaveContactDetails.
*
* For more information, please refer to the online documentation.
*
* @see https://developers.whmcs.com/domain-registrars/
*
* @copyright Copyright (c) WHMCS Limited 2017
* @license https://www.whmcs.com/license/ WHMCS Eula
*/
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
use WHMCS\Domains\DomainLookup\ResultsList;
use WHMCS\Domains\DomainLookup\SearchResult;
use WHMCS\Module\Registrar\Registrarmodule\ApiClient;
// Require any libraries needed for the module to function.
// require_once __DIR__ . '/path/to/library/loader.php';
//
// Also, perform any initialization required by the service's library.
/**
* Define module related metadata
*
* Provide some module information including the display name and API Version to
* determine the method of decoding the input values.
*
* @return array
*/
function registrarmodule_MetaData()
{
return array(
'DisplayName' => 'Sample Registrar Module for WHMCS',
'APIVersion' => '1.1',
);
}
/**
* Define registrar configuration options.
*
* The values you return here define what configuration options
* we store for the module. These values are made available to
* each module function.
*
* You can store an unlimited number of configuration settings.
* The following field types are supported:
* * Text
* * Password
* * Yes/No Checkboxes
* * Dropdown Menus
* * Radio Buttons
* * Text Areas
*
* @return array
*/
function registrarmodule_getConfigArray()
{
return array(
// Friendly display name for the module
'FriendlyName' => array(
'Type' => 'System',
'Value' => 'Sample Registrar Module for WHMCS',
),
// a text field type allows for single line text input
'API Username' => array(
'Type' => 'text',
'Size' => '25',
'Default' => '1024',
'Description' => 'Enter in megabytes',
),
// a password field type allows for masked text input
'API Key' => array(
'Type' => 'password',
'Size' => '25',
'Default' => '',
'Description' => 'Enter secret value here',
),
// the yesno field type displays a single checkbox option
'Test Mode' => array(
'Type' => 'yesno',
'Description' => 'Tick to enable',
),
// the dropdown field type renders a select menu of options
'Account Mode' => array(
'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
'Email Preference' => array(
'Type' => 'radio',
'Options' => 'First Option,Second Option,Third Option',
'Description' => 'Choose your preference',
),
// the textarea field type allows for multi-line text input
'Email' => array(
'Type' => 'textarea',
'Rows' => '3',
'Cols' => '60',
'Description' => 'Freeform multi-line text input field',
),
);
}
/**
* Register a domain.
*
* Attempt to register a domain with the domain registrar.
*
* This is triggered when the following events occur:
* * Payment received for a domain registration order
* * When a pending domain registration order is accepted
* * Upon manual request by an admin user
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_RegisterDomain($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// registration parameters
$sld = $params['sld'];
$tld = $params['tld'];
$registrationPeriod = $params['regperiod'];
/**
* Nameservers.
*
* If purchased with web hosting, values will be taken from the
* assigned web hosting server. Otherwise uses the values specified
* during the order process.
*/
$nameserver1 = $params['ns1'];
$nameserver2 = $params['ns2'];
$nameserver3 = $params['ns3'];
$nameserver4 = $params['ns4'];
$nameserver5 = $params['ns5'];
// registrant information
$firstName = $params["firstname"];
$lastName = $params["lastname"];
$fullName = $params["fullname"]; // First name and last name combined
$companyName = $params["companyname"];
$email = $params["email"];
$address1 = $params["address1"];
$address2 = $params["address2"];
$city = $params["city"];
$state = $params["state"]; // eg. TX
$stateFullName = $params["fullstate"]; // eg. Texas
$postcode = $params["postcode"]; // Postcode/Zip code
$countryCode = $params["countrycode"]; // eg. GB
$countryName = $params["countryname"]; // eg. United Kingdom
$phoneNumber = $params["phonenumber"]; // Phone number as the user provided it
$phoneCountryCode = $params["phonecc"]; // Country code determined based on country
$phoneNumberFormatted = $params["fullphonenumber"]; // Format: +CC.xxxxxxxxxxxx
/**
* Admin contact information.
*
* Defaults to the same as the client information. Can be configured
* to use the web hosts details if the `Use Clients Details` option
* is disabled in Setup > General Settings > Domains.
*/
$adminFirstName = $params["adminfirstname"];
$adminLastName = $params["adminlastname"];
$adminCompanyName = $params["admincompanyname"];
$adminEmail = $params["adminemail"];
$adminAddress1 = $params["adminaddress1"];
$adminAddress2 = $params["adminaddress2"];
$adminCity = $params["admincity"];
$adminState = $params["adminstate"]; // eg. TX
$adminStateFull = $params["adminfullstate"]; // eg. Texas
$adminPostcode = $params["adminpostcode"]; // Postcode/Zip code
$adminCountry = $params["admincountry"]; // eg. GB
$adminPhoneNumber = $params["adminphonenumber"]; // Phone number as the user provided it
$adminPhoneNumberFormatted = $params["adminfullphonenumber"]; // Format: +CC.xxxxxxxxxxxx
// domain addon purchase status
$enableDnsManagement = (bool) $params['dnsmanagement'];
$enableEmailForwarding = (bool) $params['emailforwarding'];
$enableIdProtection = (bool) $params['idprotection'];
/**
* Premium domain parameters.
*
* Premium domains enabled informs you if the admin user has enabled
* the selling of premium domain names. If this domain is a premium name,
* `premiumCost` will contain the cost price retrieved at the time of
* the order being placed. The premium order should only be processed
* if the cost price now matches the previously fetched amount.
*/
$premiumDomainsEnabled = (bool) $params['premiumEnabled'];
$premiumDomainsCost = $params['premiumCost'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'years' => $registrationPeriod,
'nameservers' => array(
'ns1' => $nameserver1,
'ns2' => $nameserver2,
'ns3' => $nameserver3,
'ns4' => $nameserver4,
'ns5' => $nameserver5,
),
'contacts' => array(
'registrant' => array(
'firstname' => $firstName,
'lastname' => $lastName,
'companyname' => $companyName,
'email' => $email,
'address1' => $address1,
'address2' => $address2,
'city' => $city,
'state' => $state,
'zipcode' => $postcode,
'country' => $countryCode,
'phonenumber' => $phoneNumberFormatted,
),
'tech' => array(
'firstname' => $adminFirstName,
'lastname' => $adminLastName,
'companyname' => $adminCompanyName,
'email' => $adminEmail,
'address1' => $adminAddress1,
'address2' => $adminAddress2,
'city' => $adminCity,
'state' => $adminState,
'zipcode' => $adminPostcode,
'country' => $adminCountry,
'phonenumber' => $adminPhoneNumberFormatted,
),
),
'dnsmanagement' => $enableDnsManagement,
'emailforwarding' => $enableEmailForwarding,
'idprotection' => $enableIdProtection,
);
if ($premiumDomainsEnabled && $premiumDomainsCost) {
$postfields['accepted_premium_cost'] = $premiumDomainsCost;
}
try {
$api = new ApiClient();
$api->call('Register', $postfields);
return array(
'success' => true,
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Initiate domain transfer.
*
* Attempt to create a domain transfer request for a given domain.
*
* This is triggered when the following events occur:
* * Payment received for a domain transfer order
* * When a pending domain transfer order is accepted
* * Upon manual request by an admin user
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_TransferDomain($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// registration parameters
$sld = $params['sld'];
$tld = $params['tld'];
$registrationPeriod = $params['regperiod'];
$eppCode = $params['eppcode'];
/**
* Nameservers.
*
* If purchased with web hosting, values will be taken from the
* assigned web hosting server. Otherwise uses the values specified
* during the order process.
*/
$nameserver1 = $params['ns1'];
$nameserver2 = $params['ns2'];
$nameserver3 = $params['ns3'];
$nameserver4 = $params['ns4'];
$nameserver5 = $params['ns5'];
// registrant information
$firstName = $params["firstname"];
$lastName = $params["lastname"];
$fullName = $params["fullname"]; // First name and last name combined
$companyName = $params["companyname"];
$email = $params["email"];
$address1 = $params["address1"];
$address2 = $params["address2"];
$city = $params["city"];
$state = $params["state"]; // eg. TX
$stateFullName = $params["fullstate"]; // eg. Texas
$postcode = $params["postcode"]; // Postcode/Zip code
$countryCode = $params["countrycode"]; // eg. GB
$countryName = $params["countryname"]; // eg. United Kingdom
$phoneNumber = $params["phonenumber"]; // Phone number as the user provided it
$phoneCountryCode = $params["phonecc"]; // Country code determined based on country
$phoneNumberFormatted = $params["fullphonenumber"]; // Format: +CC.xxxxxxxxxxxx
/**
* Admin contact information.
*
* Defaults to the same as the client information. Can be configured
* to use the web hosts details if the `Use Clients Details` option
* is disabled in Setup > General Settings > Domains.
*/
$adminFirstName = $params["adminfirstname"];
$adminLastName = $params["adminlastname"];
$adminCompanyName = $params["admincompanyname"];
$adminEmail = $params["adminemail"];
$adminAddress1 = $params["adminaddress1"];
$adminAddress2 = $params["adminaddress2"];
$adminCity = $params["admincity"];
$adminState = $params["adminstate"]; // eg. TX
$adminStateFull = $params["adminfullstate"]; // eg. Texas
$adminPostcode = $params["adminpostcode"]; // Postcode/Zip code
$adminCountry = $params["admincountry"]; // eg. GB
$adminPhoneNumber = $params["adminphonenumber"]; // Phone number as the user provided it
$adminPhoneNumberFormatted = $params["adminfullphonenumber"]; // Format: +CC.xxxxxxxxxxxx
// domain addon purchase status
$enableDnsManagement = (bool) $params['dnsmanagement'];
$enableEmailForwarding = (bool) $params['emailforwarding'];
$enableIdProtection = (bool) $params['idprotection'];
/**
* Premium domain parameters.
*
* Premium domains enabled informs you if the admin user has enabled
* the selling of premium domain names. If this domain is a premium name,
* `premiumCost` will contain the cost price retrieved at the time of
* the order being placed. The premium order should only be processed
* if the cost price now matches that previously fetched amount.
*/
$premiumDomainsEnabled = (bool) $params['premiumEnabled'];
$premiumDomainsCost = $params['premiumCost'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'eppcode' => $eppCode,
'nameservers' => array(
'ns1' => $nameserver1,
'ns2' => $nameserver2,
'ns3' => $nameserver3,
'ns4' => $nameserver4,
'ns5' => $nameserver5,
),
'years' => $registrationPeriod,
'contacts' => array(
'registrant' => array(
'firstname' => $firstName,
'lastname' => $lastName,
'companyname' => $companyName,
'email' => $email,
'address1' => $address1,
'address2' => $address2,
'city' => $city,
'state' => $state,
'zipcode' => $postcode,
'country' => $countryCode,
'phonenumber' => $phoneNumberFormatted,
),
'tech' => array(
'firstname' => $adminFirstName,
'lastname' => $adminLastName,
'companyname' => $adminCompanyName,
'email' => $adminEmail,
'address1' => $adminAddress1,
'address2' => $adminAddress2,
'city' => $adminCity,
'state' => $adminState,
'zipcode' => $adminPostcode,
'country' => $adminCountry,
'phonenumber' => $adminPhoneNumberFormatted,
),
),
'dnsmanagement' => $enableDnsManagement,
'emailforwarding' => $enableEmailForwarding,
'idprotection' => $enableIdProtection,
);
try {
$api = new ApiClient();
$api->call('Transfer', $postfields);
return array(
'success' => true,
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Renew a domain.
*
* Attempt to renew/extend a domain for a given number of years.
*
* This is triggered when the following events occur:
* * Payment received for a domain renewal order
* * When a pending domain renewal order is accepted
* * Upon manual request by an admin user
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_RenewDomain($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// registration parameters
$sld = $params['sld'];
$tld = $params['tld'];
$registrationPeriod = $params['regperiod'];
// domain addon purchase status
$enableDnsManagement = (bool) $params['dnsmanagement'];
$enableEmailForwarding = (bool) $params['emailforwarding'];
$enableIdProtection = (bool) $params['idprotection'];
/**
* Premium domain parameters.
*
* Premium domains enabled informs you if the admin user has enabled
* the selling of premium domain names. If this domain is a premium name,
* `premiumCost` will contain the cost price retrieved at the time of
* the order being placed. A premium renewal should only be processed
* if the cost price now matches that previously fetched amount.
*/
$premiumDomainsEnabled = (bool) $params['premiumEnabled'];
$premiumDomainsCost = $params['premiumCost'];
// Build post data.
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'years' => $registrationPeriod,
'dnsmanagement' => $enableDnsManagement,
'emailforwarding' => $enableEmailForwarding,
'idprotection' => $enableIdProtection,
);
try {
$api = new ApiClient();
$api->call('Renew', $postfields);
return array(
'success' => true,
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Fetch current nameservers.
*
* This function should return an array of nameservers for a given domain.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_GetNameservers($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// domain parameters
$sld = $params['sld'];
$tld = $params['tld'];
$registrationPeriod = $params['regperiod'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
);
try {
$api = new ApiClient();
$api->call('GetNameservers', $postfields);
return array(
'success' => true,
'ns1' => $api->getFromResponse('nameserver1'),
'ns2' => $api->getFromResponse('nameserver2'),
'ns3' => $api->getFromResponse('nameserver3'),
'ns4' => $api->getFromResponse('nameserver4'),
'ns5' => $api->getFromResponse('nameserver5'),
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Save nameserver changes.
*
* This function should submit a change of nameservers request to the
* domain registrar.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_SaveNameservers($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// domain parameters
$sld = $params['sld'];
$tld = $params['tld'];
// submitted nameserver values
$nameserver1 = $params['ns1'];
$nameserver2 = $params['ns2'];
$nameserver3 = $params['ns3'];
$nameserver4 = $params['ns4'];
$nameserver5 = $params['ns5'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'nameserver1' => $nameserver1,
'nameserver2' => $nameserver2,
'nameserver3' => $nameserver3,
'nameserver4' => $nameserver4,
'nameserver5' => $nameserver5,
);
try {
$api = new ApiClient();
$api->call('SetNameservers', $postfields);
return array(
'success' => true,
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Get the current WHOIS Contact Information.
*
* Should return a multi-level array of the contacts and name/address
* fields that be modified.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_GetContactDetails($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// domain parameters
$sld = $params['sld'];
$tld = $params['tld'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
);
try {
$api = new ApiClient();
$api->call('GetWhoisInformation', $postfields);
return array(
'Registrant' => array(
'First Name' => $api->getFromResponse('registrant.firstname'),
'Last Name' => $api->getFromResponse('registrant.lastname'),
'Company Name' => $api->getFromResponse('registrant.company'),
'Email Address' => $api->getFromResponse('registrant.email'),
'Address 1' => $api->getFromResponse('registrant.address1'),
'Address 2' => $api->getFromResponse('registrant.address2'),
'City' => $api->getFromResponse('registrant.city'),
'State' => $api->getFromResponse('registrant.state'),
'Postcode' => $api->getFromResponse('registrant.postcode'),
'Country' => $api->getFromResponse('registrant.country'),
'Phone Number' => $api->getFromResponse('registrant.phone'),
'Fax Number' => $api->getFromResponse('registrant.fax'),
),
'Technical' => array(
'First Name' => $api->getFromResponse('tech.firstname'),
'Last Name' => $api->getFromResponse('tech.lastname'),
'Company Name' => $api->getFromResponse('tech.company'),
'Email Address' => $api->getFromResponse('tech.email'),
'Address 1' => $api->getFromResponse('tech.address1'),
'Address 2' => $api->getFromResponse('tech.address2'),
'City' => $api->getFromResponse('tech.city'),
'State' => $api->getFromResponse('tech.state'),
'Postcode' => $api->getFromResponse('tech.postcode'),
'Country' => $api->getFromResponse('tech.country'),
'Phone Number' => $api->getFromResponse('tech.phone'),
'Fax Number' => $api->getFromResponse('tech.fax'),
),
'Billing' => array(
'First Name' => $api->getFromResponse('billing.firstname'),
'Last Name' => $api->getFromResponse('billing.lastname'),
'Company Name' => $api->getFromResponse('billing.company'),
'Email Address' => $api->getFromResponse('billing.email'),
'Address 1' => $api->getFromResponse('billing.address1'),
'Address 2' => $api->getFromResponse('billing.address2'),
'City' => $api->getFromResponse('billing.city'),
'State' => $api->getFromResponse('billing.state'),
'Postcode' => $api->getFromResponse('billing.postcode'),
'Country' => $api->getFromResponse('billing.country'),
'Phone Number' => $api->getFromResponse('billing.phone'),
'Fax Number' => $api->getFromResponse('billing.fax'),
),
'Admin' => array(
'First Name' => $api->getFromResponse('admin.firstname'),
'Last Name' => $api->getFromResponse('admin.lastname'),
'Company Name' => $api->getFromResponse('admin.company'),
'Email Address' => $api->getFromResponse('admin.email'),
'Address 1' => $api->getFromResponse('admin.address1'),
'Address 2' => $api->getFromResponse('admin.address2'),
'City' => $api->getFromResponse('admin.city'),
'State' => $api->getFromResponse('admin.state'),
'Postcode' => $api->getFromResponse('admin.postcode'),
'Country' => $api->getFromResponse('admin.country'),
'Phone Number' => $api->getFromResponse('admin.phone'),
'Fax Number' => $api->getFromResponse('admin.fax'),
),
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Update the WHOIS Contact Information for a given domain.
*
* Called when a change of WHOIS Information is requested within WHMCS.
* Receives an array matching the format provided via the `GetContactDetails`
* method with the values from the users input.
*
* @param array $params common module parameters
*
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @return array
*/
function registrarmodule_SaveContactDetails($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// domain parameters
$sld = $params['sld'];
$tld = $params['tld'];
// whois information
$contactDetails = $params['contactdetails'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'contacts' => array(
'registrant' => array(
'firstname' => $contactDetails['Registrant']['First Name'],
'lastname' => $contactDetails['Registrant']['Last Name'],
'company' => $contactDetails['Registrant']['Company Name'],
'email' => $contactDetails['Registrant']['Email Address'],
// etc...
),
'tech' => array(
'firstname' => $contactDetails['Technical']['First Name'],
'lastname' => $contactDetails['Technical']['Last Name'],
'company' => $contactDetails['Technical']['Company Name'],
'email' => $contactDetails['Technical']['Email Address'],
// etc...
),
'billing' => array(
'firstname' => $contactDetails['Billing']['First Name'],
'lastname' => $contactDetails['Billing']['Last Name'],
'company' => $contactDetails['Billing']['Company Name'],
'email' => $contactDetails['Billing']['Email Address'],
// etc...
),
'admin' => array(
'firstname' => $contactDetails['Admin']['First Name'],
'lastname' => $contactDetails['Admin']['Last Name'],
'company' => $contactDetails['Admin']['Company Name'],
'email' => $contactDetails['Admin']['Email Address'],
// etc...
),
),
);
try {
$api = new ApiClient();
$api->call('UpdateWhoisInformation', $postfields);
return array(
'success' => true,
);
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Check Domain Availability.
*
* Determine if a domain or group of domains are available for
* registration or transfer.
*
* @param array $params common module parameters
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @see \WHMCS\Domains\DomainLookup\SearchResult
* @see \WHMCS\Domains\DomainLookup\ResultsList
*
* @throws Exception Upon domain availability check failure.
*
* @return \WHMCS\Domains\DomainLookup\ResultsList An ArrayObject based collection of \WHMCS\Domains\DomainLookup\SearchResult results
*/
function registrarmodule_CheckAvailability($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// availability check parameters
$searchTerm = $params['searchTerm'];
$punyCodeSearchTerm = $params['punyCodeSearchTerm'];
$tldsToInclude = $params['tldsToInclude'];
$isIdnDomain = (bool) $params['isIdnDomain'];
$premiumEnabled = (bool) $params['premiumEnabled'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'searchTerm' => $searchTerm,
'tldsToSearch' => $tldsToInclude,
'includePremiumDomains' => $premiumEnabled,
);
try {
$api = new ApiClient();
$api->call('CheckAvailability', $postfields);
$results = new ResultsList();
foreach ($api->getFromResponse('domains') as $domain) {
// Instantiate a new domain search result object
$searchResult = new SearchResult($domain['sld'], $domain['tld']);
// Determine the appropriate status to return
if ($domain['status'] == 'available') {
$status = SearchResult::STATUS_NOT_REGISTERED;
} elseif ($domain['statis'] == 'registered') {
$status = SearchResult::STATUS_REGISTERED;
} elseif ($domain['statis'] == 'reserved') {
$status = SearchResult::STATUS_RESERVED;
} else {
$status = SearchResult::STATUS_TLD_NOT_SUPPORTED;
}
$searchResult->setStatus($status);
// Return premium information if applicable
if ($domain['isPremiumName']) {
$searchResult->setPremiumDomain(true);
$searchResult->setPremiumCostPricing(
array(
'register' => $domain['premiumRegistrationPrice'],
'renew' => $domain['premiumRenewPrice'],
'CurrencyCode' => 'USD',
)
);
}
// Append to the search results list
$results->append($searchResult);
}
return $results;
} catch (\Exception $e) {
return array(
'error' => $e->getMessage(),
);
}
}
/**
* Domain Suggestion Settings.
*
* Defines the settings relating to domain suggestions (optional).
* It follows the same convention as `getConfigArray`.
*
* @see https://developers.whmcs.com/domain-registrars/check-availability/
*
* @return array of Configuration Options
*/
function registrarmodule_DomainSuggestionOptions() {
return array(
'includeCCTlds' => array(
'FriendlyName' => 'Include Country Level TLDs',
'Type' => 'yesno',
'Description' => 'Tick to enable',
),
);
}
/**
* Get Domain Suggestions.
*
* Provide domain suggestions based on the domain lookup term provided.
*
* @param array $params common module parameters
* @see https://developers.whmcs.com/domain-registrars/module-parameters/
*
* @see \WHMCS\Domains\DomainLookup\SearchResult
* @see \WHMCS\Domains\DomainLookup\ResultsList
*
* @throws Exception Upon domain suggestions check failure.
*
* @return \WHMCS\Domains\DomainLookup\ResultsList An ArrayObject based collection of \WHMCS\Domains\DomainLookup\SearchResult results
*/
function registrarmodule_GetDomainSuggestions($params)
{
// user defined configuration values
$userIdentifier = $params['API Username'];
$apiKey = $params['API Key'];
$testMode = $params['Test Mode'];
$accountMode = $params['Account Mode'];
$emailPreference = $params['Email Preference'];
$additionalInfo = $params['Additional Information'];
// availability check parameters
$searchTerm = $params['searchTerm'];
$punyCodeSearchTerm = $params['punyCodeSearchTerm'];
$tldsToInclude = $params['tldsToInclude'];
$isIdnDomain = (bool) $params['isIdnDomain'];
$premiumEnabled = (bool) $params['premiumEnabled'];
$suggestionSettings = $params['suggestionSettings'];
// Build post data
$postfields = array(
'username' => $userIdentifier,
'password' => $apiKey,
'testmode' => $testMode,
'domain' => $sld . '.' . $tld,
'searchTerm' => $searchTerm,
'tldsToSearch' => $tldsToInclude,
'includePremiumDomains' => $premiumEnabled,
'includeCCTlds' => $suggestionSettings['includeCCTlds'],
);
try {
$api = new ApiClient();
$api->call('GetSuggestions', $postfields);