redsys-easy 3.1.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,36 @@
1
+ /**
2
+ * ISO 4217 currency code
3
+ *
4
+ * @public
5
+ */
1
6
  export declare type Currency = 'ALL' | 'DZD' | 'ARS' | 'AUD' | 'BSD' | 'BHD' | 'BDT' | 'AMD' | 'BBD' | 'BMD' | 'BTN' | 'BOB' | 'BWP' | 'BZD' | 'SBD' | 'BND' | 'MMK' | 'BIF' | 'KHR' | 'CAD' | 'CVE' | 'KYD' | 'LKR' | 'CLP' | 'CNY' | 'COP' | 'KMF' | 'CRC' | 'HRK' | 'CUP' | 'CZK' | 'DKK' | 'DOP' | 'SVC' | 'ETB' | 'ERN' | 'FKP' | 'FJD' | 'DJF' | 'GMD' | 'GIP' | 'GTQ' | 'GNF' | 'GYD' | 'HTG' | 'HNL' | 'HKD' | 'HUF' | 'ISK' | 'INR' | 'IDR' | 'IRR' | 'IQD' | 'ILS' | 'JMD' | 'JPY' | 'KZT' | 'JOD' | 'KES' | 'KPW' | 'KRW' | 'KWD' | 'KGS' | 'LAK' | 'LBP' | 'LSL' | 'LRD' | 'LYD' | 'MOP' | 'MWK' | 'MYR' | 'MVR' | 'MUR' | 'MXN' | 'MNT' | 'MDL' | 'MAD' | 'OMR' | 'NAD' | 'NPR' | 'ANG' | 'AWG' | 'VUV' | 'NZD' | 'NIO' | 'NGN' | 'NOK' | 'PKR' | 'PAB' | 'PGK' | 'PYG' | 'PEN' | 'PHP' | 'QAR' | 'RUB' | 'RWF' | 'SHP' | 'SAR' | 'SCR' | 'SLL' | 'SGD' | 'VND' | 'SOS' | 'ZAR' | 'SSP' | 'SZL' | 'SEK' | 'CHF' | 'SYP' | 'THB' | 'TOP' | 'TTD' | 'AED' | 'TND' | 'UGX' | 'MKD' | 'EGP' | 'GBP' | 'TZS' | 'USD' | 'UYU' | 'UZS' | 'WST' | 'YER' | 'TWD' | 'TMT' | 'GHS' | 'RSD' | 'MZN' | 'AZN' | 'RON' | 'TRY' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'ZMW' | 'SRD' | 'AFN' | 'TJS' | 'AOA' | 'BGN' | 'CDF' | 'BAM' | 'EUR' | 'UAH' | 'GEL' | 'PLN' | 'BRL';
7
+ /**
8
+ * ISO 4217 currency number
9
+ *
10
+ * @public
11
+ */
12
+ export declare type CurrencyNum = '8' | '12' | '32' | '36' | '44' | '48' | '50' | '51' | '52' | '60' | '64' | '68' | '72' | '84' | '90' | '96' | '104' | '108' | '116' | '124' | '132' | '136' | '144' | '152' | '156' | '170' | '174' | '188' | '191' | '192' | '203' | '208' | '214' | '222' | '230' | '232' | '238' | '242' | '262' | '270' | '292' | '320' | '324' | '328' | '332' | '340' | '344' | '348' | '352' | '356' | '360' | '364' | '368' | '376' | '388' | '392' | '398' | '400' | '404' | '408' | '410' | '414' | '417' | '418' | '422' | '426' | '430' | '434' | '446' | '454' | '458' | '462' | '480' | '484' | '496' | '498' | '504' | '512' | '516' | '524' | '532' | '533' | '548' | '554' | '558' | '566' | '578' | '586' | '590' | '598' | '600' | '604' | '608' | '634' | '643' | '646' | '654' | '682' | '690' | '694' | '702' | '704' | '706' | '710' | '728' | '748' | '752' | '756' | '760' | '764' | '776' | '780' | '784' | '788' | '800' | '807' | '818' | '826' | '834' | '840' | '858' | '860' | '882' | '886' | '901' | '934' | '936' | '941' | '943' | '944' | '946' | '949' | '950' | '951' | '952' | '953' | '967' | '968' | '971' | '972' | '973' | '975' | '976' | '977' | '978' | '980' | '981' | '985' | '986';
2
13
  interface CurrencyData {
3
- num: string;
14
+ num: CurrencyNum;
4
15
  decimals: number;
5
16
  }
