-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloasso_payment_processor.php
More file actions
1717 lines (1538 loc) · 73.3 KB
/
Copy pathhelloasso_payment_processor.php
File metadata and controls
1717 lines (1538 loc) · 73.3 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
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
require_once 'helloasso_payment_processor.civix.php';
use CRM_HelloassoPaymentProcessor_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function helloasso_payment_processor_civicrm_config(mixed &$config): void {
_helloasso_payment_processor_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_angularModules().
*/
function helloasso_payment_processor_civicrm_angularModules(mixed &$angularModules): void {
$module = include __DIR__ . '/ang/crmHelloassoPaymentProcessor.ang.php';
$module['ext'] = E::LONG_NAME;
$angularModules['crmHelloassoPaymentProcessor'] = $module;
Civi::resources()->addVars('helloassoAfform', [
'supportsInstallments' => helloasso_payment_processor_supports_afform_installments(),
]);
}
function helloasso_payment_processor_supports_afform_installments(): bool {
return version_compare(CRM_Utils_System::version(), '6.15', '>=');
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function helloasso_payment_processor_civicrm_install(): void {
_helloasso_payment_processor_civix_civicrm_install();
helloasso_payment_processor_register_civirules_conditions();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function helloasso_payment_processor_civicrm_enable(): void {
_helloasso_payment_processor_civix_civicrm_enable();
helloasso_payment_processor_register_civirules_conditions();
}
/**
* Register optional CiviRules conditions without making CiviRules a dependency.
*/
function helloasso_payment_processor_register_civirules_conditions(): void {
if (!class_exists('CRM_Civirules_Utils_Upgrader')) {
return;
}
$jsonFile = __DIR__ . DIRECTORY_SEPARATOR . 'civirules_conditions.json';
if (!is_readable($jsonFile)) {
return;
}
try {
CRM_Civirules_Utils_Upgrader::insertConditionsFromJson($jsonFile);
}
catch (Throwable $e) {
Civi::log()->warning('HelloAsso optional CiviRules conditions could not be registered: ' . $e->getMessage());
}
}
/**
* Implements hook_civicrm_alterMenu().
*/
function helloasso_payment_processor_civicrm_alterMenu(mixed &$items): void {
foreach ([
'civicrm/admin/setting/helloasso',
'civicrm/admin/setting/preferences/helloasso',
] as $path) {
if (isset($items[$path])) {
$items[$path]['title'] = E::ts('HelloAsso settings');
$items[$path]['desc'] = E::ts('HelloAsso online payments, authorization-screen connections, secure webhooks and payment reconciliation.');
}
}
foreach ([
'civicrm/admin/setting/helloasso',
'civicrm/admin/setting/preferences/helloasso',
'civicrm/helloasso/partner',
'civicrm/helloasso/partner/callback',
] as $path) {
if (isset($items[$path])) {
$items[$path]['access_arguments'] = [['administer CiviCRM'], 'and'];
}
}
}
/**
* Implements hook_civicrm_buildForm().
*/
function helloasso_payment_processor_civicrm_buildForm(string $formName, mixed &$form): void {
if (in_array($formName, [
'CRM_Contribute_Form_Contribution_Main',
'CRM_Event_Form_Registration_Register',
], TRUE)) {
helloasso_payment_processor_add_quickform_checkout_controls($formName, $form);
}
if ($formName === 'CRM_Mjwshared_Form_PaymentRefund') {
helloasso_payment_processor_lock_mjwshared_refund_amount($form);
return;
}
if ($formName === 'CRM_Admin_Form_Generic' && helloasso_payment_processor_is_helloasso_settings_form()) {
helloasso_payment_processor_inject_settings_page_panel();
return;
}
if ($formName !== 'CRM_Admin_Form_PaymentProcessor') {
return;
}
helloasso_payment_processor_protect_test_processor_edit($form);
$paymentProcessorType = $form->getVar('_paymentProcessorDAO');
if (!$paymentProcessorType || $paymentProcessorType->class_name !== 'Payment_HelloAsso') {
return;
}
if (Civi::settings()->get('helloasso_partner_auth_enabled')) {
helloasso_payment_processor_replace_payment_processor_form_rule($form);
}
$liveProcessorId = (int) $form->getVar('_id');
if (!$liveProcessorId) {
if (Civi::settings()->get('helloasso_partner_auth_enabled')) {
helloasso_payment_processor_inject_payment_processor_creation_notice();
}
return;
}
if (!Civi::settings()->get('helloasso_partner_auth_enabled')) {
return;
}
$sandboxProcessor = helloasso_payment_processor_get_editable_sandbox_processor($form);
if (!$sandboxProcessor) {
return;
}
$sandboxProcessorId = (int) $sandboxProcessor['id'];
$liveProcessorConfig = helloasso_payment_processor_get_payment_processor($liveProcessorId) ?? [];
$processorAuthConfig = new CRM_HelloassoPaymentProcessor_ProcessorAuthConfig();
$liveCurrentMode = $processorAuthConfig->getConnectionMode($liveProcessorId, $liveProcessorConfig);
$liveLink = $processorAuthConfig->getLinkedOrganization($liveProcessorId);
$liveWebhookRegistration = $processorAuthConfig->getWebhookRegistration($liveProcessorId);
$liveWebhookOwnership = $processorAuthConfig->getWebhookOwnership($liveProcessorId);
$currentMode = $processorAuthConfig->getConnectionMode($sandboxProcessorId, $sandboxProcessor);
$link = $processorAuthConfig->getLinkedOrganization($sandboxProcessorId);
$webhookRegistration = $processorAuthConfig->getWebhookRegistration($sandboxProcessorId);
$webhookOwnership = $processorAuthConfig->getWebhookOwnership($sandboxProcessorId);
$webhookAutoManaged = $webhookOwnership !== 'manual';
$liveWebhookAutoManaged = $liveWebhookOwnership !== 'manual';
$hasClassicLiveCredentials = $processorAuthConfig->hasClassicCredentials($liveProcessorConfig);
$hasClassicSandboxCredentials = $processorAuthConfig->hasClassicCredentials($sandboxProcessor);
$sandboxPluginPublicConfigured = helloasso_payment_processor_has_partner_client_credentials(TRUE);
$livePluginPublicConfigured = helloasso_payment_processor_has_partner_client_credentials(FALSE);
$liveConnectUrl = helloasso_payment_processor_get_partner_page_url('reset=1&processor_id=' . $liveProcessorId);
$connectUrl = helloasso_payment_processor_get_partner_page_url('reset=1&processor_id=' . $sandboxProcessorId);
$liveLinkedAtLabel = helloasso_payment_processor_format_datetime($liveLink['linked_at'] ?? NULL);
$liveAccessExpiresAtLabel = helloasso_payment_processor_format_datetime($liveLink['expires_at'] ?? NULL);
$liveRefreshExpiresAtLabel = helloasso_payment_processor_format_datetime($liveLink['refresh_expires_at'] ?? NULL);
$linkedAtLabel = helloasso_payment_processor_format_datetime($link['linked_at'] ?? NULL);
$accessExpiresAtLabel = helloasso_payment_processor_format_datetime($link['expires_at'] ?? NULL);
$refreshExpiresAtLabel = helloasso_payment_processor_format_datetime($link['refresh_expires_at'] ?? NULL);
$modeOptions = [];
$modeOptions[] = '<option value="community"' . ($currentMode === 'community' ? ' selected="selected"' : '') . '>' . htmlspecialchars(E::ts('Classic API key'), ENT_QUOTES, 'UTF-8') . '</option>';
$modeOptions[] = '<option value="plugin_public"' . ($currentMode === 'plugin_public' ? ' selected="selected"' : '') . ($sandboxPluginPublicConfigured ? '' : ' disabled="disabled"') . '>' . htmlspecialchars(E::ts('HelloAsso sandbox authorization screen'), ENT_QUOTES, 'UTF-8') . '</option>';
$liveModeOptions = [];
$livePluginPublicDisabled = !$livePluginPublicConfigured || $hasClassicLiveCredentials;
$livePluginPublicDisabledReason = '';
if ($hasClassicLiveCredentials) {
$livePluginPublicDisabledReason = E::ts('Production authorization-screen mode is locked while classic live API credentials are still stored on this payment processor.');
}
elseif (!$livePluginPublicConfigured) {
$livePluginPublicDisabledReason = E::ts('Production authorization-screen mode is locked until the production client ID and client secret are configured.');
}
$liveModeOptions[] = '<option value="community"' . ($liveCurrentMode === 'community' ? ' selected="selected"' : '') . '>' . htmlspecialchars(E::ts('Classic API key'), ENT_QUOTES, 'UTF-8') . '</option>';
$liveModeOptions[] = '<option value="plugin_public"'
. ($liveCurrentMode === 'plugin_public' ? ' selected="selected"' : '')
. ($livePluginPublicDisabled ? ' disabled="disabled" title="' . htmlspecialchars($livePluginPublicDisabledReason, ENT_QUOTES, 'UTF-8') . '"' : '')
. '>' . htmlspecialchars(E::ts('HelloAsso production authorization screen'), ENT_QUOTES, 'UTF-8') . '</option>';
$liveConnectButton = helloasso_payment_processor_get_authorize_button_html(
$liveConnectUrl . '&ha_action=connect',
E::ts('Connect production to HelloAsso')
);
$sandboxConnectButton = helloasso_payment_processor_get_authorize_button_html(
$connectUrl . '&ha_action=connect',
E::ts('Connect sandbox to HelloAsso')
);
$help = [];
$help[] = '<fieldset id="helloasso-live-auth-block"><legend>' . E::ts('HelloAsso production connection') . '</legend>';
$help[] = '<div class="crm-block crm-form-block"><table class="form-layout-compressed">';
$help[] = '<tr><td>' . E::ts('Live payment processor ID') . '</td><td><code>' . $liveProcessorId . '</code></td></tr>';
$help[] = '<tr><td><label for="helloasso_live_connection_mode">' . E::ts('Live connection mode') . '</label></td><td><select id="helloasso_live_connection_mode" name="helloasso_live_connection_mode">' . implode('', $liveModeOptions) . '</select></td></tr>';
$help[] = '<tr><td><label for="helloasso_live_webhook_auto_manage">' . E::ts('Automatically enable the webhook') . '</label></td><td><input type="checkbox" id="helloasso_live_webhook_auto_manage" name="helloasso_live_webhook_auto_manage" value="1"' . ($liveWebhookAutoManaged ? ' checked="checked"' : '') . '> <span class="description">' . E::ts("Enable automatic registration of the live HelloAsso webhook for this CiviCRM instance by default. Uncheck only if another instance retains control of the webhook URL.") . '</span></td></tr>';
$help[] = '</table>';
$help[] = '<p class="description">' . helloasso_payment_processor_get_partner_required_notice() . '</p>';
$help[] = '<p class="description">' . E::ts("This block connects the production HelloAsso authorization screen on this live processor: OAuth link, linked organization and webhook registration. The live payment rail can switch to the authorization screen only when this processor no longer uses classic API keys.") . '</p>';
if ($hasClassicLiveCredentials) {
$help[] = '<p class="status warning">' . E::ts('The production authorization-screen option is greyed out because this live processor still contains classic API credentials. You can connect and test the authorization screen first, then remove the live API key fields from this processor and save the processor. The authorization-screen option will become selectable once those fields are empty.') . '</p>';
}
else {
$help[] = '<p class="description">' . E::ts("No live API key is stored on this processor. You can therefore enable production authorization-screen mode on this processor once the OAuth link has been validated.") . '</p>';
}
if (!$livePluginPublicConfigured) {
$help[] = '<p class="status warning">' . E::ts('The production authorization-screen option is also greyed out because the production client ID and client secret are not configured yet.') . '</p>';
}
if ($liveLink) {
$help[] = '<p class="status success">' . E::ts('Production organization linked: %1', [1 => htmlspecialchars((string) $liveLink['organization_slug'], ENT_QUOTES, 'UTF-8')]) . '</p>';
if ($liveLinkedAtLabel !== '') {
$help[] = '<p class="description">' . E::ts('Linked on: %1', [1 => htmlspecialchars($liveLinkedAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($liveAccessExpiresAtLabel !== '') {
$help[] = '<p class="description">' . E::ts("Access token valid until: %1", [1 => htmlspecialchars($liveAccessExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($liveRefreshExpiresAtLabel !== '') {
$help[] = '<p class="description">' . E::ts("Authorization link valid until: %1", [1 => htmlspecialchars($liveRefreshExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($liveWebhookRegistration) {
$help[] = '<p class="description">' . E::ts('Webhook management: %1', [1 => htmlspecialchars(helloasso_payment_processor_describe_webhook_ownership($liveWebhookOwnership), ENT_QUOTES, 'UTF-8')]) . '</p>';
if (!empty($liveWebhookRegistration['url'])) {
$help[] = '<p class="description">' . E::ts('Registered webhook URL: %1', [1 => htmlspecialchars((string) $liveWebhookRegistration['url'], ENT_QUOTES, 'UTF-8')]) . '</p>';
}
}
}
else {
$help[] = '<p class="status">' . E::ts("No HelloAsso production organization is linked to this processor yet.") . '</p>';
}
if ($livePluginPublicConfigured) {
$help[] = '<p>' . $liveConnectButton . '</p>';
}
else {
$help[] = '<p><button class="button" type="button" disabled="disabled">' . E::ts('Connect production to HelloAsso') . '</button> ';
$help[] = '<span class="description">' . E::ts("Enter the shared client ID and client secret on the authorization-screen settings page first, then return to start the connection.") . '</span></p>';
}
$help[] = '<p><a class="button" href="' . htmlspecialchars($liveConnectUrl, ENT_QUOTES, 'UTF-8') . '">' . E::ts('Open production authorization-screen settings') . '</a></p>';
$help[] = '</div></fieldset>';
$help[] = '<fieldset id="helloasso-sandbox-auth-block"><legend>' . E::ts('HelloAsso sandbox connection') . '</legend>';
$help[] = '<div class="crm-block crm-form-block"><table class="form-layout-compressed">';
$help[] = '<tr><td>' . E::ts('Sandbox payment processor ID') . '</td><td><code>' . $sandboxProcessorId . '</code></td></tr>';
$help[] = '<tr><td><label for="helloasso_test_connection_mode">' . E::ts('Sandbox connection mode') . '</label></td><td><select id="helloasso_test_connection_mode" name="helloasso_test_connection_mode">' . implode('', $modeOptions) . '</select></td></tr>';
$help[] = '<tr><td><label for="helloasso_test_webhook_auto_manage">' . E::ts('Automatically enable the webhook') . '</label></td><td><input type="checkbox" id="helloasso_test_webhook_auto_manage" name="helloasso_test_webhook_auto_manage" value="1"' . ($webhookAutoManaged ? ' checked="checked"' : '') . '> <span class="description">' . E::ts("Enable automatic registration of the HelloAsso webhook for this CiviCRM instance by default. Uncheck only if multiple CiviCRM instances share the same HelloAsso organization and you want to manage the webhook manually.") . '</span></td></tr>';
$help[] = '</table>';
if ($hasClassicSandboxCredentials) {
$help[] = '<p class="description">' . E::ts("Sandbox API credentials are already present on this processor. API key mode remains the safest choice until you explicitly switch.") . '</p>';
}
else {
$help[] = '<p class="description">' . E::ts("No sandbox API key is stored on this processor. The HelloAsso sandbox authorization screen is therefore offered by default.") . '</p>';
}
if ($link) {
$help[] = '<p class="status success">' . E::ts('Sandbox organization linked: %1', [1 => htmlspecialchars((string) $link['organization_slug'], ENT_QUOTES, 'UTF-8')]) . '</p>';
if ($linkedAtLabel !== '') {
$help[] = '<p class="description">' . E::ts('Linked on: %1', [1 => htmlspecialchars($linkedAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($accessExpiresAtLabel !== '') {
$help[] = '<p class="description">' . E::ts("Access token valid until: %1", [1 => htmlspecialchars($accessExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($refreshExpiresAtLabel !== '') {
$help[] = '<p class="description">' . E::ts("Authorization link valid until: %1", [1 => htmlspecialchars($refreshExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($webhookRegistration) {
$help[] = '<p class="description">' . E::ts('Webhook management: %1', [1 => htmlspecialchars(helloasso_payment_processor_describe_webhook_ownership($webhookOwnership), ENT_QUOTES, 'UTF-8')]) . '</p>';
if (!empty($webhookRegistration['url'])) {
$help[] = '<p class="description">' . E::ts('Registered webhook URL: %1', [1 => htmlspecialchars((string) $webhookRegistration['url'], ENT_QUOTES, 'UTF-8')]) . '</p>';
}
}
}
else {
$help[] = '<p class="status">' . E::ts("No HelloAsso sandbox organization is linked to this processor yet.") . '</p>';
}
if ($sandboxPluginPublicConfigured) {
$help[] = '<p>' . $sandboxConnectButton . '</p>';
$help[] = '<p>';
$help[] = '<a class="button" href="' . htmlspecialchars($connectUrl, ENT_QUOTES, 'UTF-8') . '">' . E::ts('Open authorization-screen settings') . '</a></p>';
}
else {
$help[] = '<p><button class="button" type="button" disabled="disabled">' . E::ts('Connect sandbox to HelloAsso') . '</button> ';
$help[] = '<span class="description">' . E::ts('This button remains disabled until the shared HelloAsso authorization-screen client ID and client secret are configured.') . '</span></p>';
$help[] = '<p><a class="button" href="' . htmlspecialchars($connectUrl, ENT_QUOTES, 'UTF-8') . '">' . E::ts('Open authorization-screen settings') . '</a></p>';
}
$help[] = '</div></fieldset>';
$panelHtml = implode('', $help);
Civi::resources()->addScript("
CRM.\$(function(\$) {
var panelHtml = " . json_encode($panelHtml) . ";
\$('#helloasso-live-auth-block, #helloasso-sandbox-auth-block').remove();
var \$target = \$('.crm-paymentProcessor-form-block fieldset').last();
if (\$target.length) {
\$target.after(panelHtml);
}
else {
\$('.crm-paymentProcessor-form-block .crm-submit-buttons').before(panelHtml);
}
var fieldHelp = {
'HelloAsso_user_name': " . json_encode((string) E::ts('Enter the HelloAsso client ID used by this payment processor for the selected environment. Keep the live and test values aligned with the matching HelloAsso application.')) . ",
'HelloAsso_password': " . json_encode((string) E::ts('Enter the HelloAsso client secret paired with the client ID above. Store the live and sandbox secrets separately.')) . ",
'HelloAsso_subject': " . json_encode((string) E::ts('Enter the HelloAsso organization slug or organization name expected by this processor when building API calls and payment links.')) . ",
'HelloAsso_url_site': " . json_encode((string) E::ts('Base HelloAsso API URL for live payments. Keep the default production URL unless HelloAsso explicitly instructs otherwise.')) . ",
'HelloAsso_test_user_name': " . json_encode((string) E::ts('Sandbox client ID for HelloAsso test payments.')) . ",
'HelloAsso_test_password': " . json_encode((string) E::ts('Sandbox client secret for HelloAsso test payments.')) . ",
'HelloAsso_test_subject': " . json_encode((string) E::ts('Sandbox organization slug or name used for test API calls.')) . ",
'HelloAsso_test_url_site': " . json_encode((string) E::ts('Base HelloAsso API URL for sandbox payments. Keep the sandbox default unless HelloAsso explicitly instructs otherwise.')) . "
};
\$.each(fieldHelp, function(helpId, description) {
var \$helpIcon = \$('a.helpicon[data-help-id=\"' + helpId + '\"]');
if (\$helpIcon.length) {
\$helpIcon.remove();
}
var fieldName = helpId.replace('HelloAsso_', '');
var \$row = \$('.crm-paymentProcessor-form-block-' + fieldName);
if (\$row.length && !\$row.find('.helloasso-inline-help').length) {
\$row.find('td').last().append('<br><span class=\"description helloasso-inline-help\">' + CRM.utils.escapeHtml(description) + '</span>');
}
});
});
");
}
function helloasso_payment_processor_add_quickform_checkout_controls(
string $formName,
CRM_Core_Form $form
): void {
try {
$processors = civicrm_api3('PaymentProcessor', 'get', [
'class_name' => 'Payment_HelloAsso',
'is_active' => 1,
'options' => ['limit' => 0],
]);
}
catch (Exception) {
return;
}
$processorIds = [];
foreach ($processors['values'] ?? [] as $processor) {
if (!empty($processor['id'])) {
$processorIds[] = (int) $processor['id'];
}
}
if (!$processorIds) {
return;
}
$supportsInstallments = $formName === 'CRM_Contribute_Form_Contribution_Main'
&& (bool) Civi::settings()->get('helloasso_enable_installments')
&& !empty($form->_values['is_recur_installments']);
if ($supportsInstallments) {
$form->add('text', 'helloasso_installments', E::ts('Number of installments'), [
'min' => 2,
'max' => 12,
'inputmode' => 'numeric',
'pattern' => '[0-9]*',
'size' => 3,
'class' => 'three',
]);
}
$configuredMessage = trim((string) Civi::settings()->get('helloasso_quickform_redirect_message'));
$defaultMessage = 'You will be redirected to HelloAsso to complete your payment.';
$message = $configuredMessage !== '' && $configuredMessage !== $defaultMessage
? $configuredMessage
: E::ts($defaultMessage);
$submittedInstallments = CRM_Utils_Request::retrieveValue(
'helloasso_installments',
'Positive',
NULL,
FALSE,
'POST'
);
Civi::resources()->addVars('helloassoQuickForm', [
'processorIds' => $processorIds,
'supportsInstallments' => $supportsInstallments,
'message' => $message,
'installmentsValue' => $submittedInstallments ?: '',
]);
Civi::resources()->addScriptFile(E::LONG_NAME, 'js/quickform-checkout.js');
}
function helloasso_payment_processor_replace_payment_processor_form_rule(CRM_Core_Form $form): void {
if (!isset($form->_formRules) || !is_array($form->_formRules)) {
return;
}
$updatedRules = [];
foreach ($form->_formRules as $ruleConfig) {
if (!is_array($ruleConfig) || count($ruleConfig) < 2) {
$updatedRules[] = $ruleConfig;
continue;
}
[$rule, $options] = $ruleConfig;
if ($rule === ['CRM_Admin_Form_PaymentProcessor', 'formRule']) {
$updatedRules[] = ['helloasso_payment_processor_payment_processor_form_rule', $form];
continue;
}
$updatedRules[] = $ruleConfig;
}
$form->_formRules = $updatedRules;
}
function helloasso_payment_processor_payment_processor_form_rule(mixed $fields, mixed $files, mixed $form): bool|array {
if (!$form instanceof CRM_Core_Form) {
return CRM_Admin_Form_PaymentProcessor::formRule($fields);
}
$normalizedFields = is_array($fields) ? $fields : [];
if (helloasso_payment_processor_should_allow_partner_first_save($form)) {
foreach (['user_name', 'password', 'test_user_name', 'test_password'] as $fieldName) {
if (trim((string) ($normalizedFields[$fieldName] ?? '')) === '') {
$normalizedFields[$fieldName] = '__helloasso_partner_first_save__';
}
}
}
$submittedLiveMode = (string) ($normalizedFields['helloasso_live_connection_mode'] ?? $_POST['helloasso_live_connection_mode'] ?? '');
$submittedMode = (string) ($normalizedFields['helloasso_test_connection_mode'] ?? $_POST['helloasso_test_connection_mode'] ?? '');
if ($submittedLiveMode === 'plugin_public') {
// Allow the live section to be driven by the shared OAuth authorization
// screen when classic API credentials are intentionally absent.
$normalizedFields['user_name'] = '__helloasso_plugin_public__';
}
if ($submittedMode === 'plugin_public') {
// Allow the sandbox/test section to be managed by the OAuth authorization
// screen without reintroducing a requirement for a test API key.
$normalizedFields['test_user_name'] = '__helloasso_plugin_public__';
}
return CRM_Admin_Form_PaymentProcessor::formRule($normalizedFields);
}
function helloasso_payment_processor_should_allow_partner_first_save(CRM_Core_Form $form): bool {
if (!Civi::settings()->get('helloasso_partner_auth_enabled')) {
return FALSE;
}
if ((int) $form->getVar('_id') > 0) {
return FALSE;
}
$paymentProcessorType = $form->getVar('_paymentProcessorDAO');
return $paymentProcessorType && $paymentProcessorType->class_name === 'Payment_HelloAsso';
}
function helloasso_payment_processor_inject_payment_processor_creation_notice(): void {
$panel = [];
$panel[] = '<div id="helloasso-payment-processor-create-notice" class="messages status no-popup">';
$panel[] = '<fieldset><legend>' . E::ts('HelloAsso authorization-screen setup') . '</legend>';
$panel[] = '<p>' . E::ts("This HelloAsso processor can be saved a first time without API credentials when the authorization screen is enabled.") . '</p>';
$panel[] = '<p class="description">' . E::ts("Enter the processor name, save once, then return to this processor to configure the live and sandbox authorization-screen connections.") . '</p>';
$panel[] = '<p class="description"><a href="' . htmlspecialchars(helloasso_payment_processor_get_helloasso_settings_url(), ENT_QUOTES, 'UTF-8') . '">' . E::ts('Open HelloAsso settings') . '</a></p>';
$panel[] = '</fieldset></div>';
$panelHtml = implode('', $panel);
Civi::resources()->addScript("
CRM.\$(function(\$) {
var panelHtml = " . json_encode($panelHtml) . ";
var \$panel = \$('#helloasso-payment-processor-create-notice');
if (\$panel.length) {
\$panel.remove();
}
var \$submitButtons = \$('.crm-paymentProcessor-form-block .crm-submit-buttons').first();
if (\$submitButtons.length) {
\$submitButtons.before(panelHtml);
return;
}
var \$targetFieldset = \$('.crm-paymentProcessor-form-block fieldset').last();
if (\$targetFieldset.length) {
\$targetFieldset.after(panelHtml);
return;
}
var \$container = \$('.crm-paymentProcessor-form-block').first();
if (\$container.length) {
\$container.prepend(panelHtml);
}
});
");
}
function helloasso_payment_processor_get_partner_page_url(string $query): string {
$query = ltrim($query, '?&');
$config = CRM_Core_Config::singleton();
if ($config->userFramework === 'WordPress') {
return CRM_Utils_System::url('civicrm/helloasso/partner', $query, TRUE, NULL, FALSE, FALSE);
}
return CRM_Utils_System::url('civicrm/helloasso/partner', $query, TRUE, NULL, FALSE, TRUE);
}
function helloasso_payment_processor_is_helloasso_settings_form(): bool {
return in_array(CRM_Utils_System::currentPath(), [
'civicrm/admin/setting/helloasso',
'civicrm/admin/setting/preferences/helloasso',
], TRUE);
}
function helloasso_payment_processor_get_helloasso_settings_url(): string {
$config = CRM_Core_Config::singleton();
if ($config->userFramework === 'WordPress' && function_exists('admin_url')) {
return admin_url('admin.php?page=CiviCRM&q=' . rawurlencode('civicrm/admin/setting/helloasso') . '&reset=1');
}
return CRM_Utils_System::url(
'civicrm/admin/setting/helloasso',
'reset=1',
TRUE,
NULL,
FALSE,
TRUE
);
}
function helloasso_payment_processor_get_authorize_button_image_url(): string {
return 'https://api.helloasso.com/v5/img/logo-ha.svg';
}
function helloasso_payment_processor_get_authorize_button_html(string $href, string $label): string {
$escapedHref = htmlspecialchars($href, ENT_QUOTES, 'UTF-8');
$escapedLabel = htmlspecialchars($label, ENT_QUOTES, 'UTF-8');
$imageUrl = htmlspecialchars(helloasso_payment_processor_get_authorize_button_image_url(), ENT_QUOTES, 'UTF-8');
$visibleLabel = htmlspecialchars(E::ts('Connect to HelloAsso'), ENT_QUOTES, 'UTF-8');
return helloasso_payment_processor_get_authorize_button_css()
. '<a class="helloasso-authorize-button HaAuthorizeButton" href="' . $escapedHref . '" aria-label="' . $escapedLabel . '" title="' . $escapedLabel . '">'
. '<span class="HaAuthorizeButtonLogoWrap" aria-hidden="true"><img src="' . $imageUrl . '" alt="" class="HaAuthorizeButtonLogo"></span>'
. '<span class="HaAuthorizeButtonTitle" aria-hidden="true">' . $visibleLabel . '</span>'
. '<span class="helloasso-authorize-button-sr">' . $escapedLabel . '</span></a>';
}
function helloasso_payment_processor_get_authorize_button_css(): string {
static $printed = FALSE;
if ($printed) {
return '';
}
$printed = TRUE;
return '<style>
.helloasso-authorize-button {
text-decoration: none;
}
.helloasso-authorize-button:hover,
.helloasso-authorize-button:focus,
.helloasso-authorize-button:active {
text-decoration: none;
}
.HaAuthorizeButton {
align-items: center;
background-color: #FFFFFF;
border: 0.0625rem solid #4B3FCF;
border-radius: 0.125rem;
display: inline-flex;
padding: 0;
}
.HaAuthorizeButton:focus {
box-shadow: 0 0 0 0.25rem rgba(73, 211, 138, 0.25);
outline: none;
}
.HaAuthorizeButtonLogoWrap {
align-items: center;
background-color: #FFFFFF;
display: inline-flex;
justify-content: center;
padding: 0 0.8rem;
}
.HaAuthorizeButtonLogo {
display: block;
width: 2.25rem;
}
.HaAuthorizeButtonTitle {
align-items: center;
background-color: #4B3FCF;
color: #FFFFFF;
display: inline-flex;
font-size: 1rem;
font-weight: 700;
line-height: 1;
padding: 0.78125rem 1.5rem;
white-space: nowrap;
}
.helloasso-authorize-button-sr {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
white-space: nowrap;
width: 1px;
}
</style>';
}
function helloasso_payment_processor_get_partner_required_notice(): string {
return E::ts('HelloAsso helps associations collect online payments and provides its services free of charge. It covers all transaction fees so that you can receive the full amount paid by your supporters, without fees. Voluntary contributions left by them are its only source of revenue.');
}
function helloasso_payment_processor_describe_webhook_ownership(?string $ownership): string {
return $ownership === 'manual'
? E::ts('manual / another instance in control')
: E::ts('managed by this CiviCRM instance');
}
function helloasso_payment_processor_get_primary_processor(bool $isTest): ?array {
try {
$result = civicrm_api3('PaymentProcessor', 'get', [
'class_name' => 'Payment_HelloAsso',
'is_active' => 1,
'is_test' => $isTest ? 1 : 0,
'options' => [
'limit' => 1,
'sort' => 'id ASC',
],
]);
}
catch (Exception) {
return NULL;
}
if (empty($result['values']) || !is_array($result['values'])) {
return NULL;
}
$values = array_values($result['values']);
return is_array($values[0] ?? NULL) ? $values[0] : NULL;
}
function helloasso_payment_processor_get_payment_processor(int $paymentProcessorId): ?array {
if (!$paymentProcessorId) {
return NULL;
}
try {
return civicrm_api3('PaymentProcessor', 'getsingle', ['id' => $paymentProcessorId]);
}
catch (Exception) {
return NULL;
}
}
function helloasso_payment_processor_lock_mjwshared_refund_amount(CRM_Core_Form $form): void {
$paymentProcessorId = helloasso_payment_processor_get_refund_form_payment_processor_id();
$processor = $paymentProcessorId ? helloasso_payment_processor_get_payment_processor($paymentProcessorId) : NULL;
if (($processor['class_name'] ?? NULL) !== 'Payment_HelloAsso') {
return;
}
if (method_exists($form, 'elementExists') && !$form->elementExists('refund_amount')) {
return;
}
try {
$form->freeze(['refund_amount']);
}
catch (Throwable) {
try {
$form->getElement('refund_amount')->freeze();
}
catch (Throwable) {
}
}
CRM_Core_Resources::singleton()->addScript(<<<'JS'
CRM.$(function($) {
var $refundAmount = $('#refund_amount');
if ($refundAmount.length) {
$refundAmount.prop('readonly', true).attr('aria-readonly', 'true').addClass('crm-form-readonly');
}
});
JS
);
}
function helloasso_payment_processor_get_refund_form_payment_processor_id(): ?int {
$paymentId = CRM_Utils_Request::retrieveValue('payment_id', 'Positive', NULL, FALSE, 'REQUEST');
if ($paymentId) {
$paymentProcessorId = CRM_Core_DAO::singleValueQuery(
'SELECT payment_processor_id FROM civicrm_financial_trxn WHERE id = %1',
[1 => [(int) $paymentId, 'Integer']]
);
return $paymentProcessorId ? (int) $paymentProcessorId : NULL;
}
$contributionId = CRM_Utils_Request::retrieveValue('contribution_id', 'Positive', NULL, FALSE, 'REQUEST');
if (!$contributionId) {
return NULL;
}
$paymentProcessorId = CRM_Core_DAO::singleValueQuery(
"SELECT ft.payment_processor_id
FROM civicrm_financial_trxn ft
INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = ft.id
WHERE eft.entity_table = 'civicrm_contribution'
AND eft.entity_id = %1
AND ft.is_payment = 1
AND ft.total_amount > 0
ORDER BY ft.id DESC
LIMIT 1",
[1 => [(int) $contributionId, 'Integer']]
);
return $paymentProcessorId ? (int) $paymentProcessorId : NULL;
}
function helloasso_payment_processor_render_settings_page_launch_panel(
string $title,
?array $processor,
CRM_HelloassoPaymentProcessor_ProcessorAuthConfig $processorAuthConfig,
bool $enabled,
bool $credentialsConfigured
): string {
if (!$processor || empty($processor['id'])) {
return '<fieldset class="helloasso-mire-settings-card"><legend>' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</legend>'
. '<p class="description">' . E::ts("No matching HelloAsso payment processor was found on this instance.") . '</p>'
. '</fieldset>';
}
$processorId = (int) $processor['id'];
$organizationLink = $processorAuthConfig->getLinkedOrganization($processorId);
$webhookRegistration = $processorAuthConfig->getWebhookRegistration($processorId);
$webhookOwnership = $processorAuthConfig->getWebhookOwnership($processorId);
$settingsUrl = helloasso_payment_processor_get_partner_page_url('reset=1&processor_id=' . $processorId);
$connectUrl = helloasso_payment_processor_get_partner_page_url('reset=1&processor_id=' . $processorId . '&ha_action=connect');
$connectLabel = !empty($processor['is_test']) ? E::ts('Connect sandbox to HelloAsso') : E::ts('Connect production to HelloAsso');
$linkedAtLabel = helloasso_payment_processor_format_datetime($organizationLink['linked_at'] ?? NULL);
$accessExpiresAtLabel = helloasso_payment_processor_format_datetime($organizationLink['expires_at'] ?? NULL);
$refreshExpiresAtLabel = helloasso_payment_processor_format_datetime($organizationLink['refresh_expires_at'] ?? NULL);
$lastRefreshErrorDateLabel = helloasso_payment_processor_format_datetime($organizationLink['last_refresh_error_date'] ?? NULL);
$processorTitle = trim((string) ($processor['title'] ?? $processor['name'] ?? ''));
$html = '<fieldset class="helloasso-mire-settings-card"><legend>' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</legend>';
$html .= '<p class="description">' . E::ts('The operational choice between API key and authorization screen remains on the processor record. This page enables the authorization-screen flow, explains how it works and starts the connection.') . '</p>';
$html .= '<p><strong>' . E::ts('Target processor:') . '</strong> '
. htmlspecialchars($processorTitle !== '' ? sprintf('%s (#%d)', $processorTitle, $processorId) : sprintf('#%d', $processorId), ENT_QUOTES, 'UTF-8')
. '</p>';
if ($organizationLink) {
$html .= '<p class="status success">' . E::ts('Organization linked: %1', [1 => htmlspecialchars((string) $organizationLink['organization_slug'], ENT_QUOTES, 'UTF-8')]) . '</p>';
if (($organizationLink['refresh_status'] ?? '') === 'reconnect_required') {
$httpStatus = !empty($organizationLink['last_refresh_http_status']) ? ' HTTP ' . (int) $organizationLink['last_refresh_http_status'] : '';
$failureDate = $lastRefreshErrorDateLabel !== '' ? ' (' . htmlspecialchars($lastRefreshErrorDateLabel, ENT_QUOTES, 'UTF-8') . ')' : '';
$html .= '<p class="status warning">' . E::ts("The HelloAsso authorization link on this rail can no longer be renewed%1%2. Reconnect the organization before accepting new payments through the authorization screen.", [1 => $httpStatus, 2 => $failureDate]) . '</p>';
}
elseif (($organizationLink['refresh_status'] ?? '') === 'organization_blocked') {
$httpStatus = !empty($organizationLink['last_refresh_http_status']) ? ' HTTP ' . (int) $organizationLink['last_refresh_http_status'] : '';
$failureDate = $lastRefreshErrorDateLabel !== '' ? ' (' . htmlspecialchars($lastRefreshErrorDateLabel, ENT_QUOTES, 'UTF-8') . ')' : '';
$html .= '<p class="status warning">' . E::ts("The HelloAsso organization linked on this rail is not currently allowed to receive online payments%1%2. Check its administrative status in HelloAsso before accepting new payments through the authorization screen.", [1 => $httpStatus, 2 => $failureDate]) . '</p>';
}
elseif (($organizationLink['refresh_status'] ?? '') === 'refresh_failed') {
$html .= '<p class="status warning">' . E::ts("The latest HelloAsso authorization-link renewal failed on this rail. Check the next maintenance job or reconnect the organization if the problem persists.") . '</p>';
}
if ($linkedAtLabel !== '') {
$html .= '<p class="description">' . E::ts('Linked on: %1', [1 => htmlspecialchars($linkedAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($accessExpiresAtLabel !== '') {
$html .= '<p class="description">' . E::ts("Access token valid until: %1", [1 => htmlspecialchars($accessExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
if ($refreshExpiresAtLabel !== '') {
$html .= '<p class="description">' . E::ts("Authorization link valid until: %1", [1 => htmlspecialchars($refreshExpiresAtLabel, ENT_QUOTES, 'UTF-8')]) . '</p>';
}
}
else {
$html .= '<p class="status">' . E::ts("No organization is linked on this rail yet.") . '</p>';
}
$html .= '<p class="description">' . E::ts('Webhook management: %1', [1 => htmlspecialchars(helloasso_payment_processor_describe_webhook_ownership($webhookOwnership), ENT_QUOTES, 'UTF-8')]) . '</p>';
if (!empty($webhookRegistration['url'])) {
$html .= '<p class="description">' . E::ts('Registered webhook URL: %1', [1 => htmlspecialchars((string) $webhookRegistration['url'], ENT_QUOTES, 'UTF-8')]) . '</p>';
}
$html .= '<p><a class="button" href="' . htmlspecialchars($settingsUrl, ENT_QUOTES, 'UTF-8') . '">' . E::ts('Open this authorization-screen settings page') . '</a></p>';
if (!$enabled) {
$html .= '<p class="description">' . E::ts("Enable the authorization-screen switch below and save the page before starting the connection.") . '</p>';
}
elseif (!$credentialsConfigured) {
$html .= '<p class="description">' . E::ts("Open this authorization-screen settings page first to enter the shared client ID and client secret, then return to start the connection.") . '</p>';
}
else {
$html .= '<p>' . helloasso_payment_processor_get_authorize_button_html($connectUrl, $connectLabel) . '</p>';
}
$html .= '</fieldset>';
return $html;
}
function helloasso_payment_processor_inject_settings_page_panel(): void {
$enabled = (bool) Civi::settings()->get('helloasso_partner_auth_enabled');
$sandboxCredentialsConfigured = helloasso_payment_processor_has_partner_client_credentials(TRUE);
$liveCredentialsConfigured = helloasso_payment_processor_has_partner_client_credentials(FALSE);
$processorAuthConfig = new CRM_HelloassoPaymentProcessor_ProcessorAuthConfig();
$sandboxProcessor = helloasso_payment_processor_get_primary_processor(TRUE);
$liveProcessor = helloasso_payment_processor_get_primary_processor(FALSE);
$settingsUrl = helloasso_payment_processor_get_helloasso_settings_url();
$panel = [];
$panel[] = '<div id="helloasso-mire-settings-panel" class="crm-block crm-form-block">';
$panel[] = '<fieldset><legend>' . E::ts('HelloAsso authorization-screen flow') . '</legend>';
$panel[] = '<p>' . helloasso_payment_processor_get_partner_required_notice() . '</p>';
$panel[] = '<p class="description">' . E::ts("The switch below enables or hides the authorization-screen interface on HelloAsso processors. Shared client credentials and connection startup remain managed from the dedicated authorization-screen pages.") . '</p>';
$panel[] = '<p class="description">' . E::ts("For an initial configuration: enable the authorization screen here, save the page, then open the sandbox or production rail to enter the client ID and client secret before starting the connection.") . '</p>';
$panel[] = helloasso_payment_processor_render_settings_page_launch_panel(
E::ts('HelloAsso sandbox authorization screen'),
$sandboxProcessor,
$processorAuthConfig,
$enabled,
$sandboxCredentialsConfigured
);
$panel[] = helloasso_payment_processor_render_settings_page_launch_panel(
E::ts('HelloAsso production authorization screen'),
$liveProcessor,
$processorAuthConfig,
$enabled,
$liveCredentialsConfigured
);
$panel[] = '<p class="description">' . E::ts("The official button above opens the HelloAsso connection. If you need to adjust client credentials or check the link status, use the settings link first.") . '</p>';
$panel[] = '<p class="description"><a href="' . htmlspecialchars($settingsUrl, ENT_QUOTES, 'UTF-8') . '">' . E::ts('Refresh this HelloAsso settings page') . '</a></p>';
$panel[] = '</fieldset></div>';
$panelHtml = implode('', $panel);
Civi::resources()->addScript("
CRM.\$(function(\$) {
var panelHtml = " . json_encode($panelHtml) . ";
var \$panel = \$('#helloasso-mire-settings-panel');
if (\$panel.length) {
\$panel.remove();
}
var \$submitButtons = \$('.crm-settings-form-block .crm-submit-buttons').first();
if (\$submitButtons.length) {
\$submitButtons.before(panelHtml);
return;
}
var \$targetFieldset = \$('.crm-settings-form-block fieldset').first();
if (\$targetFieldset.length) {
\$targetFieldset.before(panelHtml);
return;
}
var \$container = \$('.crm-settings-form-block').first();
if (\$container.length) {
\$container.prepend(panelHtml);
}
});
");
}
/**
* Implements hook_civicrm_postProcess().
*/
function helloasso_payment_processor_civicrm_postProcess(string $formName, mixed &$form): void {
if ($formName === 'CRM_Mjwshared_Form_PaymentRefund') {
helloasso_payment_processor_show_refund_success_message();
return;
}
if ($formName !== 'CRM_Admin_Form_PaymentProcessor') {
return;
}
$paymentProcessorType = $form->getVar('_paymentProcessorDAO');
if (!$paymentProcessorType || $paymentProcessorType->class_name !== 'Payment_HelloAsso') {
return;
}
$processorAuthConfig = new CRM_HelloassoPaymentProcessor_ProcessorAuthConfig();
$liveProcessorId = (int) $form->getVar('_id');
$submittedLiveMode = (string) ($_POST['helloasso_live_connection_mode'] ?? '');
if ($liveProcessorId && in_array($submittedLiveMode, ['community', 'plugin_public'], TRUE)) {
$liveProcessor = helloasso_payment_processor_get_payment_processor($liveProcessorId) ?? [];
if (
$submittedLiveMode === 'plugin_public'
&& (
!$liveProcessor
|| $processorAuthConfig->hasClassicCredentials($liveProcessor)
|| !helloasso_payment_processor_has_partner_client_credentials(FALSE)
)
) {
$submittedLiveMode = 'community';
}
$processorAuthConfig->setConnectionMode($liveProcessorId, $submittedLiveMode);
$processorAuthConfig->setWebhookOwnership(
$liveProcessorId,
!empty($_POST['helloasso_live_webhook_auto_manage']) ? 'managed_by_civicrm' : 'manual'
);
}
$sandboxProcessor = helloasso_payment_processor_get_editable_sandbox_processor($form);
if (!$sandboxProcessor) {
return;
}
$submittedMode = (string) ($_POST['helloasso_test_connection_mode'] ?? '');
if (!in_array($submittedMode, ['community', 'plugin_public'], TRUE)) {
return;
}
$processorAuthConfig->setConnectionMode((int) $sandboxProcessor['id'], $submittedMode);
$processorAuthConfig->setWebhookOwnership(
(int) $sandboxProcessor['id'],
!empty($_POST['helloasso_test_webhook_auto_manage']) ? 'managed_by_civicrm' : 'manual'
);
}
/**
* Implements hook_civicrm_check().
*/
function helloasso_payment_processor_civicrm_check(mixed &$messages): void {
try {
$missingColumns = helloasso_payment_processor_get_missing_metadata_columns([
'checkout_intent_id',
'helloasso_payment_id',
'event_type',
'state',
'payment_processor_id',
'sync_origin_date',
'sync_next_date',
'sync_last_date',
'sync_attempt_count',
'sync_error_count',
'long_sync_scheme',
'long_sync_origin_date',
'long_sync_next_date',
'long_sync_last_date',
'long_sync_attempt_count',
'long_sync_error_count',
]);
$missingAuthColumns = helloasso_payment_processor_get_missing_auth_columns([
'refresh_issued_at',
'refresh_status',
'last_refresh_error',
'last_refresh_error_date',
'last_refresh_http_status',
]);
$missingIndexes = helloasso_payment_processor_get_missing_metadata_indexes([
'index_contribution_id',
'index_checkout_intent_id',
'index_helloasso_payment_id',
'index_payment_processor_id_sync_next_date',
'index_sync_next_date',
'index_payment_processor_id_long_sync_next_date',
]);
if ($missingColumns || $missingAuthColumns || $missingIndexes) {
$details = [];
if ($missingColumns) {
$details[] = E::ts('Missing metadata columns: %1', [1 => implode(', ', $missingColumns)]);
}
if ($missingAuthColumns) {
$details[] = E::ts('Missing authorization columns: %1', [1 => implode(', ', $missingAuthColumns)]);
}
if ($missingIndexes) {
$details[] = E::ts('Missing indexes: %1', [1 => implode(', ', $missingIndexes)]);
}
$messages[] = new CRM_Utils_Check_Message(
'helloasso_payment_processor_schema_incomplete',
E::ts(
'The HelloAsso v2 schema upgrade is incomplete. %1 Run <code>cv updb</code> and then <code>cv flush</code> before relying on webhook queueing, follow-up sync, or legacy repair.',
[1 => implode(' ', $details)]
),
E::ts('HelloAsso: Incomplete V2 Upgrade'),
\Psr\Log\LogLevel::WARNING,
'fa-exclamation-triangle'
);
}
}
catch (Exception $e) {
$messages[] = new CRM_Utils_Check_Message(
'helloasso_payment_processor_schema_check_failed',
E::ts('The HelloAsso schema check could not be completed: %1', [1 => $e->getMessage()]),
E::ts('HelloAsso: Schema Check Failed'),
\Psr\Log\LogLevel::WARNING,
'fa-exclamation-triangle'
);
}
try {
$processorAuthConfig = new CRM_HelloassoPaymentProcessor_ProcessorAuthConfig();
$linkedProcessors = $processorAuthConfig->getLinkedProcessors();
$now = time();
$expiringSoon = [];