PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Payment / SubmissionPaymentCustomerName.php

SubmissionPaymentCustomerName.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Services/Payment/SubmissionPaymentCustomerName.php

73 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Payment;
4
5 use IvyForms\Entity\Form\Form;
6
7 /**
8 * Resolves the Payments "Customer" column from mapped billing fields.
9 */
10 class SubmissionPaymentCustomerName
11 {
12 /**
13 * @param array<int, object> $formFields
14 * @param array<int|string, mixed> $submissionData
15 * @param array<string, mixed> $submissionByTypeIndex
16 */
17 public static function resolve(
18 ?string $fromCharge,
19 Form $form,
20 string $gatewayId,
21 array $formFields,
22 array $submissionData,
23 array $submissionByTypeIndex
24 ): ?string {
25 if ($fromCharge !== null && $fromCharge !== '') {
26 return $fromCharge;
27 }
28
29 return FormSubmissionPaymentService::resolveCustomerNameFromBuyerInfo(
30 SquareBuyerInfoBuilder::build(
31 self::settingsForGateway($form, $gatewayId),
32 $submissionByTypeIndex,
33 $formFields,
34 $submissionData
35 )
36 );
37 }
38
39 /**
40 * @return array<string, mixed>
41 */
42 public static function settingsForGateway(Form $form, string $gatewayId): array
43 {
44 $integrationSettings = $form->getIntegrationSettings();
45 if ($integrationSettings === null) {
46 return [];
47 }
48
49 foreach (array_unique([$gatewayId, 'paypal', 'stripe', 'square']) as $slug) {
50 $settings = $integrationSettings->get($slug);
51 if (!is_array($settings)) {
52 continue;
53 }
54 if (self::hasBuyerMapping($settings)) {
55 return $settings;
56 }
57 }
58
59 $fallback = $integrationSettings->get($gatewayId);
60
61 return is_array($fallback) ? $fallback : [];
62 }
63
64 /**
65 * @param array<string, mixed> $settings
66 */
67 private static function hasBuyerMapping(array $settings): bool
68 {
69 return (string) ($settings['billingNameField'] ?? '') !== ''
70 || (string) ($settings['buyerEmailField'] ?? '') !== '';
71 }
72 }
73