Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sw6.5 #64

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wizmogmbh/ivy-payment",
"description": "Ivy - Sustainable Shopping",
"version": "1.2.6",
"version": "2.0.0",
"type": "shopware-platform-plugin",
"license": "proprietary",
"authors": [
Expand Down Expand Up @@ -49,10 +49,7 @@
}
},
"require": {
"php": "^7.4 || ^8.0",
"guzzlehttp/guzzle": ">=7.3",
"symfony/serializer": ">=5.0",
"shopware/core": ">=6.4.0,<6.5.0"
"shopware/core": "^6.5.0"
},
"conflict": {
"ivy/shopware-payment-plugin": "*"
Expand Down
6 changes: 2 additions & 4 deletions src/Components/CustomObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

namespace WizmoGmbh\IvyPayment\Components;

use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

class CustomObjectNormalizer extends ObjectNormalizer
{
/**
* @param $object
* @param string|null $format
* @param array|null $context
* @param null $format
* @param array $context
* @return array
* @throws ExceptionInterface
*/
public function normalize($object, $format = null, array $context = []): array
{
Expand Down
12 changes: 5 additions & 7 deletions src/Controller/Api/ApiTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
use Symfony\Component\Routing\Annotation\Route;
use WizmoGmbh\IvyPayment\Components\Config\ConfigHandler;

/**
* @Route(defaults={"_routeScope"={"administration"}})
*/
#[Route(
defaults: ["_routeScope" => ["administration"]]
)]
class ApiTestController
{
/**
* @Route(path="/api/_action/ivy-api-test/verify")
*/
#[Route('/api/_action/ivy-api-test/verify')]
public function check(RequestDataBag $dataBag): JsonResponse
{
$env = $dataBag->get('environment');
Expand Down Expand Up @@ -70,7 +68,7 @@ private function checkIntegrationReady(string $url, string $apikey): array
$ivyResponse = $client->post('merchant/app/check-integration-ready', $options);

if ($ivyResponse->getStatusCode() === 200) {
$ivyResponseArray = \json_decode((string) $ivyResponse->getBody(), true);
$ivyResponseArray = \json_decode((string)$ivyResponse->getBody(), true);

$response['success'] = $ivyResponseArray['ready'];
$response['message'] = '';
Expand Down
84 changes: 37 additions & 47 deletions src/Core/Checkout/Payment/Controller/IvyPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace WizmoGmbh\IvyPayment\Core\Checkout\Payment\Controller;

use Doctrine\DBAL\Exception;
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionEntity;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Payment\Cart\Token\TokenFactoryInterfaceV2;
Expand All @@ -17,7 +18,6 @@
use Shopware\Core\Checkout\Payment\Exception\InvalidTransactionException;
use Shopware\Core\Checkout\Payment\Exception\TokenExpiredException;
use Shopware\Core\Checkout\Payment\Exception\UnknownPaymentMethodException;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\Framework\ShopwareHttpException;
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
Expand All @@ -27,15 +27,13 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use WizmoGmbh\IvyPayment\Exception\IvyException;
use WizmoGmbh\IvyPayment\Logger\IvyLogger;
use WizmoGmbh\IvyPayment\Services\IvyPaymentService;
use WizmoGmbh\IvyPayment\Express\Service\ExpressService;
use WizmoGmbh\IvyPayment\Components\Config\ConfigHandler;
use WizmoGmbh\IvyPayment\IvyApi\ApiClient;

/**
* @Route(defaults={"_routeScope"={"storefront"}})
*/

#[Route(defaults: ["_routeScope" => ["storefront"]])]
class IvyPaymentController extends StorefrontController
{
private IvyPaymentService $paymentService;
Expand All @@ -46,39 +44,37 @@ class IvyPaymentController extends StorefrontController

private ExpressService $expressService;

private ConfigHandler $configHandler;

private ApiClient $ivyApiClient;
private string $privateDir;

/**
* @param IvyPaymentService $paymentService
* @param TokenFactoryInterfaceV2 $tokenFactoryInterfaceV2
* @param IvyLogger $logger
* @param ExpressService $expressService
* @param ConfigHandler $configHandler
* @param ApiClient $ivyApiClient
* @param array $privatePath
*/
public function __construct(
IvyPaymentService $paymentService,
IvyPaymentService $paymentService,
TokenFactoryInterfaceV2 $tokenFactoryInterfaceV2,
IvyLogger $logger,
ExpressService $expressService,
ConfigHandler $configHandler,
ApiClient $ivyApiClient
) {
IvyLogger $logger,
ExpressService $expressService,
array $privatePath
)
{
$this->paymentService = $paymentService;
$this->configHandler = $configHandler;
$this->tokenFactoryInterfaceV2 = $tokenFactoryInterfaceV2;
$this->logger = $logger;
$this->logger->setName('WEBHOOK');
$this->expressService = $expressService;
$this->ivyApiClient = $ivyApiClient;
$this->privateDir = $privatePath['config']['root'];;
}

#[Route('/ivypayment/failed-transaction',
name: 'frontend.ivypayment.failed.transaction',
defaults: ["XmlHttpRequest" => true],
methods: ['POST', 'GET']
)]
/**
* @Since("6.0.0.0")
* @Route("/ivypayment/failed-transaction", name="frontend.ivypayment.failed.transaction", methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true})
*
* @throws AsyncPaymentFinalizeException
* @throws CustomerCanceledAsyncPaymentException
* @throws InvalidTransactionException
Expand Down Expand Up @@ -110,22 +106,26 @@ public function failedTransaction(Request $request, SalesChannelContext $salesCh
return new RedirectResponse($finishUrl);
}

#[Route('/ivypayment/update-transaction',
name: 'frontend.ivypayment.update.transaction',
defaults: ["XmlHttpRequest" => true, 'csrf_protected' => false, 'auth_required' => false],
methods: ['POST', 'GET']
)]
/**
* @Since("6.0.0.0")
* @Route("/ivypayment/update-transaction", name="ivypayment.update.transaction", methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true,"csrf_protected"=false,"auth_required"=false})
*
* @throws AsyncPaymentFinalizeException
* @throws CustomerCanceledAsyncPaymentException
* @throws InvalidTransactionException
* @throws TokenExpiredException
* @throws UnknownPaymentMethodException|\Doctrine\DBAL\Exception|\WizmoGmbh\IvyPayment\Exception\IvyException
* @throws UnknownPaymentMethodException|Exception|IvyException
* @psalm-suppress InvalidArrayAccess
*/
public function updateTransaction(Request $request, RequestDataBag $inputData, SalesChannelContext $salesChannelContext): Response
{
$this->logger->setName('WEBHOOK');
$this->logger->info('recieved new webhook');
$type = $request->request->get('type');
/** @var array $payload */
$payload = $request->request->get('payload');
$payload = $inputData->get('payload')?->all();

if (empty($type) || empty($payload)) {
$this->logger->error('bad webhook request');
Expand All @@ -147,7 +147,7 @@ public function updateTransaction(Request $request, RequestDataBag $inputData, S
}

if (!isset($payload['status'])) {
$this->logger->error('bad webhook request');
$this->logger->error('bad webhook request, status not set');
return new JsonResponse(['success' => false, 'error' => 'bad webhook request'], Response::HTTP_BAD_REQUEST);
}

Expand All @@ -162,7 +162,8 @@ public function updateTransaction(Request $request, RequestDataBag $inputData, S
$referenceId = $payload['referenceId'];
$ivyOrderId = $payload['id'];
$lockName = 'ivylock_' . $ivyOrderId . '.lock';
$tmpdir = \sys_get_temp_dir();
$tmpdir = $this->privateDir;

$fp = \fopen($tmpdir . $lockName, 'wb');

$count = 0;
Expand Down Expand Up @@ -204,20 +205,6 @@ public function updateTransaction(Request $request, RequestDataBag $inputData, S
/** @var OrderEntity $order */
[$order, $token] = $this->expressService->checkoutConfirm($inputData, $payload, $salesChannelContext);

$config = $this->configHandler->getFullConfig($salesChannelContext);

$this->logger->info('update order over ivy api');
$ivyResponse = $this->ivyApiClient->sendApiRequest('order/update', $config, \json_encode([
'id' => $ivyOrderId,
'displayId' => $order->getOrderNumber(),
'referenceId' => $order->getId(),
'metadata' => [
'_sw_payment_token' => $token,
'shopwareOrderId' => $order->getOrderNumber()
]
]));
$this->logger->info('ivy response: ' . \print_r($ivyResponse, true));

$outputData = [
"success" => true
];
Expand All @@ -242,14 +229,17 @@ public function updateTransaction(Request $request, RequestDataBag $inputData, S
}

$this->logger->debug('webhook finished <== ' . $type);


unlink($tmpdir . $lockName);
return new JsonResponse(null, Response::HTTP_OK);
}

#[Route('/ivypayment/finalize-transaction',
name: 'frontend.ivypayment.finalize.transaction',
defaults: ["XmlHttpRequest" => true],
methods: ['POST', 'GET']
)]
/**
* @Since("6.0.0.0")
* @Route("/ivypayment/finalize-transaction", name="frontend.ivypayment.finalize.transaction", methods={"GET", "POST"}, defaults={"XmlHttpRequest"=true})
*
* @throws AsyncPaymentFinalizeException
* @throws CustomerCanceledAsyncPaymentException
* @throws InvalidTransactionException
Expand Down
16 changes: 6 additions & 10 deletions src/Core/IvyPayment/IvyCheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\PlatformRequest;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Framework\Routing\Router;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Serializer;
Expand All @@ -34,17 +32,14 @@ class IvyCheckoutSession

private string $version;

private RouterInterface $router;

public function __construct(
EntityRepository $pluginRepository,
ConfigHandler $configHandler,
EntityRepository $pluginRepository,
ConfigHandler $configHandler,
createIvyOrderData $createIvyOrderData,
ApiClient $ivyApiClient,
RouterInterface $router
) {
ApiClient $ivyApiClient,
)
{
$this->configHandler = $configHandler;
$this->router = $router;
$this->createIvyOrderData = $createIvyOrderData;
$this->ivyApiClient = $ivyApiClient;
$encoders = [new XmlEncoder(), new JsonEncoder()];
Expand All @@ -62,6 +57,7 @@ public function __construct(
* @param SalesChannelContext $salesChannelContext
* @param bool $express
* @param OrderEntity|null $order
* @param Cart|null $cart
* @return string
* @throws Exception
* @throws IvyApiException
Expand Down
Loading