|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WSW\SiftScience\Transformers; |
|
4
|
|
|
|
|
5
|
|
|
use WSW\SiftScience\Collections\Items; |
|
6
|
|
|
use WSW\SiftScience\Collections\PaymentMethods; |
|
7
|
|
|
use WSW\SiftScience\Collections\Promotions; |
|
8
|
|
|
use WSW\SiftScience\Entities\Address; |
|
9
|
|
|
use WSW\SiftScience\Events\CreateOrder; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class CreateOrderTransformer |
|
13
|
|
|
* |
|
14
|
|
|
* @package WSW\SiftScience\Transformers |
|
15
|
|
|
* @author Ronaldo Matos Rodrigues <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class CreateOrderTransformer extends AbstractTransformer |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param CreateOrder $createOrder |
|
21
|
|
|
* |
|
22
|
|
|
* @return array |
|
23
|
|
|
*/ |
|
24
|
|
|
public function transform(CreateOrder $createOrder) |
|
25
|
|
|
{ |
|
26
|
|
|
return array_filter([ |
|
27
|
|
|
'$type' => $createOrder->getType(), |
|
28
|
|
|
'$api_key' => $createOrder->getApiKey(), |
|
29
|
|
|
'$user_id' => $createOrder->getUserId(), |
|
30
|
|
|
'$session_id' => $createOrder->getSession(), |
|
31
|
|
|
'$order_id' => $createOrder->getOrder(), |
|
32
|
|
|
'$user_email' => $createOrder->getUserEmail()->getEmail(), |
|
33
|
|
|
'$amount' => $createOrder->getAmount()->getMicros(), |
|
34
|
|
|
'$currency_code' => $createOrder->getAmount()->getCurrency()->getCode(), |
|
35
|
|
|
'$billing_address' => $this->address($createOrder->getBillingAddress()), |
|
36
|
|
|
'$payment_methods' => $this->paymentMethods($createOrder->getPaymentMethods()), |
|
37
|
|
|
'$shipping_address' => $this->address($createOrder->getShippingAddress()), |
|
38
|
|
|
'$expedited_shipping' => $createOrder->isExpeditedShipping(), |
|
39
|
|
|
'$shipping_method' => $createOrder->getShippingMethod(), |
|
40
|
|
|
'$items' => $this->items($createOrder->getItems()), |
|
41
|
|
|
'$seller_user_id' => $createOrder->getSellerUserId(), |
|
42
|
|
|
'$promotions' => $this->promotions($createOrder->getPromotions()) |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Address $address |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function address(Address $address) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->loadItem($address, new AddressTransformer()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param PaymentMethods $collection |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function paymentMethods(PaymentMethods $collection) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->loadCollection($collection->getValues(), new PaymentMethodTransformer); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param Items $items |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function items(Items $items) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->loadCollection($items->getValues(), new ItemTransformer); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param Promotions $promotions |
|
78
|
|
|
* |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function promotions(Promotions $promotions) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->loadCollection($promotions->getValues(), new PromotionTransformer); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|