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

[ECP-8327] Saving multiple Statedata #444

Merged
merged 9 commits into from
Jan 9, 2024
13 changes: 9 additions & 4 deletions src/Controller/StoreApi/OrderApi/OrderApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,15 @@ public function giftcardStateData(SalesChannelContext $context, Request $request
* @param Request $request
* @return JsonResponse
*/
public function deleteGiftCardStateData(SalesChannelContext $context, Request $request): JsonResponse
public function deleteGiftCardStateData(SalesChannelContext $context, Request $request)
khushboo-singhvi marked this conversation as resolved.
Show resolved Hide resolved
{
$this->paymentStateDataService->deletePaymentStateDataFromContextToken($context->getToken());

return new JsonResponse(['token' => $context->getToken()]);
$stateData = json_decode($request->request->get('stateData', ''), true);
if (!empty($stateData)) {
khushboo-singhvi marked this conversation as resolved.
Show resolved Hide resolved
$Id = $stateData['id'];
$this->paymentStateDataService->deletePaymentStateData($Id);
return new JsonResponse(['token' => $context->getToken()]);
}
else
khushboo-singhvi marked this conversation as resolved.
Show resolved Hide resolved
return new JsonResponse('StateData is not available.');
khushboo-singhvi marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 2 additions & 2 deletions src/Handlers/AbstractPaymentMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public function pay(

if ($storedStateData) {
// Remove the used state.data
$this->paymentStateDataService->deletePaymentStateDataFromContextToken($salesChannelContext->getToken());
$this->paymentStateDataService->deletePaymentStateData($storedStateData['id']);
}

try {
Expand Down Expand Up @@ -870,7 +870,7 @@ public function handleAdyenOrderPayment(
) - $partialAmount;

// Remove the used state.data
$this->paymentStateDataService->deletePaymentStateDataFromContextToken($salesChannelContext->getToken());
$this->paymentStateDataService->deletePaymentStateData($storedStateData['id']);
khushboo-singhvi marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
15 changes: 2 additions & 13 deletions src/Service/PaymentStateDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,13 @@ public function updateStateDataContextToken(PaymentStateDataEntity $stateData, $
/**
* @param PaymentStateDataEntity $stateData
*/
public function deletePaymentStateData(PaymentStateDataEntity $stateData): void
public function deletePaymentStateData(string $Id): void
{
$this->paymentStateDataRepository->delete(
[
['id' => $stateData->getId()],
['id' => $Id],
],
Context::createDefaultContext()
);
}

/**
* @param string $contextToken
*/
public function deletePaymentStateDataFromContextToken(string $contextToken): void
{
$stateData = $this->getPaymentStateDataFromContextToken($contextToken);
if (!empty($stateData)) {
$this->deletePaymentStateData($stateData);
}
}
}
Loading