Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 34 additions & 0 deletions src/Exception/ExtensionStoreApiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace SwagExtensionStore\Exception;

use GuzzleHttp\Exception\ClientException;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Store\Exception\StoreApiException;

#[Package('checkout')]
class ExtensionStoreApiException extends StoreApiException
{
protected string $apiCode;

public function __construct(ClientException $exception)
{
$data = json_decode($exception->getResponse()->getBody()->getContents(), true);

parent::__construct($exception);

$this->apiCode = $data['code'] ?? '';
}

public function getErrors(bool $withTrace = false): \Generator
{
$errors = parent::getErrors($withTrace);

foreach ($errors as $error) {
yield [
...$error,
'apiCode' => $this->apiCode,
];
}
}
}
5 changes: 2 additions & 3 deletions src/Exception/ExtensionStoreException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Store\Exception\InvalidExtensionIdException;
use Shopware\Core\Framework\Store\Exception\InvalidVariantIdException;
use Shopware\Core\Framework\Store\Exception\StoreApiException;
use Symfony\Component\HttpFoundation\Response;

#[Package('checkout')]
class ExtensionStoreException extends HttpException
{
public static function createStoreApiExceptionFromClientError(ClientException $clientException): StoreApiException
public static function createStoreApiExceptionFromClientError(ClientException $clientException): ExtensionStoreApiException
{
return new StoreApiException($clientException);
return new ExtensionStoreApiException($clientException);
}

public static function invalidExtensionId(): InvalidExtensionIdException
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/app/administration/src/global.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ declare global {
inAppPurchasesService: InAppPurchasesService;
}

type ErrorResponse = AxiosError<{ errors: Array<ShopwareHttpError> }>;
type ErrorResponse = AxiosError<{ errors: Array<ShopwareHttpError & { apiCode: string }> }>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export default Shopware.Component.wrapComponentConfig({
}
},

data() {
return {
allowedErrors: [
'The requested in-app feature has already been purchased',
'Das angefragte In-App Feature wurde bereits erworben'
]
};
},

computed: {
classes() {
return {
Expand Down Expand Up @@ -71,28 +62,15 @@ export default Shopware.Component.wrapComponentConfig({
},

errorSnippet(): string {
// if snippet is null, return the default error message
if (!this.error) {
return this.$t('sw-in-app-purchase-checkout-state.errorSubtitle');
}

const slugifiedSnippet = this.error
.toLowerCase()
.replace(/[^a-zA-Z0-9_ -]/g, '') // remove all non-alphanumeric characters except underscores and spaces
.replace(/[\s_]+/g, '-'); // replace spaces and underscores with hyphens

// if snippet slug exists in translation file, it comes from the extension store and must be translated
if (this.$te(`sw-in-app-purchase-checkout-state.errors.${slugifiedSnippet}`)) {
return this.$t(`sw-in-app-purchase-checkout-state.errors.${slugifiedSnippet}`);
}

// if it does not exist in the allowedErrors return the default error message
if (!this.allowedErrors.includes(this.error)) {
return this.$t('sw-in-app-purchase-checkout-state.errorSubtitle');
if (this.$te(`sw-in-app-purchase-checkout-state.errors.${this.error}`)) {
return this.$t(`sw-in-app-purchase-checkout-state.errors.${this.error}`);
}

// if it exists in the allowedErrors it comes from SBP and is already translated
return this.error;
return this.$t('sw-in-app-purchase-checkout-state.errorSubtitle');
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ describe('sw-in-app-purchase-checkout-state', () => {
});

it('should compute subtitle correctly', async () => {
// error comes from SBP
wrapper = await createWrapper({ state: 'error', error: 'The requested in-app feature has already been purchased' });
expect(wrapper.vm.subtitle).toBe('The requested in-app feature has already been purchased');

// error comes from ExtensionStore
wrapper = await createWrapper({ state: 'error', error: 'This-error_exists.' });
expect(wrapper.vm.subtitle).toBe(wrapper.vm.$t('sw-in-app-purchase-checkout-state.errors.this-error-exists'));

// error not found in SBP or allowed
wrapper = await createWrapper({ state: 'error', error: 'error is not allowed' });
expect(wrapper.vm.subtitle).toBe(wrapper.vm.$t('sw-in-app-purchase-checkout-state.errorSubtitle'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default Shopware.Component.wrapComponentConfig({
},

getError(errorResponse: ErrorResponse): string | null {
return errorResponse?.response?.data.errors[0]?.detail ?? null;
return errorResponse?.response?.data.errors[0]?.apiCode ?? null;
},

reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<sw-in-app-purchase-checkout-state
v-if="['loading', 'success', 'error'].includes(state)"
:state="state"
:error-snippet="errorMessage"
:error="errorMessage"
/>

<template #modal-footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@
"successTitle": "In-App Kauf war erfolgreich!",
"successSubtitle": "Du kannst jetzt dein neues Feature erleben.",
"errors": {
"the-extension-provider-disallowed-your-purchase-please-contact-the-extension-provider": "Der Anbieter der Erweiterung hat Ihren Kauf abgelehnt. Bitte kontaktieren Sie den Anbieter."
"ShopwarePlatformException-87": "Ungültiges In-App-Feature",
"ShopwarePlatformException-88": "In-App-Feature nicht gefunden",
"ShopwarePlatformException-89": "In-App-Feature bereits gekauft",
"ShopwarePlatformException-90": "In-App-Feature nicht kaufbar",
"ShopwarePlatformException-91": "Änderung des In-App-Feature-Abos nicht erlaubt",
"ShopwarePlatformException-92": "In-App-Feature bereits zur Herabstufung vorgemerkt",
"ShopwarePlatformException-93": "Ungültige Bestellung",
"ShopwarePlatformException-94": "Unzureichendes Guthaben",
"ShopwarePlatformException-95": "AGB nicht akzeptiert",
"ShopwarePlatformException-96": "In-App-Lizenz nicht gefunden",
"CloudAdminException-42": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-87",
"CloudAdminException-43": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-88",
"CloudAdminException-44": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-89",
"CloudAdminException-45": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-90",
"CloudAdminException-46": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-93",
"CloudAdminException-49": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-91",
"CloudAdminException-47": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-94",
"CloudAdminException-48": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-95",
"CloudAdminException-50": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-96",
"CloudAdminException-51": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-92"
}
},
"sw-in-app-purchase-price-box": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@
"successTitle": "In-App Purchase was successful!",
"successSubtitle": "You can now experience your new feature.",
"errors": {
"the-extension-provider-disallowed-your-purchase-please-contact-the-extension-provider": "The extension provider disallowed your purchase. Please contact the extension provider."
"ShopwarePlatformException-87": "Invalid in-app feature",
"ShopwarePlatformException-88": "In-app feature not found",
"ShopwarePlatformException-89": "In-app feature already purchased",
"ShopwarePlatformException-90": "In-app feature not purchasable",
"ShopwarePlatformException-91": "In-app feature subscription change not allowed",
"ShopwarePlatformException-92": "In-app feature already pending downgrade",
"ShopwarePlatformException-93": "Invalid order",
"ShopwarePlatformException-94": "Insufficient balance",
"ShopwarePlatformException-95": "GTC not accepted",
"ShopwarePlatformException-96": "In-app license not found",
"CloudAdminException-42": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-87",
"CloudAdminException-43": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-88",
"CloudAdminException-44": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-89",
"CloudAdminException-45": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-90",
"CloudAdminException-46": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-93",
"CloudAdminException-49": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-91",
"CloudAdminException-47": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-94",
"CloudAdminException-48": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-95",
"CloudAdminException-50": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-96",
"CloudAdminException-51": "@:sw-in-app-purchase-checkout-state.errors.ShopwarePlatformException-92"
}
},
"sw-in-app-purchase-price-box": {
Expand Down
Loading