Passed
Branch [email protected] (8a736f)
by Bruno
13:13
created

ExtOrdIdBoletoHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 3
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\Response;
10
11
use InvalidArgumentException;
12
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
13
use Magento\Payment\Gateway\Response\HandlerInterface;
14
15
/**
16
 * External Ordor Id Boleto Handler - Set the Getnet Order Id.
17
 */
18
class ExtOrdIdBoletoHandler implements HandlerInterface
19
{
20
    /**
21
     * Response Pay Boleto - Block name.
22
     */
23
    public const RESPONSE_BOLETO = 'boleto';
24
25
    /**
26
     * @const string
27
     */
28
    public const RESPONSE_BOLETO_ID = 'boleto_id';
29
30
    /**
31
     * Handles.
32
     *
33
     * @param array $handlingSubject
34
     * @param array $response
35
     *
36
     * @return void
37
     */
38
    public function handle(array $handlingSubject, array $response)
39
    {
40
        if (!isset($handlingSubject['payment'])
41
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
42
        ) {
43
            throw new InvalidArgumentException('Payment data object should be provided');
44
        }
45
46
        $paymentDO = $handlingSubject['payment'];
47
48
        $payment = $paymentDO->getPayment();
49
50
        $order = $payment->getOrder();
51
52
        $payBoleto = $response[self::RESPONSE_BOLETO];
53
54
        $order->setExtOrderId($payBoleto[self::RESPONSE_BOLETO_ID]);
55
    }
56
}
57