1 | <?php |
||
15 | class BatchPurchaseStrategy implements PurchaseStrategyInterface |
||
16 | { |
||
17 | use PurchaseResultTrait; |
||
18 | |||
19 | /** |
||
20 | * @var AbstractCartPosition[] |
||
21 | */ |
||
22 | protected $positions = []; |
||
23 | |||
24 | /** |
||
25 | * @var ShoppingCart |
||
26 | */ |
||
27 | protected $cart; |
||
28 | |||
29 | /** |
||
30 | * @var AbstractPurchase[] |
||
31 | */ |
||
32 | protected $purchases; |
||
33 | |||
34 | /** |
||
35 | * BatchPurchaseStrategy constructor. |
||
36 | * |
||
37 | * @param ShoppingCart $cart |
||
38 | */ |
||
39 | public function __construct(ShoppingCart $cart) |
||
43 | |||
44 | /** {@inheritdoc} */ |
||
45 | public function addPosition(AbstractCartPosition $position) |
||
50 | |||
51 | /** {@inheritdoc} */ |
||
52 | public function run() |
||
70 | |||
71 | private function createPurchaseObjects() |
||
77 | |||
78 | private function collectData() |
||
93 | |||
94 | private function extractResultsFromException(ResponseErrorException $e) |
||
105 | |||
106 | protected function analyzeResponse($response) { |
||
111 | |||
112 | protected function analyzeResponseItem($key, $data) |
||
127 | |||
128 | /** |
||
129 | * @param AbstractPurchase $purchase |
||
130 | * @param array $data |
||
131 | * @return null|string Error message or `null` when no errors found |
||
132 | */ |
||
133 | protected function getPurchaseErrorFromResponse(AbstractPurchase $purchase, $data) |
||
141 | |||
142 | /** |
||
143 | * Override this method to detect pending purchase result. |
||
144 | * |
||
145 | * @param AbstractPurchase $purchase |
||
146 | * @param array $data |
||
147 | * @return null|string Pending reason or `null` when no errors found |
||
148 | */ |
||
149 | protected function getPurchasePendingFromResponse(AbstractPurchase $purchase, $data) |
||
153 | |||
154 | protected function ensureConsistency() |
||
167 | } |
||
168 |