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

Release 4.0.0 #515

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
34 changes: 33 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 @@ -92,6 +93,9 @@ class AdminController
/** @var OrderTransactionRepository */
private OrderTransactionRepository $orderTransactionRepository;

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

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

/**
Expand Down Expand Up @@ -506,4 +513,29 @@ public function rescheduleNotification(string $notificationId): JsonResponse

return new JsonResponse($notificationId);
}

/**
* @param string $orderId
* @return JsonResponse
*/
#[Route(
'/api/adyen/orders/{orderId}/is-adyen-order',
name: 'api.adyen_is_adyen_order.get',
methods: ['GET']
)]
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);
}
}
}
2 changes: 1 addition & 1 deletion src/Migration/Migration1713255011AlterAdyenPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function getCreationTimestamp(): int
public function update(Connection $connection): void
{
$connection->executeStatement(<<<SQL
ALTER TABLE `adyen_payment` ADD COLUMN `total_refunded` int DEFAULT(0) NOT NULL;
ALTER TABLE `adyen_payment` ADD COLUMN `total_refunded` int DEFAULT 0 NOT NULL;
SQL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,10 @@ 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isAdyenOrder method does not return a boolean as far as I see, can we ensure the type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the fix in this PR.

if (this.showWidget) {
this.fetchRefunds();
}
Expand Down
28 changes: 16 additions & 12 deletions src/Resources/app/administration/src/service/adyenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,22 @@ 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;
isAdyenOrder(order){
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
Loading
Loading