Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Novalnet-Technic committed Oct 27, 2023
0 parents commit e090579
Show file tree
Hide file tree
Showing 444 changed files with 30,980 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Client/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Novalnet\Bundle\NovalnetBundle\Client;

use GuzzleHttp\ClientInterface;

/**
* Handle Novalnet payport API request and response
*/
class Gateway implements GatewayInterface
{
/** @var ClientInterface */
protected $httpClient;

/**
* @param ClientInterface $httpClient
*/
public function __construct(ClientInterface $httpClient)
{
$this->httpClient = $httpClient;
}

/** {@inheritdoc} */
public function send($paymentAccessKey, $parameters, $hostAddress)
{
$encodedData = base64_encode($paymentAccessKey);
$headers = [
'Content-Type' => 'application/json',
'charset' => 'utf-8',
'Accept' => 'application/json',
'X-NN-Access-Key' => $encodedData,
];

$response = $this->httpClient->request(
'POST',
$hostAddress,
$this->getRequestOptions($parameters, $headers)
);
$result = json_decode($response->getBody(true), true);
return $result;
}

/**
* @param object $config
* @return array
*/
protected function getRequestOptions($parameters, $headers)
{
$requestOptions = [
'json' => $parameters,
'headers' => $headers
];

return $requestOptions;
}
}
16 changes: 16 additions & 0 deletions Client/GatewayInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Novalnet\Bundle\NovalnetBundle\Client;

/**
* Interface for Handle Novalnet payport API request and response
*/
interface GatewayInterface
{
/**
* @param string $paymentAccessKey
* @param array $parameters
* @param string $hostAddress
*/
public function send($paymentAccessKey, $parameters, $hostAddress);
}
57 changes: 57 additions & 0 deletions Controller/Frontend/AjaxNovalnetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Novalnet\Bundle\NovalnetBundle\Controller\Frontend;

use Oro\Bundle\CheckoutBundle\Entity\Checkout;
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor;
use Oro\Bundle\SecurityBundle\Annotation\CsrfProtection;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Novalnet\Bundle\NovalnetBundle\Entity\NovalnetTransactionDetails;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Oro\Bundle\EntityBundle\ORM\DoctrineHelper;

/**
* Ajax Novalnet Controller
*/
class AjaxNovalnetController extends AbstractController
{
/**
* @Route(
* "/remove-payment-data/{id}",
* name="novalnet_frontend_ajax_remove_payment_data",
* requirements={"id"="\d+"},
* methods={"POST"}
* )
* @ParamConverter("paymentTransaction", class="NovalnetBundle:NovalnetTransactionDetails", options={"id" = "id"})
* @param NovalnetTransactionDetails $novalnetTransactionDetails
* @return JsonResponse
*/
public function removePaymentDataAction(NovalnetTransactionDetails $novalnetTransactionDetails)
{
$success = true;
try {
$doctrineHelper = $this->get(DoctrineHelper::class);
$novalnetTransactionDetails->setToken(null);
$novalnetTransactionDetails->setPaymentData(null);
$entityManager = $doctrineHelper->getEntityManager('NovalnetBundle:NovalnetTransactionDetails');
$entityManager->persist($novalnetTransactionDetails);
$entityManager->flush();
} catch (\Exception $exception) {
$success = false;
}

return new JsonResponse(['successful' => $success]);
}

/**
* {@inheritdoc}
*/
public static function getSubscribedServices()
{
return array_merge(parent::getSubscribedServices(), [
DoctrineHelper::class
]);
}
}
Loading

0 comments on commit e090579

Please sign in to comment.