Skip to content

Commit

Permalink
ECP-8327 Allow saving multiple statedata
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-singhvi committed Nov 23, 2023
1 parent 77fe0d6 commit bfc32fc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/Controller/StoreApi/OrderApi/OrderApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ public function giftcardStateData(SalesChannelContext $context, Request $request
*/
public function deleteGiftCardStateData(SalesChannelContext $context, Request $request): JsonResponse
{
$this->paymentStateDataService->deletePaymentStateDataFromContextToken($context->getToken());
$stateData = json_decode($request->request->get('stateData', ''), true);
$Id = $stateData['id'];
$this->paymentStateDataService->deletePaymentStateData($Id);

return new JsonResponse(['token' => $context->getToken()]);
}
Expand Down
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']);
}

/**
Expand Down
14 changes: 2 additions & 12 deletions src/Service/PaymentStateDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,14 @@ 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);
}
}
}

0 comments on commit bfc32fc

Please sign in to comment.