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 / Factory / Payment / PaymentFactory.php

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

59 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Factory\Payment;
4
5 use IvyForms\Entity\Payment\Payment as PaymentEntity;
6 use IvyForms\ValueObjects\Payment\Payment as PaymentValueObject;
7
8 /**
9 * Factory for payment entities.
10 */
11 class PaymentFactory
12 {
13 /**
14 * @param array<string, mixed> $data
15 * @return PaymentEntity
16 */
17 public static function create(array $data): PaymentEntity
18 {
19 $entryId = null;
20 if (array_key_exists('entryId', $data) && $data['entryId'] !== null && $data['entryId'] !== '') {
21 $entryId = (int) $data['entryId'];
22 if ($entryId <= 0) {
23 $entryId = null;
24 }
25 }
26
27 $paymentObject = new PaymentValueObject(
28 (int) ($data['id'] ?? 0),
29 $entryId,
30 (int) ($data['formId'] ?? 0),
31 (string) ($data['transactionId'] ?? ''),
32 (string) ($data['paymentMethod'] ?? 'square'),
33 isset($data['customerName']) && $data['customerName'] !== ''
34 ? (string) $data['customerName']
35 : null,
36 (int) ($data['amount'] ?? 0),
37 (string) ($data['currency'] ?? 'USD'),
38 isset($data['squareReceiptUrl']) ? (string) $data['squareReceiptUrl'] : null,
39 isset($data['dateCreated']) ? (string) $data['dateCreated'] : null,
40 isset($data['providerMeta']) && $data['providerMeta'] !== ''
41 ? (string) $data['providerMeta']
42 : null
43 );
44
45 $payment = new PaymentEntity($paymentObject);
46 $payment->setStatus((string) ($data['status'] ?? 'succeeded'));
47
48 if (isset($data['id'])) {
49 $payment->setId((int) $data['id']);
50 }
51
52 if (isset($data['dateCreated'])) {
53 $payment->setDateCreated((string) $data['dateCreated']);
54 }
55
56 return $payment;
57 }
58 }
59