17
+ /**
18
+ * Maps a ISO 4217 code to a ISO 4217 currency number and decimal positions
19
+ *
20
+ * @public
21
+ */
6
22
  export declare const CURRENCIES: Record<Currency, CurrencyData>;
7
23
  interface RevCurrencyData {
8
24
  code: Currency;
9
25
  decimals: number;
10
26
  }
11
- declare const REV_CURRENCIES: Record<string, RevCurrencyData>;
27
+ /**
28
+ * Maps a ISO 4217 number to a ISO 4217 currency code and decimal positions
29
+ *
30
+ * @remarks
31
+ * @see {@link CURRENCIES}
32
+ *
33
+ * @public
34
+ */
35
+ declare const REV_CURRENCIES: Record<CurrencyNum, RevCurrencyData>;
12
36
  export { REV_CURRENCIES };
@@ -1,4 +1,31 @@
1
+ /**
2
+ * ISO 639-1 language code
3
+ *
4
+ * @public
5
+ */
1
6
  export declare type Language = 'es' | 'en' | 'ca' | 'fr' | 'de' | 'nl' | 'it' | 'sv' | 'pt' | 'pl' | 'gl' | 'eu' | 'bg' | 'zh' | 'hr' | 'cs' | 'da' | 'et' | 'fi' | 'el' | 'hu' | 'ja' | 'lv' | 'lt' | 'mt' | 'ro' | 'ru' | 'sk' | 'sl' | 'tr';
2
- export declare const LANGUAGES: Record<Language, string>;
3
- declare const REV_LANGUAGES: Record<string, Language>;
7
+ /**
8
+ * Redsys language code
9
+ *
10
+ * @public
11
+ */
12
+ export declare type LanguageNum = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | '100' | '156' | '191' | '203' | '208' | '233' | '246' | '300' | '348' | '392' | '428' | '440' | '470' | '642' | '643' | '703' | '705' | '792';
13
+ /**
14
+ * Maps an ISO 639-1 language code to redsys language number
15
+ *
16
+ * @remarks
17
+ * Some ISO 639-1 language codes may include more more than one redsys language number. In such cases the main redsys language number is used.
18
+ *
19
+ * @public
20
+ */
21
+ export declare const LANGUAGES: Record<Language, LanguageNum>;
22
+ /**
23
+ * Maps a redsys language code to an ISO 639-1 language code
24
+ *
25
+ * @remarks
26
+ * @see {@link LANGUAGES}
27
+ *
28
+ * @public
29
+ */
30
+ declare const REV_LANGUAGES: Record<LanguageNum, Language>;
4
31
  export { REV_LANGUAGES };
