Write PHP/Symfony code to integrate Aplazame payment system in style of current code:

<?php

namespace BillingBundle\Controller\PaymentSystem;

use BillingBundle\Controller\PaymentController;
use BillingBundle\Entity\Payment;
use BillingBundle\Entity\PaymentMethod;
use BillingBundle\Entity\ProofOfPayments;
use BillingBundle\Handler\DonePaymentHandler;
use BillingBundle\Handler\PaymentSystem\PledgHandler;
use BillingBundle\Payum\KlarnaGateway\Action\CaptureAction;
use BillingBundle\Payum\KlarnaGateway\Action\CreateClientAction;
use BillingBundle\Payum\KlarnaGateway\DataProvider\DataProvider;
use CartBundle\Entity\Purchase;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

//https://docs.klarna.com/resources/test-environment/sample-customer-data/#spain
//https://docs.klarna.com/klarna-payments/integrate-with-klarna-payments/step-2-check-out/22-get-authorization/

//insert paymentmethods (`code`, `name`, `description`, `is_enabled`, `type`) values ('KLARNA', 'Klarna', 'Klarna payment', 1, 'CARD');
class KlarnaController extends Controller
{
    public function initiatePaymentAction(Request $request)
    {
        /** @var CaptureAction $captureAction */
        $captureAction = $this->get("pf_payment.klarna.capture");
        $purchaseId = $request->request->get("purchase");
        /** @var Purchase|null $purchase */
        $purchase = $this->getDoctrine()->getRepository(Purchase::class)->find($purchaseId);

        $response = $captureAction->initiatePayment($purchase, $request->getLocale());

        return $this->json($response);
    }

    public function authorizePaymentAction(Request $request)
    {
        /** @var DataProvider $provider */
        $provider = $this->get("billing.payum.klarna_gateway.data_provider.data_provider");

        $purchaseId = $request->request->get("purchase");
        /** @var Purchase $purchase */
        $purchase = $this->getDoctrine()->getRepository(Purchase::class)->find($purchaseId);

        $payment = $provider->createPayment($purchase);

        $this->getDoctrine()->getManager()->flush();

        return $this->json([
            "purchaseData" => $provider->getAuthorizePaymentData($purchase, $request->getLocale()),
            "paymentId" => $payment->getId(),
        ]);
    }

    public function failPaymentAction(Request $request, $id)
    {
        /** @var DataProvider $provider */
        $provider = $this->get("billing.payum.klarna_gateway.data_provider.data_provider");
        $paymentId = $request->request->get("paymentId");
        $klarnaResponse = $request->request->get("klarnaResponse", []);

        /** @var Purchase $purchase */
        $purchase = $this->getDoctrine()->getRepository(Purchase::class)->find($id);

        $provider->saveError($purchase, $paymentId, $klarnaResponse);

        if(!$paymentId){
            $this->get('session')->getFlashBag()->add('error',
                $this->get('translator')->trans('text.problemPayment', [], 'payment'));
        }

        return $this->json([]);
    }

    public function createOrderAction(Request $request, $id)
    {
        /** @var CaptureAction $captureAction */
        $captureAction = $this->get("pf_payment.klarna.capture");
        $klarnaResponse = $request->request->get("klarnaResponse", []);

        if(!is_array($klarnaResponse) || !isset($klarnaResponse["authorization_token"])){
            return $this->json(["redirectUrl" => $this->generateUrl("billing.payment_system.redirect3ds.exception_notification", ["id" => $id])]);
        }

        /** @var Payment $payment */
        $payment = $this->getDoctrine()->getRepository(Payment::class)->find($id);

        $response = $captureAction->createOrder($payment, $klarnaResponse, $request->getLocale());

        if(isset($response["error"])){
            return $this->json(["redirectUrl" => $this->generateUrl("billing.payment_system.redirect3ds.exception_notification", ["id" => $id])]);
        }
        elseif(isset($response["redirectUrl"])) {
            return $this->json(["redirectUrl" => $response["redirectUrl"]]);
        }

        return $this->json(["redirectUrl" => $this->generateUrl("billing.payment_system.redirect3ds.success_notification", ["id" => $id])]);
    }

    public function confirmationPaymentAction(Request $request, $id)
    {
        $klarnaResponse = $request->request->all();

        /** @var Payment $payment */
        $payment = $this->getDoctrine()->getRepository(Payment::class)->find($id);

        $extra = $payment->getParsedExtra();

        $extra["klarna_confirmation"] = $klarnaResponse;

        $payment->setExtra(json_encode($extra));

        $this->getDoctrine()->getManager()->flush();

        return $this->redirectToRoute("billing.payment_system.redirect3ds.success_notification", ["id" => $id]);
    }

    public function webhookNotificationsAction(Request $request)
    {
        $allData = $request->request->all();

        if(!is_array($allData) || !isset($allData["event_type"]) || $allData["event_type"] !== "order.created"){
            return $this->json(["success" => 1]);
        }

        /** @var EntityManagerInterface $em */
        $em = $this->getDoctrine()->getManager();

        $proof = new ProofOfPayments();
        $proof->setOrderId($allData["order"]["merchant_reference1"]);
        $proof->setStatus($allData["event_type"]);
        $proof->setDate(new DateTime());
        $proof->setMetaData(json_encode($allData));
        $proof->setPaymentMethodCode(PaymentMethod::KLARNA_CODE);

        $em->persist($proof);
        $em->flush();

        return $this->json(["success" => 2]);
    }

    public function registerClientAction(Request $request)
    {
        $clientData = $request->request->all();
        /** @var CreateClientAction $createService */
        $createService = $this->get("pf_payment.klarna.create_client");

        try {
            if(!$createService->isValidData($clientData)){
                return $this->json(["success" => false]);
            }

            $createService->registerClient($clientData, $request->getLocale());
        }
        catch (\Exception $exception){
            return $this->json(["success" => false]);
        }

        return $this->json([
            "success" => true,
            "redirectUrl" => $this->generateUrl("cart_shipping"),
        ]);
    }
}