RefundCommandPlugin   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 41
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 28 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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...
11
use Generated\Shared\Transfer\PayonePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentTransfer 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 Generated\Shared\Transfer\PayoneRefundTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneRefundTransfer 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...
13
use Orm\Zed\Sales\Persistence\SpySalesOrder;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder 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...
14
use Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
15
use Spryker\Zed\Oms\Communication\Plugin\Oms\Command\CommandByOrderInterface;
16
use SprykerEco\Shared\Payone\PayoneApiConstants;
17
18
/**
19
 * @method \SprykerEco\Zed\Payone\Communication\PayoneCommunicationFactory getFactory()
20
 * @method \SprykerEco\Zed\Payone\Business\PayoneFacadeInterface getFacade()
21
 */
22
class RefundCommandPlugin extends AbstractPayonePlugin implements CommandByOrderInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Spryker\Zed\Oms\Communic...CommandByOrderInterface has been deprecated: Use {@link \Spryker\Zed\Oms\Dependency\Plugin\Command\CommandByOrderInterface} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
class RefundCommandPlugin extends AbstractPayonePlugin implements /** @scrutinizer ignore-deprecated */ CommandByOrderInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
23
{
24
    /**
25
     * {@inheritDoc}
26
     *
27
     * @api
28
     *
29
     * @param array $orderItems
30
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $orderEntity
31
     * @param \Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject $data
32
     *
33
     * @return array
34
     */
35
    public function run(array $orderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
36
    {
37
        $payoneRefundTransfer = new PayoneRefundTransfer();
38
39
        $orderTransfer = new OrderTransfer();
40
        $orderTransfer->fromArray($orderEntity->toArray(), true);
41
42
        $refundTransfer = $this->getFactory()
43
            ->getRefundFacade()
44
            ->calculateRefund($orderItems, $orderEntity);
45
46
        $payoneRefundTransfer->setAmount($refundTransfer->getAmount() * -1);
47
48
        $paymentPayoneEntity = $orderEntity->getSpyPaymentPayones()->getFirst();
49
50
        $payonePaymentTransfer = new PayonePaymentTransfer();
51
        $payonePaymentTransfer->fromArray($paymentPayoneEntity->toArray(), true);
52
53
        $payoneRefundTransfer->setPayment($payonePaymentTransfer);
54
        $payoneRefundTransfer->setUseCustomerdata(PayoneApiConstants::USE_CUSTOMER_DATA_YES);
55
        $payoneRefundTransfer->setOrder($this->getOrderTransfer($orderEntity));
56
57
        $narrativeText = $this->getFactory()->getConfig()->getNarrativeText($orderItems, $orderEntity, $data);
58
        $payoneRefundTransfer->setNarrativeText($narrativeText);
59
60
        $this->getFacade()->refundPayment($payoneRefundTransfer);
61
62
        return [];
63
    }
64
}
65