Skip to content

Commit

Permalink
[ECP-9206-v3] Adyen related tables missing for giftcard payments on a…
Browse files Browse the repository at this point in the history
…dmin panel (#506)

* [ECP-9206-v3] Update Adyen order check logic by using order transaction instead of original psp-reference and create and end point for this check

* [ECP-9206-v3] Update catch exception message

* [ECP-9206-v3] Remove context parameter

* [ECP-9206-v3] Fix return type in checking adyen orders

* [ECP-9206-v3] Update v3 specific annotation syntax, return false from isAdyenOrder() instead of throwing error in case of failure

* [ECP-9206-v3] Remove extra line from annotation

---------

Co-authored-by: sushmita <[email protected]>
  • Loading branch information
SushmitaThakur and sushmita authored Jul 17, 2024
1 parent b2d338d commit 00dd37b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
35 changes: 34 additions & 1 deletion src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Adyen\Shopware\Entity\AdyenPayment\AdyenPaymentEntity;
use Adyen\Shopware\Entity\Notification\NotificationEntity;
use Adyen\Shopware\Exception\CaptureException;
use Adyen\Shopware\Provider\AdyenPluginProvider;
use Adyen\Shopware\Service\AdyenPaymentService;
use Adyen\Shopware\Service\CaptureService;
use Adyen\Shopware\Service\ConfigurationService;
Expand Down Expand Up @@ -96,6 +97,9 @@ class AdminController
/** @var OrderTransactionRepository */
private $orderTransactionRepository;

/** @var AdyenPluginProvider */
private AdyenPluginProvider $pluginProvider;

/**
* AdminController constructor.
*
Expand All @@ -111,6 +115,7 @@ class AdminController
* @param ConfigurationService $configurationService
* @param AdyenPaymentService $adyenPaymentService
* @param OrderTransactionRepository $orderTransactionRepository
* @param AdyenPluginProvider $pluginProvider
*/
public function __construct(
LoggerInterface $logger,
Expand All @@ -124,7 +129,8 @@ public function __construct(
Currency $currencyUtil,
ConfigurationService $configurationService,
AdyenPaymentService $adyenPaymentService,
OrderTransactionRepository $orderTransactionRepository
OrderTransactionRepository $orderTransactionRepository,
AdyenPluginProvider $pluginProvider
) {
$this->logger = $logger;
$this->orderRepository = $orderRepository;
Expand All @@ -138,6 +144,7 @@ public function __construct(
$this->configurationService = $configurationService;
$this->adyenPaymentService = $adyenPaymentService;
$this->orderTransactionRepository = $orderTransactionRepository;
$this->pluginProvider = $pluginProvider;
}

/**
Expand Down Expand Up @@ -535,4 +542,30 @@ public function rescheduleNotification(string $notificationId): JsonResponse

return new JsonResponse($notificationId);
}

/**
* @Route(
* "/api/adyen/orders/{orderId}/is-adyen-order",
* name="api.adyen_is_adyen_order.get",
* methods={"GET"}
* )
*
* @param string $orderId
* @return JsonResponse
*/
public function isAdyenOrder(string $orderId): JsonResponse
{
try {
$transaction = $this->orderTransactionRepository->getFirstAdyenOrderTransaction($orderId);

if (!is_null($transaction)) {
return new JsonResponse(['status' => true]);
}

return new JsonResponse(['status' => false]);
} catch (Throwable $t) {
$this->logger->error($t->getMessage());
return new JsonResponse(['message' => 'adyen.error'], 500);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Component.register('adyen-notifications', {
}
},

beforeMount() {
this.showWidget = this.adyenService.isAdyenOrder(this.order);
async beforeMount() {
this.showWidget = await this.adyenService.isAdyenOrder(this.order);
if (this.showWidget) {
this.fetchNotifications();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Component.register('adyen-partial-payments', {
}
},

beforeMount() {
async beforeMount() {
this.isVersionOlderThan65 = VersionHelper.isVersionOlderThan65();
this.showWidget = this.adyenService.isAdyenOrder(this.order);
this.showWidget = await this.adyenService.isAdyenOrder(this.order);

if (this.showWidget) {
this.fetchAdyenPartialPayments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,11 @@ Component.register('adyen-refund', {
}

this.allowRefund = this.order.amountTotal > (refundedAmount / 100);
},

isAdyenOrder() {
const orderTransactions = this.order.transactions;
let isAdyen = false;
for (let i = 0; i < orderTransactions.length; i++) {
if (orderTransactions[i].customFields !== undefined) {
if (orderTransactions[i].customFields.originalPspReference !== undefined) {
isAdyen = true;
}
}
}

this.showWidget = isAdyen;
}
},

beforeMount() {
this.isAdyenOrder();
async beforeMount() {
this.showWidget = await this.adyenService.isAdyenOrder(this.order);
if (this.showWidget) {
this.fetchRefunds();
}
Expand Down
26 changes: 15 additions & 11 deletions src/Resources/app/administration/src/service/adyenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,21 @@ class ApiClient extends ApiService {
}

isAdyenOrder(order) {
const orderTransactions = order.transactions;
let isAdyen = false;
for (let i = 0; i < orderTransactions.length; i++) {
if (orderTransactions[i].customFields !== undefined) {
if (orderTransactions[i].customFields.originalPspReference !== undefined) {
isAdyen = true;
}
}
}

return isAdyen;
const headers = this.getBasicHeaders({});
return this.httpClient
.get(this.getApiBasePath() + '/orders/' + order.id + '/is-adyen-order', {
headers
})
.then((response) => {
return ApiService.handleResponse(response);
})
.then((response) => {
return response.status
})
.catch((error) => {
console.error('An error occurred: ' + error.message);
return false;
});
}

fetchAdyenPartialPayments(orderId) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 00dd37b

Please sign in to comment.