Skip to content

Commit

Permalink
[ECP-9206-v3] Update Adyen order check logic by using order transacti…
Browse files Browse the repository at this point in the history
…on instead of original psp-reference and create and end point for this check
  • Loading branch information
sushmita committed Jun 5, 2024
1 parent a8a59eb commit 6f3a43b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
39 changes: 38 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,34 @@ 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,
Context::createDefaultContext()
);

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

return new JsonResponse(['status' => false]);
} catch (Throwable $t) {
return new JsonResponse(['message' => "Something went wrong."], 500);
}
}
}
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();
this.showWidget = 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);
throw error;
});
}

fetchAdyenPartialPayments(orderId) {
Expand Down

0 comments on commit 6f3a43b

Please sign in to comment.