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 / ProductSubmissionSnapshotHelper.php

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

48 lines 1.2 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 /**
6 * Handles product submission snapshot parsing and normalization.
7 *
8 * Snapshot line priceAmount values are for entry display only — never use them
9 * to compute charge amounts (see ProductSelectionSubtotalCalculator).
10 */
11 class ProductSubmissionSnapshotHelper
12 {
13 /**
14 * @param mixed $rawValue
15 * @return mixed
16 */
17 public function normalizeProductSubmissionValue($rawValue)
18 {
19 if (!is_string($rawValue)) {
20 return $rawValue;
21 }
22
23 $trimmed = trim($rawValue);
24 if ($trimmed === '' || ($trimmed[0] ?? '') !== '{') {
25 return $rawValue;
26 }
27
28 $decoded = json_decode($trimmed, true);
29 if (!is_array($decoded) || (int) ($decoded['v'] ?? 0) !== 1) {
30 return $rawValue;
31 }
32
33 $productType = (string) ($decoded['productType'] ?? '');
34 $raw = (string) ($decoded['raw'] ?? '');
35
36 if ($productType === 'checkbox') {
37 return array_values(
38 array_filter(
39 array_map('trim', explode(',', $raw)),
40 static fn(string $part): bool => $part !== ''
41 )
42 );
43 }
44
45 return $raw !== '' ? $raw : $rawValue;
46 }
47 }
48