PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Domain / Factory / Payment / PaymentFactory.php
ameliabooking / src / Domain / Factory / Payment Last commit date
PaymentFactory.php 1 month ago PaymentGatewayFactory.php 7 months ago
PaymentFactory.php
134 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Domain\Factory\Payment;
9
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Domain\Entity\Payment\PaymentGateway;
12 use AmeliaBooking\Domain\Entity\Payment\Payment;
13 use AmeliaBooking\Domain\Services\DateTime\DateTimeService;
14 use AmeliaBooking\Domain\ValueObjects\BooleanValueObject;
15 use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue;
16 use AmeliaBooking\Domain\ValueObjects\Json;
17 use AmeliaBooking\Domain\ValueObjects\Number\Float\Price;
18 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
19 use AmeliaBooking\Domain\ValueObjects\String\PaymentStatus;
20 use AmeliaBooking\Domain\ValueObjects\String\Name;
21 use AmeliaBooking\Domain\ValueObjects\String\PaymentData;
22 use AmeliaBooking\Domain\ValueObjects\String\Url;
23 use AmeliaBooking\Infrastructure\WP\HelperService\HelperService;
24 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\StarterWooCommerceService;
25
26 /**
27 * Class PaymentFactory
28 *
29 * @package AmeliaBooking\Domain\Factory\Payment
30 */
31 class PaymentFactory
32 {
33 /**
34 * @param $data
35 *
36 * @return Payment
37 * @throws InvalidArgumentException
38 */
39 public static function create($data)
40 {
41 if (isset($data['data']) && !is_string($data['data'])) {
42 $data['data'] = json_encode($data['data'], true);
43 }
44
45 $payment = new Payment(
46 new Price($data['amount']),
47 new DateTimeValue(DateTimeService::getCustomDateTimeObject($data['dateTime'])),
48 new PaymentStatus($data['status']),
49 new PaymentGateway(new Name($data['gateway'])),
50 new PaymentData(isset($data['data']) ? $data['data'] : '')
51 );
52
53 if (!empty($data['customerBookingId'])) {
54 $payment->setCustomerBookingId(new Id($data['customerBookingId']));
55 }
56
57 if (isset($data['id'])) {
58 $payment->setId(new Id($data['id']));
59 }
60
61 if (!empty($data['gatewayTitle'])) {
62 $payment->setGatewayTitle(new Name($data['gatewayTitle']));
63 }
64
65 if (!empty($data['packageCustomerId'])) {
66 $payment->setPackageCustomerId(new Id($data['packageCustomerId']));
67 }
68
69 if (!empty($data['parentId'])) {
70 $payment->setParentId(new Id($data['parentId']));
71 }
72
73 if (!empty($data['invoiceNumber'])) {
74 $payment->setInvoiceNumber(new Id($data['invoiceNumber']));
75 }
76
77 if (!empty($data['entity'])) {
78 $payment->setEntity(new Name($data['entity']));
79 }
80
81 if (!empty($data['actionsCompleted'])) {
82 $payment->setActionsCompleted(new BooleanValueObject($data['actionsCompleted']));
83 }
84
85 if (!empty($data['triggeredActions'])) {
86 $payment->setTriggeredActions(new BooleanValueObject($data['triggeredActions']));
87 }
88
89 if (!empty($data['created'])) {
90 $payment->setCreated(new DateTimeValue(DateTimeService::getCustomDateTimeObjectFromUtc($data['created'])));
91 }
92
93 if (
94 !empty($data['wcOrderId']) &&
95 StarterWooCommerceService::isEnabled()
96 ) {
97 $payment->setWcOrderId(new Id($data['wcOrderId']));
98
99 if (!empty($data['wcOrderItemId'])) {
100 $payment->setWcOrderItemId(new Id($data['wcOrderItemId']));
101 }
102
103 if ($wcOrderUrl = HelperService::getWooCommerceOrderUrl($data['wcOrderId'])) {
104 $payment->setWcOrderUrl(new Url($wcOrderUrl));
105 }
106
107 if ($wcOrderItemValues = HelperService::getWooCommerceOrderItemAmountValues($data['wcOrderId'])) {
108 $key = !empty($data['wcOrderItemId']) && !empty($wcOrderItemValues[$data['wcOrderItemId']]) ?
109 $data['wcOrderItemId'] : array_keys($wcOrderItemValues)[0];
110
111 if (!empty($wcOrderItemValues[$key]['coupon'])) {
112 $payment->setWcItemCouponValue(
113 new Price($wcOrderItemValues[$key]['coupon'] < 0 ? 0 : $wcOrderItemValues[$key]['coupon'])
114 );
115 }
116
117 if (!empty($wcOrderItemValues[$key]['tax'])) {
118 $payment->setWcItemTaxValue(new Price($wcOrderItemValues[$key]['tax']));
119 }
120 }
121 }
122
123 if (!empty($data['transactionId'])) {
124 $payment->setTransactionId($data['transactionId']);
125 }
126
127 if (!empty($data['transfers'])) {
128 $payment->setTransfers(new Json($data['transfers']));
129 }
130
131 return $payment;
132 }
133 }
134