<?php

namespace KupShop\GTMBundle\Ecommerce;

class AddPaymentInfo extends AbstractEcommerce
{
    /**
     * Specific PageData.
     *
     * @throws \Exception
     */
    public function getData(&$dataContainer)
    {
        /** @var \Payment $delivery */
        $payment = $this->pageData['payment'];

        if ($method = ($this->pageData['method'] ?? false)) {
            $paymentType = $method['name'];
        } else {
            $paymentType = is_object($payment['class']) ? $payment['class']->getName() : $payment['name'];
        }

        $dataContainer->event = 'addPaymentInfo';
        $dataContainer->addPaymentInfo = new \stdClass();
        $dataContainer->addPaymentInfo->paymentType = $paymentType;
        $dataContainer->addPaymentInfo->payment = [
            'type' => $payment['name'] ?? '',
            'method' => [
                'id' => $method['id'] ?? null,
            ],
        ];
    }
}
