Better Payment 0.11.1 API
    Preparing search index...

    Function localizedErrors

    • Replaces the errorMessage of failed results with a message for the customer, in their language, chosen by the result's normalized code (or by a plugin's error code in errorCode). The provider's message stays in providerMessage.

      Parameters

      Returns {
          hooks: {
              after: [
                  {
                      handler: (
                          ctx: OperationResultContext,
                      ) => {
                          result:
                              | PaymentResponse
                              | SaveCardResponse
                              | ListCardsResponse
                              | DeleteCardResponse
                              | ThreeDSInitResponse
                              | RefundResponse
                              | CancelResponse
                              | BinCheckResponse
                              | InstallmentInfoResponse;
                      };
                      matcher: (ctx: OperationResultContext) => boolean;
                  },
              ];
          };
          id: "localized-errors";
          methods: (
              ctx: PluginContext,
          ) => {
              errors: {
                  locales: string[];
                  message: (code: string, language?: string) => string | undefined;
                  translate: <T>(result: T, language?: string) => T;
              };
          };
          onResponse: (
              response: BetterPaymentResponse,
              __namedParameters: ResponseContext,
          ) =>
              | {
                  body: Localizable;
                  headers: Record<string, string>;
                  status: number;
              }
              | undefined;
          options: LocalizedErrorsOptions;
      }

      import { localizedErrors } from 'better-payment/plugins';

      const payment = betterPayment({
      providers: { ... },
      plugins: [localizedErrors({ locale: 'tr' })],
      });