getnet-adquirencia /
payment-magento
| 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\Config\Config; |
||
| 12 | use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
||
| 13 | use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory; |
||
|
0 ignored issues
–
show
|
|||
| 14 | use Getnet\PaymentMagento\Gateway\SubjectReader; |
||
| 15 | use InvalidArgumentException; |
||
| 16 | use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
||
| 17 | use Magento\Payment\Gateway\Request\BuilderInterface; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Class Amount And Interest Data Request - Payment amount structure. |
||
| 21 | */ |
||
| 22 | class AmountAndInterestDataRequest implements BuilderInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Amount block name. |
||
| 26 | */ |
||
| 27 | public const AMOUNT = 'amount'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var SubjectReader |
||
| 31 | */ |
||
| 32 | protected $subjectReader; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var OrderAdapterFactory |
||
| 36 | */ |
||
| 37 | protected $orderAdapterFactory; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var Config |
||
| 41 | */ |
||
| 42 | protected $config; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var ConfigCc |
||
| 46 | */ |
||
| 47 | protected $configCc; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param SubjectReader $subjectReader |
||
| 51 | * @param OrderAdapterFactory $orderAdapterFactory |
||
| 52 | * @param Config $config |
||
| 53 | * @param ConfigCc $configCc |
||
| 54 | */ |
||
| 55 | public function __construct( |
||
| 56 | SubjectReader $subjectReader, |
||
| 57 | OrderAdapterFactory $orderAdapterFactory, |
||
| 58 | Config $config, |
||
| 59 | ConfigCc $configCc |
||
| 60 | ) { |
||
| 61 | $this->subjectReader = $subjectReader; |
||
| 62 | $this->orderAdapterFactory = $orderAdapterFactory; |
||
| 63 | $this->config = $config; |
||
| 64 | $this->configCc = $configCc; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Build. |
||
| 69 | * |
||
| 70 | * @param array $buildSubject |
||
| 71 | */ |
||
| 72 | public function build(array $buildSubject) |
||
| 73 | { |
||
| 74 | if (!isset($buildSubject['payment']) |
||
| 75 | || !$buildSubject['payment'] instanceof PaymentDataObjectInterface |
||
| 76 | ) { |
||
| 77 | throw new InvalidArgumentException('Payment data object should be provided'); |
||
| 78 | } |
||
| 79 | |||
| 80 | $paymentDO = $this->subjectReader->readPayment($buildSubject); |
||
| 81 | |||
| 82 | $result = []; |
||
| 83 | |||
| 84 | $order = $paymentDO->getOrder(); |
||
| 85 | |||
| 86 | $grandTotal = $order->getGrandTotalAmount(); |
||
| 87 | |||
| 88 | $payment = $paymentDO->getPayment(); |
||
| 89 | |||
| 90 | $installment = $payment->getAdditionalInformation('cc_installments') ?: 1; |
||
| 91 | |||
| 92 | $total = $grandTotal; |
||
| 93 | |||
| 94 | $result[self::AMOUNT] = $this->config->formatPrice($total); |
||
| 95 | |||
| 96 | if ($installment > 1) { |
||
| 97 | $storeId = $order->getStoreId(); |
||
| 98 | $amountInterest = $this->configCc->getInterestToAmount($installment, $grandTotal, $storeId); |
||
| 99 | $total = $grandTotal + $amountInterest; |
||
| 100 | $result[self::AMOUNT] = $this->config->formatPrice($total); |
||
| 101 | } |
||
| 102 | |||
| 103 | return $result; |
||
| 104 | } |
||
| 105 | } |
||
| 106 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths