Skip to content

Commit

Permalink
AD-288 Implement Translation Support in Adyen Library for Spartacus S…
Browse files Browse the repository at this point in the history
…torefront
  • Loading branch information
pjaneta committed Aug 13, 2024
1 parent 7b79c52 commit 6fafd5b
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 18 deletions.
12 changes: 10 additions & 2 deletions projects/adyen-payments/src/lib/adyen-payments.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {AdyenAddressService} from "./service/adyen-address.service";
import {AdditionalDetailsConnector} from "./core/connectors/additional-details.connector";
import {OccAdditionalDetailsAdapter} from "./core/occ/adapters/occ-additionaldetails.adapter";
import {AdyenRedirectModule} from "./adyen-redirect/adyen-redirect.module";
import { provideDefaultConfig } from '@spartacus/core';
import {I18nConfig, provideConfig, provideDefaultConfig} from '@spartacus/core';
import {adyenCheckoutTranslationChunksConfig, adyenCheckoutTranslations} from "./assets/translations/translations";



@NgModule({
Expand Down Expand Up @@ -55,7 +57,13 @@ import { provideDefaultConfig } from '@spartacus/core';
OccCheckoutConfigAdapter,
CheckoutAdyenEventListener,
CheckoutConfigurationConnector,
OrderHistoryConnector],
OrderHistoryConnector,
provideConfig(<I18nConfig>{
i18n: {
resources: adyenCheckoutTranslations,
chunks: adyenCheckoutTranslationChunksConfig,
},
})],
})
export class AdyenPaymentsModule {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
GlobalMessageType,
OCC_CART_ID_CURRENT,
RoutingService,
TranslationService,
UserIdService
} from '@spartacus/core';

Expand All @@ -18,7 +19,8 @@ export class AdyenRedirectErrorComponent implements OnInit {
constructor(protected routingService: RoutingService,
protected globalMessageService: GlobalMessageService,
protected multiCartFacade: MultiCartFacade,
protected userIdService: UserIdService
protected userIdService: UserIdService,
protected translationService: TranslationService,
) {
}

Expand All @@ -28,8 +30,11 @@ export class AdyenRedirectErrorComponent implements OnInit {

if (errorCode) {
let decodedError = atob(errorCode);

this.globalMessageService.add(decodedError, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);

this.translationService.translate(decodedError).subscribe(message => {
this.globalMessageService.add(message, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);
})

this.multiCartFacade.reloadCart(OCC_CART_ID_CURRENT)

this.userIdService.takeUserId().subscribe((userId) => {
Expand Down
1 change: 1 addition & 0 deletions projects/adyen-payments/src/lib/assets/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './translations/translations';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"adyenCheckout": {
"selectBillingAddress": "Select your billing address",
"selectAddress": "Select address",
"paymentFailed": "Payment failed",
"paymentPending": "Payment processing in progress",
"paymentRejected": "Your payment was rejected",
"paymentSuccessful": "Payment successful",
"paymentTimeout": "Payment took longer than expected. Try refreshing page in few minutes"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-ignore
import adyenCheckout from './adyen-checkout.json';
// @ts-ignore
import paymentErrors from './payment-errors.json';

export const en = {
adyenCheckout,
paymentErrors
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"checkout": {
"error": {
"authorization": {
"payment": {
"refused": "The payment is REFUSED.",
"detail": {
"not": {
"found": "The payment is REFUSED because the saved card is removed. Please try an other payment method."
}
}
},
"restricted": {
"card": "The card is restricted."
},
"cvc": {
"declined": "The payment is REFUSED. Please check your Card details."
},
"transaction": {
"not": {
"permitted": "The transaction is not permitted."
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {TranslationChunksConfig, TranslationResources} from "@spartacus/core";
import {en} from "./en";

export const adyenCheckoutTranslations: TranslationResources = {
en,
};

export const adyenCheckoutTranslationChunksConfig: TranslationChunksConfig = {
adyenCheckout: [
'adyenCheckout'
],
paymentErrors: [
'checkout'
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ export class AdyenCheckoutAdyenDeliveryAddressComponent implements OnInit {
this.selectedAddress$,
]);
const translations$ = combineLatest([

//TODO: translations
of("Select address"),
this.translationService.translate('adyenCheckout.selectAddress'),
this.translationService.translate('addressCard.selected'),
this.translationService.translate('addressCard.phoneNumber'),
this.translationService.translate('addressCard.mobileNumber'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@

<ng-template #showExistingAddresses>
<p class="cx-checkout-text">
<!-- TODO: Translations-->
{{ 'Select your billing address' }}
{{ 'adyenCheckout.selectBillingAddress' | cxTranslate }}
</p>

<div class="cx-checkout-btns cx-checkout-btns-top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class= "payment-status">
<cx-order-confirmation-icon-fail/>
<div class="payment-status_text">Payment failed</div>
<div class="payment-status_text">{{ 'adyenCheckout.paymentFailed' | cxTranslate }}</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class= "payment-status">
<cx-order-confirmation-payment-status-spinner/>
<div class="payment-status_text">Payment processing in progress</div>
<div class="payment-status_text">{{ 'adyenCheckout.paymentPending' | cxTranslate }}</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class= "payment-status">
<cx-order-confirmation-icon-fail/>
<div class="payment-status_text">Your payment was rejected</div>
<div class="payment-status_text">{{ 'adyenCheckout.paymentRejected' | cxTranslate }}</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class= "payment-status">
<cx-order-confirmation-icon-success/>
<div class="payment-status_text">Payment successful</div>
<div class="payment-status_text">{{ 'adyenCheckout.paymentSuccessful' | cxTranslate }}</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class= "payment-status">
<cx-order-confirmation-icon-timeout/>
<div class="payment-status_text">Payment took longer than expected. Try refreshing page in few minutes</div>
<div class="payment-status_text">{{ 'adyenCheckout.paymentTimeout' | cxTranslate }}</div>
</div>
14 changes: 11 additions & 3 deletions projects/adyen-payments/src/lib/service/adyen-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EventService,
GlobalMessageService,
GlobalMessageType,
TranslationService,
UserIdService
} from "@spartacus/core";
import {OrderConnector, OrderHistoryConnector, OrderService} from '@spartacus/order/core';
Expand All @@ -31,7 +32,8 @@ export class AdyenOrderService extends OrderService {
protected override orderConnector: OrderConnector,
protected override eventService: EventService,
protected globalMessageService: GlobalMessageService,
protected orderHistoryConnector: OrderHistoryConnector
protected orderHistoryConnector: OrderHistoryConnector,
protected translationService: TranslationService
) {
super(activeCartFacade, userIdService, commandService, orderConnector, eventService)
}
Expand Down Expand Up @@ -59,7 +61,10 @@ export class AdyenOrderService extends OrderService {
return {...response, success: true}
}),
catchError((error: HttpErrorResponse) => {
this.globalMessageService.add(error.error.errorCode, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);
this.translationService.translate(error.error.errorCode).subscribe((message) => {
this.globalMessageService.add(message, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);
})

let response: PlaceOrderResponse = {
success: false,
error: error.error.errorCode,
Expand Down Expand Up @@ -103,7 +108,10 @@ export class AdyenOrderService extends OrderService {
return {...response, success: true}
}),
catchError((error: HttpErrorResponse) => {
this.globalMessageService.add(error.error.errorCode, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);
this.translationService.translate(error.error.errorCode).subscribe((message) => {
this.globalMessageService.add(message, GlobalMessageType.MSG_TYPE_ERROR, this.messageTimeout);
})

let response: PlaceOrderResponse = {
success: false,
error: error.error.errorCode,
Expand Down

0 comments on commit 6fafd5b

Please sign in to comment.