Issues (139)

Gateway/Request/CustomerDataPixRequest.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Gateway\Request;
10
11
use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory;
0 ignored issues
show
The type Getnet\PaymentMagento\Ga...der\OrderAdapterFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Getnet\PaymentMagento\Gateway\SubjectReader;
13
use InvalidArgumentException;
14
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
15
use Magento\Payment\Gateway\Request\BuilderInterface;
16
17
/**
18
 * Class Customer Data Pix Request - Customer structure.
19
 */
20
class CustomerDataPixRequest implements BuilderInterface
21
{
22
    /**
23
     * Unique user id.
24
     * Required.
25
     */
26
    public const CUSTOMER_ID = 'customer_id';
27
28
    /**
29
     * @var SubjectReader
30
     */
31
    protected $subjectReader;
32
33
    /**
34
     * @var OrderAdapterFactory
35
     */
36
    protected $orderAdapterFactory;
37
38
    /**
39
     * @param SubjectReader       $subjectReader
40
     * @param OrderAdapterFactory $orderAdapterFactory
41
     */
42
    public function __construct(
43
        SubjectReader $subjectReader,
44
        OrderAdapterFactory $orderAdapterFactory
45
    ) {
46
        $this->subjectReader = $subjectReader;
47
        $this->orderAdapterFactory = $orderAdapterFactory;
48
    }
49
50
    /**
51
     * Build.
52
     *
53
     * @param array $buildSubject
54
     */
55
    public function build(array $buildSubject)
56
    {
57
        if (!isset($buildSubject['payment'])
58
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
59
        ) {
60
            throw new InvalidArgumentException('Payment data object should be provided');
61
        }
62
63
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
64
        $payment = $paymentDO->getPayment();
65
        $result = [];
66
67
        /** @var OrderAdapterFactory $orderAdapter * */
68
        $orderAdapter = $this->orderAdapterFactory->create(
69
            ['order' => $payment->getOrder()]
70
        );
71
72
        $billingAddress = $orderAdapter->getBillingAddress();
73
74
        $result[self::CUSTOMER_ID] = $billingAddress->getEmail();
75
76
        return $result;
77
    }
78
}
79