1 <?php
2 3 4
5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy;
6
7 use Team3\PayU\Order\Model\OrderInterface;
8 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
9 use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp;
10 use Team3\PayU\PropertyExtractor\ExtractorResult;
11
12 class GeneralTransformer implements UserOrderTransformerStrategyInterface
13 {
14 15 16
17 public function transform(
18 OrderInterface $order,
19 ExtractorResult $extractorResult
20 ) {
21 $this->copyValue(
22 $order,
23 $extractorResult->getPropertyName(),
24 $extractorResult->getValue()
25 );
26 }
27
28 29 30 31 32
33 public function supports($propertyName)
34 {
35 return 1 === preg_match(
36 TransformerPropertiesRegExp::GENERAL_REGEXP,
37 $propertyName
38 );
39 }
40
41 42 43 44 45
46 private function copyValue(
47 OrderInterface $order,
48 $propertyName,
49 $value
50 ) {
51 switch ($propertyName) {
52 case TransformerProperties::GENERAL_CUSTOMER_IP:
53 $order->setCustomerIp($value);
54 break;
55 case TransformerProperties::GENERAL_ORDER_ID:
56 $order->setOrderId($value);
57 break;
58 case TransformerProperties::GENERAL_ADDITIONAL_DESC:
59 $order->setAdditionalDescription($value);
60 break;
61 case TransformerProperties::GENERAL_CURRENCY_CODE:
62 $order->setCurrencyCode($value);
63 break;
64 case TransformerProperties::GENERAL_DESCRIPTION:
65 $order->setDescription($value);
66 break;
67 case TransformerProperties::GENERAL_MERCHANT_POS_ID:
68 $order->setMerchantPosId($value);
69 break;
70 case TransformerProperties::GENERAL_SIGNATURE:
71 $order->setSignature($value);
72 break;
73 case TransformerProperties::GENERAL_TOTAL_AMOUNT:
74 $order->setTotalAmount($value);
75 break;
76 default:
77 }
78 }
79 }
80