1: | <?php |
2: | declare(strict_types=1); |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | class Billing_Module extends Module_Skeleton implements \Module\Skeleton\Contracts\Hookable |
21: | { |
22: | |
23: | private static $BILLING_SERVER_HOST = BILLING_HOST; |
24: | private static $BILLING_SERVER_USER = BILLING_USER; |
25: | private static $BILLING_SERVER_PASSWORD = BILLING_PASSWORD; |
26: | private static $BILLING_SERVER_DATABASE = BILLING_DB; |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | private static $_PAYOUT_OPTIONS = array('tender', 'freeze', 'balance'); |
37: | |
38: | |
39: | |
40: | |
41: | |
42: | |
43: | public function __construct() |
44: | { |
45: | parent::__construct(); |
46: | |
47: | $this->exportedFunctions = array( |
48: | '*' => PRIVILEGE_SITE, |
49: | 'add_referral' => PRIVILEGE_ADMIN, |
50: | 'get_invoice_from_domain' => PRIVILEGE_ADMIN, |
51: | 'get_package_type' => PRIVILEGE_SITE|PRIVILEGE_USER, |
52: | 'get_package_by_invoice' => PRIVILEGE_ADMIN, |
53: | |
54: | |
55: | 'get_invoice' => PRIVILEGE_ALL |
56: | ); |
57: | } |
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: | public function get_payment_method(): ?string |
65: | { |
66: | return 'other'; |
67: | |
68: | } |
69: | |
70: | |
71: | |
72: | |
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: | |
81: | public function get_next_payment(): array |
82: | { |
83: | return [ |
84: | 'date' => -1, |
85: | 'amount' => 0 |
86: | ]; |
87: | } |
88: | |
89: | |
90: | |
91: | |
92: | |
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: | |
100: | |
101: | |
102: | |
103: | |
104: | |
105: | |
106: | |
107: | |
108: | public function list_payments(): array |
109: | { |
110: | $recs = []; |
111: | |
112: | return $recs; |
113: | |
114: | } |
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: | public function get_billing_status(string $invoice = ''): int |
123: | { |
124: | return $this->get_status($invoice); |
125: | } |
126: | |
127: | |
128: | |
129: | |
130: | |
131: | |
132: | |
133: | |
134: | |
135: | |
136: | |
137: | |
138: | |
139: | |
140: | public function get_status(string $invoice = ''): ?int |
141: | { |
142: | return 1; |
143: | } |
144: | |
145: | |
146: | |
147: | |
148: | |
149: | |
150: | public function is_billed(): bool |
151: | { |
152: | return (bool)$this->get_hosting_subscription(); |
153: | } |
154: | |
155: | |
156: | |
157: | |
158: | |
159: | |
160: | public function get_hosting_subscription(): ?string |
161: | { |
162: | return $this->getConfig('billing', 'invoice'); |
163: | } |
164: | |
165: | |
166: | |
167: | |
168: | |
169: | |
170: | |
171: | public function is_referred(string $invoice): bool |
172: | { |
173: | return false; |
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: | public function get_payment_information(string $transnum, int $date, string $type = 'paypal'): array |
206: | { |
207: | return []; |
208: | } |
209: | |
210: | |
211: | |
212: | |
213: | |
214: | |
215: | |
216: | public function edit_referral_profile(array $credentials): bool { |
217: | return error('not implemented'); |
218: | } |
219: | |
220: | |
221: | |
222: | |
223: | |
224: | |
225: | public function referral_profile_exists(): bool |
226: | { |
227: | return false; |
228: | } |
229: | |
230: | |
231: | |
232: | |
233: | |
234: | |
235: | public function get_referral_username(): ?string |
236: | { |
237: | return null; |
238: | } |
239: | |
240: | |
241: | |
242: | |
243: | |
244: | |
245: | |
246: | public function edit_payout_amount(float $amount): bool |
247: | { |
248: | return error('not implemented'); |
249: | } |
250: | |
251: | |
252: | |
253: | |
254: | |
255: | |
256: | public function get_payout_amount(): ?float |
257: | { |
258: | return null; |
259: | } |
260: | |
261: | |
262: | |
263: | |
264: | |
265: | |
266: | public function get_minimum_payout_amount(): float |
267: | { |
268: | return (float)self::PAYOUT_MINBAL; |
269: | } |
270: | |
271: | |
272: | |
273: | |
274: | |
275: | |
276: | public function referral_balance(): float |
277: | { |
278: | return 0; |
279: | } |
280: | |
281: | |
282: | |
283: | |
284: | |
285: | |
286: | public function referral_multiplier(): float |
287: | { |
288: | return 1; |
289: | } |
290: | |
291: | |
292: | |
293: | |
294: | |
295: | |
296: | |
297: | |
298: | |
299: | |
300: | public function referral_upgrade_needed(): array |
301: | { |
302: | $next = array('method' => 'client', 'next' => 2); |
303: | |
304: | return $next; |
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: | public function get_referrals(): array |
334: | { |
335: | return []; |
336: | } |
337: | |
338: | |
339: | |
340: | |
341: | |
342: | |
343: | public function get_customer_referral_information(): ?array |
344: | { |
345: | return null; |
346: | } |
347: | |
348: | |
349: | |
350: | |
351: | |
352: | |
353: | |
354: | |
355: | |
356: | public function create_referral_profile(string $username, array $personal = []): bool { |
357: | return error('not implemented'); |
358: | } |
359: | |
360: | |
361: | |
362: | |
363: | |
364: | |
365: | |
366: | |
367: | public function change_payout_preference(string $pref, string $val): bool |
368: | { |
369: | return error('not implemented'); |
370: | } |
371: | |
372: | |
373: | |
374: | |
375: | |
376: | |
377: | |
378: | public function get_payout_preference(string $pref): ?string |
379: | { |
380: | return null; |
381: | } |
382: | |
383: | |
384: | |
385: | |
386: | |
387: | |
388: | |
389: | |
390: | public function add_referral(string $invoice, string $pinvoice): bool |
391: | { |
392: | return error('not implemented'); |
393: | } |
394: | |
395: | |
396: | |
397: | |
398: | |
399: | |
400: | |
401: | public function get_credit_from_invoice(string $invoice): ?float |
402: | { |
403: | return 0; |
404: | } |
405: | |
406: | |
407: | |
408: | |
409: | |
410: | |
411: | |
412: | public function get_credit_from_package_type(string $package): float |
413: | { |
414: | return 1; |
415: | } |
416: | |
417: | |
418: | |
419: | |
420: | |
421: | |
422: | |
423: | public function get_invoice_from_domain(string $domain): ?string |
424: | { |
425: | return null; |
426: | } |
427: | |
428: | |
429: | |
430: | |
431: | |
432: | |
433: | public function get_renewal_hash(string $invoice = null): ?string |
434: | { |
435: | return null; |
436: | } |
437: | |
438: | |
439: | |
440: | |
441: | |
442: | |
443: | |
444: | |
445: | |
446: | public function get_renewal_link(string $invoice = null): ?string |
447: | { |
448: | return null; |
449: | } |
450: | |
451: | |
452: | |
453: | |
454: | |
455: | |
456: | public function get_customer_since(): int |
457: | { |
458: | return (int)($this->getConfig('billing', 'ctime') ?? |
459: | filectime($this->domain_fs_path())); |
460: | } |
461: | |
462: | |
463: | |
464: | |
465: | |
466: | |
467: | |
468: | |
469: | |
470: | |
471: | |
472: | |
473: | |
474: | |
475: | |
476: | |
477: | |
478: | |
479: | |
480: | |
481: | public function get_billing_information(): array |
482: | { |
483: | return array(); |
484: | } |
485: | |
486: | |
487: | |
488: | |
489: | |
490: | |
491: | public function get_credit_card_information() |
492: | { |
493: | return []; |
494: | } |
495: | |
496: | |
497: | |
498: | |
499: | |
500: | |
501: | |
502: | |
503: | |
504: | |
505: | |
506: | public function change_credit_card_information( |
507: | int $expyear, |
508: | int $expmonth, |
509: | ?string $cvm = null, |
510: | ?string $number = null, |
511: | string $type = null |
512: | ): bool { |
513: | return error('not implemented'); |
514: | } |
515: | |
516: | |
517: | |
518: | |
519: | |
520: | |
521: | |
522: | |
523: | |
524: | |
525: | |
526: | |
527: | |
528: | |
529: | |
530: | |
531: | public function change_billing_information(array $details): bool { |
532: | return error('not implemented'); |
533: | } |
534: | |
535: | |
536: | |
537: | |
538: | |
539: | |
540: | public function get_package_type(): ?string |
541: | { |
542: | $invoice = $this->get_invoice(); |
543: | |
544: | return $this->get_package_by_invoice($invoice); |
545: | } |
546: | |
547: | |
548: | |
549: | |
550: | |
551: | |
552: | |
553: | public function get_package_by_invoice(string $invoice): ?string |
554: | { |
555: | if ($invoice === $this->get_invoice()) { |
556: | return $this->getServiceValue('siteinfo', 'plan'); |
557: | } |
558: | |
559: | $ids = \Auth::get_site_id_from_invoice($invoice); |
560: | if (null === $ids) { |
561: | return null; |
562: | } |
563: | |
564: | foreach ($ids as $siteid) { |
565: | $ctx = \Auth::context(null, "site{$siteid}"); |
566: | if ($ctx->getAccount()->cur['billing']['invoice'] === $invoice) { |
567: | return $ctx->getAccount()->cur['siteinfo']['plan'] ?? null; |
568: | } |
569: | } |
570: | |
571: | return null; |
572: | } |
573: | |
574: | |
575: | |
576: | |
577: | |
578: | |
579: | |
580: | public function claim_referral(string $token): bool |
581: | { |
582: | return error('not implemented'); |
583: | } |
584: | |
585: | |
586: | |
587: | |
588: | |
589: | |
590: | |
591: | |
592: | |
593: | |
594: | |
595: | |
596: | |
597: | public function claim_metadata(string $token) |
598: | { |
599: | return error('not implemented'); |
600: | } |
601: | |
602: | |
603: | |
604: | |
605: | |
606: | |
607: | public function configured(): bool |
608: | { |
609: | return static::class !== self::class; |
610: | } |
611: | |
612: | public function _verify_conf(\Opcenter\Service\ConfigurationContext $ctx): bool |
613: | { |
614: | return true; |
615: | } |
616: | |
617: | public function _create() |
618: | { |
619: | |
620: | } |
621: | |
622: | public function _delete() |
623: | { |
624: | |
625: | } |
626: | |
627: | public function _edit() |
628: | { |
629: | |
630: | } |
631: | |
632: | public function _create_user(string $user) |
633: | { |
634: | |
635: | } |
636: | |
637: | public function _delete_user(string $user) |
638: | { |
639: | |
640: | } |
641: | |
642: | public function _edit_user(string $userold, string $usernew, array $oldpwd) |
643: | { |
644: | |
645: | } |
646: | |
647: | |
648: | |
649: | |
650: | |
651: | |
652: | private function get_all_invoices(): array |
653: | { |
654: | $invoice = (array)$this->get_invoice(); |
655: | if (!$invoice) { |
656: | return []; |
657: | } |
658: | $addons = (array)$this->getConfig('billing', 'addons'); |
659: | if (!$addons) { |
660: | return $invoice; |
661: | } |
662: | |
663: | return array_merge($invoice, $addons); |
664: | } |
665: | |
666: | |
667: | |
668: | |
669: | |
670: | |
671: | public function get_invoice(): ?string |
672: | { |
673: | if ($this->permission_level & (PRIVILEGE_ADMIN | PRIVILEGE_RESELLER)) { |
674: | return null; |
675: | } |
676: | $invoice = (string)$this->getConfig('billing', 'invoice'); |
677: | if ($invoice) { |
678: | return $invoice; |
679: | } |
680: | if ($this->getConfig('billing', 'parent_invoice')) { |
681: | return (string)$this->getConfig('billing', 'parent_invoice'); |
682: | } |
683: | |
684: | return null; |
685: | } |
686: | |
687: | |
688: | } |