-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathBuckarooRestOrderData.php
71 lines (64 loc) · 2.19 KB
/
BuckarooRestOrderData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the MIT License
* It is available through the world-wide-web at this URL:
* https://tldrlegal.com/license/mit-license
* If you are unable to obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact [email protected] for more information.
*
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/
namespace Buckaroo\Magento2\Model;
use Buckaroo\Magento2\Helper\PaymentGroupTransaction;
use Buckaroo\Magento2\Api\Data\BuckarooRestOrderDataInterface;
use Buckaroo\Magento2\Api\Data\Giftcard\TransactionResponseInterfaceFactory;
class BuckarooRestOrderData implements BuckarooRestOrderDataInterface
{
private string $orderIncrementId;
private PaymentGroupTransaction $groupTransaction;
/**
* @var TransactionResponseInterfaceFactory
*/
private $trResponseFactory;
public function __construct(
string $orderIncrementId,
PaymentGroupTransaction $groupTransaction,
TransactionResponseInterfaceFactory $trResponseFactory
) {
$this->orderIncrementId = $orderIncrementId;
$this->groupTransaction = $groupTransaction;
$this->trResponseFactory = $trResponseFactory;
}
/**
* @return \Buckaroo\Magento2\Api\Data\Giftcard\TransactionResponseInterface[]
*/
public function getGroupTransactions() {
return $this->formatFound(
$this->groupTransaction->getActiveItemsWithName(
$this->orderIncrementId
)
);
}
/**
* Format data for json response
*
* @param array $collection
*
* @return \Buckaroo\Magento2\Api\Data\Giftcard\TransactionResponseInterface[]
*/
protected function formatFound(array $collection)
{
return array_map(function ($item) {
return $this->trResponseFactory->create()->addData($item->getData());
}, $collection);
}
}