PaymentViewFactory::createFromPayment()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Factory\User\OrderHistory;
14
15
use BitBag\SyliusVueStorefrontPlugin\View\User\OrderHistory\PaymentView;
16
use Sylius\Component\Core\Model\PaymentInterface;
17
18
final class PaymentViewFactory implements PaymentViewFactoryInterface
19
{
20
    /** @var string */
21
    private $paymentViewClass;
22
23
    public function __construct(string $paymentViewClass)
24
    {
25
        $this->paymentViewClass = $paymentViewClass;
26
    }
27
28
    public function create(PaymentInterface $syliusPayment): PaymentView
29
    {
30
        return $this->createFromPayment($syliusPayment);
31
    }
32
33
    private function createFromPayment(PaymentInterface $syliusPayment): PaymentView
34
    {
35
        /** @var PaymentView $paymentView */
36
        $paymentView = new $this->paymentViewClass();
37
        $paymentView->account_status = null;
38
        $paymentView->additional_information[] = [
39
            $syliusPayment->getMethod() ? $syliusPayment->getMethod()->getName() : 'undefined',
40
        ];
41
        $paymentView->amount_ordered = $syliusPayment->getAmount();
42
        $paymentView->base_amount_ordered = $syliusPayment->getAmount();
43
        $paymentView->base_shipping_amount = $syliusPayment->getOrder()->getShippingTotal();
44
        $paymentView->cc_last4 = null;
45
        $paymentView->entity_id = $syliusPayment->getId();
46
        $paymentView->method = $syliusPayment->getMethod()->getCode();
47
        $paymentView->parent_id = $syliusPayment->getOrder()->getId();
48
        $paymentView->shipping_amount = $syliusPayment->getOrder()->getShippingTotal();
49
50
        return $paymentView;
51
    }
52
}
53