@@ -1,21 +1,56 @@
1
- export declare type TransactionType = '0' | '1' | '2' | '3' | '5' | '6' | '7' | '8' | '9' | 'O' | 'F' | 'P' | 'Q' | 'R' | 'S' | 'A' | '44';
1
+ /**
2
+ * Transaction type code
3
+ *
4
+ * @public
5
+ */
6
+ export declare type TransactionType = '0' | '1' | '2' | '3' | '5' | '6' | '7' | '8' | '9' | '15' | '17' | '34' | '37' | '44' | 'O' | 'F' | 'P' | 'Q' | 'R' | 'S' | 'A';
7
+ /**
8
+ * Transaction type enum
9
+ *
10
+ * @public
11
+ */
2
12
  export declare const TRANSACTION_TYPES: {
13
+ /** Autorización */
3
14
  readonly AUTHORIZATION: "0";
15
+ /** Preautorización */
4
16
  readonly PRE_AUTHORIZATION: "1";
17
+ /** Confirmación de preautorización */
5
18
  readonly CONFIRMATION: "2";
19
+ /** Devolución Automática */
6
20
  readonly AUTO_REFUND: "3";
21
+ /** Transacción Recurrente */
7
22
  readonly RECURRING_TRANSACTION: "5";
23
+ /** Transacción Sucesiva */
8
24
  readonly SUCCESSIVE_TRANSACTION: "6";
25
+ /** Pre-autenticación */
9
26
  readonly PRE_AUTHENTICATION: "7";
27
+ /** Confirmación de pre-autenticación */
10
28
  readonly PRE_AUTHENTICATION_CONFIRMATION: "8";
29
+ /** Anulación de Preautorización */
11
30
  readonly PRE_AUTHORIZATION_CANCEL: "9";
31
+ /** Autorización en diferido */
12
32
  readonly DEFERRED_AUTHORIZATION: "O";
33
+ /** Paygold */
34
+ readonly PAYGOLD: "15";
35
+ /** Autenticación Puce */
36
+ readonly PUCE_AUTH: "17";
37
+ /** Devolución sin original */
38
+ readonly RETURN_WITHOUT_ORIGINAL: "34";
39
+ /** Premio de apuestas */
40
+ readonly BETTING_PAYOUT: "37";
41
+ /** Eliminar referencia */
42
+ readonly DELETE_REFERENCE: "44";
43
+ /** Operaciones sin autenticacíon */
44
+ readonly NO_AUTHENTICATION: "A";
45
+ /** Paygold */
13
46
  readonly PAYLINK: "F";
47
+ /** Confirmación de autorización en diferido */
14
48
  readonly DEFERRED_AUTHORIZATION_CONFIRMATION: "P";
49
+ /** Anulación de autorización en diferido */
15
50
  readonly DEFERRED_AUTHORIZATION_CANCEL: "Q";
51
+ /** Cuota inicial diferido */
16
52
  readonly DEFERRED_INITIAL_FEE: "R";
53
+ /** Cuota sucesiva diferido */
17
54
  readonly DEFERRED_SUCCESSIVE_FEE: "S";
18
- readonly NO_AUTHENTICATION: "A";
19
- readonly DELETE_REFERENCE: "44";
20
55
  };
21
56
  export default TRANSACTION_TYPES;
@@ -0,0 +1,50 @@
1
+ import type { ResponseJSONSuccess, RedirectForm } from './types/api';
2
+ import type { RestIniciaPeticionInputParams, RestTrataPeticionInputParams, RedirectInputParams } from './types/input-params';
3
+ import type { RestIniciaPeticionOutputParams, RestTrataPeticionOutputParams, RestNotificationOutputParams, SoapNotificationOutputParams } from './types/output-params';
4
+ /**
5
+ * URLs to configure the API
6
+ *
7
+ * @public
8
+ */
9
+ export interface UrlsConfig {
10
+ redirect: string;
11
+ restTrataPeticion: string;
12
+ restIniciaPeticion: string;
13
+ }
14
+ /**
15
+ * Redsys production urls
16
+ *
17
+ * @public
18
+ */
19
+ export declare const PRODUCTION_URLS: UrlsConfig;
20
+ /**
21
+ * Redsys sandbox urls
22
+ *
23
+ * @public
24
+ */
25
+ export declare const SANDBOX_URLS: UrlsConfig;
26
+ /**
27
+ * Redsys API settings
28
+ *
29
+ * @public
30
+ */
31
+ export interface RedsysConfig {
32
+ secretKey: string;
33
+ urls: UrlsConfig;
34
+ }
35
+ /**
36
+ * Creates Redsys API functions
37
+ *
38
+ * @remarks
39
+ * These API functions are anonymous and can be wrapped by formatters and processors
40
+ *
41
+ * @public
42
+ */
43
+ export declare const createRedsysAPI: (config: RedsysConfig) => {
44
+ restIniciaPeticion: (paramsInput: RestIniciaPeticionInputParams) => Promise<RestIniciaPeticionOutputParams>;
45
+ restTrataPeticion: (paramsInput: RestTrataPeticionInputParams) => Promise<RestTrataPeticionOutputParams>;
46
+ createRedirectForm: (paramsInput: RedirectInputParams) => RedirectForm;
47
+ processRestNotification: (body: ResponseJSONSuccess) => RestNotificationOutputParams;
48
+ processSoapNotification: (xml: string) => SoapNotificationOutputParams;
49
+ createSoapNotificationAnswer: (order: string, allow: boolean) => string;
50
+ };
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Adds padding to a buffer.
4
+ *
5
+ * Rounds up the buffer length to the next block and uses 0 as padding.
6
+ *
7
+ * @params buf - Input buffer
8
+ * @params blocksize - Size of block
9
+ */
10
+ export declare const zeroPad: (buf: Buffer, blocksize: number) => Buffer;
11
+ /**
12
+ * Encrypt a message using 3DES
13
+ *
14
+ * @params key - Key to encrypt message
15
+ * @params message - Message to be encrypted
16
+ */
17
+ export declare const encrypt3DES: (key: string, message: string) => Buffer;
18
+ /**
19
+ * Compute HMAC_SHA256_V1 signature
20
+ *
21
+ * @params merchantKey - Key to encrypt message
22
+ * @params order - Order number
23
+ * @params params - Payload to sign
24
+ */
25
+ export declare const sha256Sign: (merchantKey: string, order: string, params: string) => string;
package/lib/errors.d.ts CHANGED
@@ -1,20 +1,75 @@
1
+ /**
2
+ * Error superclass for all redsys-easy specific errors
3
+ *
4
+ * @public
5
+ */
1
6
  export declare class RedsysError extends Error {
2
7
  constructor(message: string);
3
8
  }
