for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Copyright © Getnet. All rights reserved.
*
* @author Bruno Elisei <[email protected]>
* See LICENSE for license details.
*/
namespace Getnet\PaymentMagento\Gateway\Request;
use Getnet\PaymentMagento\Gateway\Config\Config;
use Getnet\PaymentMagento\Gateway\SubjectReader;
use InvalidArgumentException;
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
use Magento\Payment\Gateway\Request\BuilderInterface;
* Class Amount Data Request - Payment amount structure.
class AmountDataRequest implements BuilderInterface
{
* Amount block name.
public const AMOUNT = 'amount';
* @var SubjectReader
protected $subjectReader;
* @var Config
protected $config;
* @param SubjectReader $subjectReader
* @param Config $config
public function __construct(
SubjectReader $subjectReader,
Config $config
) {
$this->subjectReader = $subjectReader;
$this->config = $config;
}
* Build.
* @param array $buildSubject
public function build(array $buildSubject)
if (!isset($buildSubject['payment'])
|| !$buildSubject['payment'] instanceof PaymentDataObjectInterface
throw new InvalidArgumentException('Payment data object should be provided');
$paymentDO = $this->subjectReader->readPayment($buildSubject);
$result = [];
$order = $paymentDO->getOrder();
$grandTotal = $order->getGrandTotalAmount();
$result[self::AMOUNT] = $this->config->formatPrice($grandTotal);
return $result;