1 <?php
2 3 4
5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy;
6
7 use Team3\PayU\Order\Model\Buyer\InvoiceInterface;
8 use Team3\PayU\Order\Model\OrderInterface;
9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp;
11 use Team3\PayU\PropertyExtractor\ExtractorResult;
12
13 class InvoiceTransformer implements UserOrderTransformerStrategyInterface
14 {
15 16 17
18 public function transform(
19 OrderInterface $order,
20 ExtractorResult $extractorResult
21 ) {
22 $this
23 ->copyValue(
24 $order->getBuyer()->getInvoice(),
25 $extractorResult->getPropertyName(),
26 $extractorResult->getValue()
27 )
28 ->copyRecipientValue(
29 $order->getBuyer()->getInvoice(),
30 $extractorResult->getPropertyName(),
31 $extractorResult->getValue()
32 );
33 }
34
35 36 37
38 public function supports($propertyName)
39 {
40 return 1 === preg_match(
41 TransformerPropertiesRegExp::INVOICE_REGEXP,
42 $propertyName
43 );
44 }
45
46 47 48 49 50 51
52 private function copyValue(
53 InvoiceInterface $invoice,
54 $propertyName,
55 $value
56 ) {
57 switch ($propertyName) {
58 case TransformerProperties::INVOICE_CITY:
59 $invoice->setCity($value);
60 break;
61 case TransformerProperties::INVOICE_COUNTRY_CODE:
62 $invoice->setCountryCode($value);
63 break;
64 case TransformerProperties::INVOICE_E_INVOICE_REQUESTED:
65 $invoice->setEInvoiceRequested($value);
66 break;
67 case TransformerProperties::INVOICE_NAME:
68 $invoice->setName($value);
69 break;
70 case TransformerProperties::INVOICE_POSTAL_CODE:
71 $invoice->setPostalCode($value);
72 break;
73 case TransformerProperties::INVOICE_STREET:
74 $invoice->setStreet($value);
75 break;
76 }
77
78 return $this;
79 }
80
81 82 83 84 85 86
87 private function copyRecipientValue(
88 InvoiceInterface $invoice,
89 $propertyName,
90 $value
91 ) {
92 switch ($propertyName) {
93 case TransformerProperties::INVOICE_RECIPIENT_EMAIL:
94 $invoice->setRecipientEmail($value);
95 break;
96 case TransformerProperties::INVOICE_RECIPIENT_NAME:
97 $invoice->setRecipientName($value);
98 break;
99 case TransformerProperties::INVOICE_RECIPIENT_PHONE:
100 $invoice->setRecipientPhone($value);
101 break;
102 case TransformerProperties::INVOICE_RECIPIENT_TIN:
103 $invoice->setRecipientTin($value);
104 break;
105 }
106
107 return $this;
108 }
109 }
110