9
+ /**
10
+ * Invalid input provided
11
+ *
12
+ * @public
13
+ */
4
14
  export declare class ValidationError extends RedsysError {
5
15
  value: unknown;
6
- field: string;
7
- constructor(message: string, value: unknown, field: string);
16
+ parameters: object;
17
+ constructor(message: string, parameters: object);
8
18
  }
19
+ /**
20
+ * Response cannot be parsed
21
+ *
22
+ * @public
23
+ */
9
24
  export declare class ParseError extends RedsysError {
10
25
  value: unknown;
11
- text: string | undefined;
12
- code: string | undefined;
26
+ location: unknown | undefined;
13
27
  description: string | undefined;
14
- constructor(message: string, value?: unknown, text?: string);
28
+ constructor(message: string, value?: unknown, location?: unknown);
29
+ }
30
+ interface HTTPErrorOptions {
31
+ message?: string;
32
+ code: number;
33
+ response?: unknown;
34
+ }
35
+ /**
36
+ * HTTP Error
37
+ *
38
+ * @public
39
+ */
40
+ export declare class HTTPError extends RedsysError {
41
+ code: number | undefined;
42
+ response: unknown | undefined;
43
+ constructor({ message, code, response }: HTTPErrorOptions);
15
44
  }
45
+ interface GatewayErrorOptions {
46
+ message?: string;
47
+ code: string;
48
+ response?: unknown;
49
+ }
50
+ /**
51
+ * Request could not be processed by Redsys
52
+ *
53
+ * @public
54
+ */
16
55
  export declare class GatewayError extends RedsysError {
56
+ code: string | undefined;
57
+ response: unknown | undefined;
58
+ constructor({ message, code, response }: GatewayErrorOptions);
59
+ }
60
+ interface ResponseErrorOptions {
61
+ message?: string;
62
+ code: number;
63
+ response?: unknown;
64
+ }
65
+ /**
66
+ * Response contained an error code
67
+ *
68
+ * @public
69
+ */
70
+ export declare class ResponseError extends RedsysError {
17
71
  code: number | undefined;
18
72
  response: unknown | undefined;
19
- constructor(message: string, code?: number, response?: unknown);
73
+ constructor({ message, code, response }: ResponseErrorOptions);
20
74
  }
75
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Applies an input formatter to the first argument of a function
3
+ *
4
+ * @remarks
5
+ * The signature of this function is so complex because tries to suport
6
+ * formatters with generics that provide a default type. This should remain
7
+ * until [variadic generics](https://github.com/microsoft/TypeScript/issues/5453)
8
+ * land in typescript
9
+ *
10
+ * @public
11
+ */
12
+ export declare const useSingleInputFormatter: <AF extends (input: any) => B, B, C extends readonly unknown[], D>(fn: (args_0: B, ...args_1: C) => D, inputFormatter: AF) => (input: Parameters<AF>[0], ...otherArgs_0: C) => D;
13
+ /**
14
+ * Applies an output formatter to a function
15
+ *
16
+ * @public
17
+ */
18
+ export declare const useOutputFormatter: <A, B, C>(fn: (a: A) => B, outputFormatter: (b: B) => C) => (a: A) => C;
19
+ /**
20
+ * Applies an output formatter to the resolved ouput promise of a function
21
+ *
22
+ * @public
23
+ */
24
+ export declare const usePromiseOutputFormatter: <A, B, C>(fn: (a: A) => Promise<B>, outputFormatter: (b: B) => C) => (a: A) => Promise<C>;
@@ -0,0 +1,21 @@
1
+ import type { RedirectInputParams, RequestInputParams, RestIniciaPeticionInputParams, RestTrataPeticionInputParams } from '../types/input-params';
2
+ import type { RedirectFormatterInput, RequestFormatterInput, RestIniciaPeticionFormatterInput, RestTrataPeticionFormatterInput } from './types';
3
+ /**
4
+ * Redirection input formatter
5
+ *
6
+ * @public
7
+ */
8
+ export declare const redirectInputFormatter: <RawInputParams extends Partial<RedirectInputParams> = Partial<RedirectInputParams>>(input: RedirectFormatterInput<RawInputParams>) => RedirectInputParams;
9
+ export declare const requestInputFormatter: <RawInputParams extends Partial<RequestInputParams>>(input: RequestFormatterInput<RawInputParams>) => RequestInputParams;
10
+ /**
11
+ * REST iniciaPeticion input formatter
12
+ *
13
+ * @public
14
+ */
15
+ export declare const restIniciaPeticionInputFormatter: <RawInputParams extends Partial<RestIniciaPeticionInputParams> = Partial<RestIniciaPeticionInputParams>>(raw: RestIniciaPeticionFormatterInput<RawInputParams>) => RestIniciaPeticionInputParams;
16
+ /**
17
+ * REST trataPeticion input formatter
18
+ *
19
+ * @public
20
+ */
21
+ export declare const restTrataPeticionInputFormatter: <RawInputParams extends Partial<RestTrataPeticionInputParams> = Partial<RestTrataPeticionInputParams>>(raw: RestTrataPeticionFormatterInput<RawInputParams>) => RestTrataPeticionInputParams;
@@ -0,0 +1,29 @@
1
+ import type { BaseOutputParams, RestNotificationOutputParams, SoapNotificationOutputParams, RequestOutputParams, RestIniciaPeticionOutputParams, RestTrataPeticionOutputParams, ResolvedTransactionTrait } from '../types/output-params';
2
+ import type { BaseFormatterOutput, NotificationFormatterOutput, RequestFormatterOutput, RestIniciaPeticionFormatterOutput, RestTrataPeticionFormatterOutput, ResolvedTransactionTraitFormatterOutput } from './types';
3
+ export declare const baseOutputFormatter: <RawOutputParams extends BaseOutputParams>(raw: RawOutputParams) => BaseFormatterOutput<RawOutputParams>;
4
+ export declare const formatPrice: (params: Omit<ResolvedTransactionTrait, 'Ds_Response'>) => Omit<ResolvedTransactionTraitFormatterOutput, 'response'>;
5
+ /**
6
+ * REST notification formatter
7
+ *
8
+ * @public
9
+ */
10
+ export declare const restNotificationOutputFormatter: <RawOutputParams extends RestNotificationOutputParams = RestNotificationOutputParams>(raw: RawOutputParams) => NotificationFormatterOutput<RawOutputParams>;
11
+ /**
12
+ * SOAP notification formatter
13
+ *
14
+ * @public
15
+ */
16
+ export declare const soapNotificationOutputFormatter: <RawOutputParams extends SoapNotificationOutputParams = SoapNotificationOutputParams>(raw: RawOutputParams) => NotificationFormatterOutput<RawOutputParams>;
17
+ export declare const requestOutputFormatter: <RawOutputParams extends RequestOutputParams>(raw: RawOutputParams) => RequestFormatterOutput<RawOutputParams>;
18
+ /**
19
+ * REST iniciaPeticion output formatter
20
+ *
21
+ * @public
22
+ */
23
+ export declare const restIniciaPeticionOutputFormatter: <RawOutputParams extends RestIniciaPeticionOutputParams = RestIniciaPeticionOutputParams>(raw: RawOutputParams) => RestIniciaPeticionFormatterOutput<RawOutputParams>;
24
+ /**
25
+ * REST trataPeticion output formatter
26
+ *
27
+ * @public
28
+ */
29
+ export declare const restTrataPeticionOutputFormatter: <RawOutputParams extends RestTrataPeticionOutputParams = RestTrataPeticionOutputParams>(raw: RawOutputParams) => RestTrataPeticionFormatterOutput<RawOutputParams>;