@apolopay-sdk/core 1.0.0
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.
- package/README.md +40 -0
- package/dist/index.d.mts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.js +401 -0
- package/dist/index.mjs +368 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @apolopay-sdk/core
|
|
2
|
+
|
|
3
|
+
The core logic and common types for the Apolo Pay JavaScript SDK. This package provides the foundational classes and services used across all platform-specific SDKs (React, Vue, Angular, etc.).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @apolopay-sdk/core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @apolopay-sdk/core
|
|
11
|
+
# or
|
|
12
|
+
yarn add @apolopay-sdk/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### ApoloPayClient
|
|
18
|
+
|
|
19
|
+
The `ApoloPayClient` is the main entry point for interacting with the Apolo Pay API. You'll need your Public Key to initialize it.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ApoloPayClient } from '@apolopay-sdk/core';
|
|
23
|
+
|
|
24
|
+
const client = new ApoloPayClient({
|
|
25
|
+
publicKey: 'pk_test_...', // Your Apolo Pay Public Key
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Services and Types
|
|
30
|
+
|
|
31
|
+
This package also exports various types and services:
|
|
32
|
+
|
|
33
|
+
- `PaymentService`: Handles API calls for payments, assets, and WebSocket connections.
|
|
34
|
+
- `I18n`: Internationalization utility for the SDK.
|
|
35
|
+
- `Locale`: Type for supported languages ('es', 'en').
|
|
36
|
+
- `ClientResponse`, `ClientError`: Standardized response and error types.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
interface ApoloPayClientOptions {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
}
|
|
4
|
+
declare class ApoloPayClient {
|
|
5
|
+
private publicKey;
|
|
6
|
+
constructor(options: ApoloPayClientOptions);
|
|
7
|
+
getPublicKey(): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Network {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
network: string;
|
|
14
|
+
image: string;
|
|
15
|
+
isNative: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Asset {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
symbol: string;
|
|
22
|
+
image: string;
|
|
23
|
+
networks: Network[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare abstract class ClientResponseBase {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly message: string;
|
|
29
|
+
constructor({ code, message }: {
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
declare class ClientResponse<T = any> extends ClientResponseBase {
|
|
35
|
+
readonly result?: T;
|
|
36
|
+
constructor({ code, message, result }: {
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
result?: T;
|
|
40
|
+
});
|
|
41
|
+
static fromJson<T = any>(json: any, { code, message, result }?: {
|
|
42
|
+
code?: string;
|
|
43
|
+
message?: string;
|
|
44
|
+
result?: (json: any) => T;
|
|
45
|
+
}): ClientResponse<T>;
|
|
46
|
+
}
|
|
47
|
+
declare class ClientError extends ClientResponseBase {
|
|
48
|
+
readonly error?: any;
|
|
49
|
+
constructor({ code, message, error }: {
|
|
50
|
+
code: string;
|
|
51
|
+
message: string;
|
|
52
|
+
error?: any;
|
|
53
|
+
});
|
|
54
|
+
static fromError(error: any, { code, message }?: {
|
|
55
|
+
code?: string;
|
|
56
|
+
message?: string;
|
|
57
|
+
}): ClientError;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface QrRequestDetails {
|
|
61
|
+
assetId: string;
|
|
62
|
+
networkId: string;
|
|
63
|
+
}
|
|
64
|
+
interface QrResponseData {
|
|
65
|
+
id: string;
|
|
66
|
+
network: string;
|
|
67
|
+
asset: string;
|
|
68
|
+
amount: number | string;
|
|
69
|
+
address: string;
|
|
70
|
+
qrCodeUrl: string;
|
|
71
|
+
expiresAtMs: number;
|
|
72
|
+
paymentUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
interface ClientOptions {
|
|
75
|
+
publicKey: string;
|
|
76
|
+
}
|
|
77
|
+
interface PaymentSessionOptions {
|
|
78
|
+
processId: string;
|
|
79
|
+
onSuccess: (response: ClientResponse) => void;
|
|
80
|
+
onError: (error: ClientError) => void;
|
|
81
|
+
}
|
|
82
|
+
interface PaymentOptions extends ClientOptions, PaymentSessionOptions {
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare class PaymentService {
|
|
86
|
+
private client;
|
|
87
|
+
private socket;
|
|
88
|
+
constructor(client: ApoloPayClient);
|
|
89
|
+
getPublicKey(): string;
|
|
90
|
+
getAssets(): Promise<Asset[]>;
|
|
91
|
+
fetchQrCodeDetails(details: QrRequestDetails, session: PaymentSessionOptions): Promise<QrResponseData>;
|
|
92
|
+
disconnectWebSocket(): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare enum ModalStep {
|
|
96
|
+
SELECT_ASSET = 0,
|
|
97
|
+
SELECT_NETWORK = 1,
|
|
98
|
+
SHOW_QR = 2,
|
|
99
|
+
RESULT = 3
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface Dictionary {
|
|
103
|
+
trigger: {
|
|
104
|
+
loading: string;
|
|
105
|
+
};
|
|
106
|
+
modal: {
|
|
107
|
+
titles: {
|
|
108
|
+
selectAsset: string;
|
|
109
|
+
selectNetwork: string;
|
|
110
|
+
scanQr: string;
|
|
111
|
+
success: string;
|
|
112
|
+
error: string;
|
|
113
|
+
idle: string;
|
|
114
|
+
};
|
|
115
|
+
subtitles: {
|
|
116
|
+
selectAsset: string;
|
|
117
|
+
selectNetwork: string;
|
|
118
|
+
idle: string;
|
|
119
|
+
};
|
|
120
|
+
actions: {
|
|
121
|
+
back: string;
|
|
122
|
+
close: string;
|
|
123
|
+
support: string;
|
|
124
|
+
scanApp: string;
|
|
125
|
+
copy: string;
|
|
126
|
+
copied: string;
|
|
127
|
+
payFromDevice: string;
|
|
128
|
+
};
|
|
129
|
+
labels: {
|
|
130
|
+
network: string;
|
|
131
|
+
address: string;
|
|
132
|
+
amount: string;
|
|
133
|
+
product: string;
|
|
134
|
+
minutes: string;
|
|
135
|
+
seconds: string;
|
|
136
|
+
};
|
|
137
|
+
warnings: {
|
|
138
|
+
networkMatch: string;
|
|
139
|
+
noNFT: string;
|
|
140
|
+
onlyToken: string;
|
|
141
|
+
timer: string;
|
|
142
|
+
selectNetworkLater: string;
|
|
143
|
+
};
|
|
144
|
+
success: {
|
|
145
|
+
message: string;
|
|
146
|
+
message2: string;
|
|
147
|
+
details: string;
|
|
148
|
+
support: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
errors: {
|
|
152
|
+
generic: string;
|
|
153
|
+
publicKeyMissing: string;
|
|
154
|
+
config: string;
|
|
155
|
+
timeout: string;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type Locale = 'es' | 'en';
|
|
160
|
+
declare class I18nService {
|
|
161
|
+
private static _currentLocale;
|
|
162
|
+
private static _dictionary;
|
|
163
|
+
static setLocale(locale: Locale): void;
|
|
164
|
+
static get current(): Locale;
|
|
165
|
+
static get t(): Dictionary;
|
|
166
|
+
static interpolate(text: string, params: Record<string, string | number>): string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { ApoloPayClient, type ApoloPayClientOptions, type Asset, ClientError, type ClientOptions, ClientResponse, ClientResponseBase, type Dictionary, I18nService as I18n, type Locale, ModalStep, type Network, type PaymentOptions, PaymentService, type PaymentSessionOptions, type QrRequestDetails, type QrResponseData };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
interface ApoloPayClientOptions {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
}
|
|
4
|
+
declare class ApoloPayClient {
|
|
5
|
+
private publicKey;
|
|
6
|
+
constructor(options: ApoloPayClientOptions);
|
|
7
|
+
getPublicKey(): string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Network {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
network: string;
|
|
14
|
+
image: string;
|
|
15
|
+
isNative: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Asset {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
symbol: string;
|
|
22
|
+
image: string;
|
|
23
|
+
networks: Network[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare abstract class ClientResponseBase {
|
|
27
|
+
readonly code: string;
|
|
28
|
+
readonly message: string;
|
|
29
|
+
constructor({ code, message }: {
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
declare class ClientResponse<T = any> extends ClientResponseBase {
|
|
35
|
+
readonly result?: T;
|
|
36
|
+
constructor({ code, message, result }: {
|
|
37
|
+
code: string;
|
|
38
|
+
message: string;
|
|
39
|
+
result?: T;
|
|
40
|
+
});
|
|
41
|
+
static fromJson<T = any>(json: any, { code, message, result }?: {
|
|
42
|
+
code?: string;
|
|
43
|
+
message?: string;
|
|
44
|
+
result?: (json: any) => T;
|
|
45
|
+
}): ClientResponse<T>;
|
|
46
|
+
}
|
|
47
|
+
declare class ClientError extends ClientResponseBase {
|
|
48
|
+
readonly error?: any;
|
|
49
|
+
constructor({ code, message, error }: {
|
|
50
|
+
code: string;
|
|
51
|
+
message: string;
|
|
52
|
+
error?: any;
|
|
53
|
+
});
|
|
54
|
+
static fromError(error: any, { code, message }?: {
|
|
55
|
+
code?: string;
|
|
56
|
+
message?: string;
|
|
57
|
+
}): ClientError;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface QrRequestDetails {
|
|
61
|
+
assetId: string;
|
|
62
|
+
networkId: string;
|
|
63
|
+
}
|
|
64
|
+
interface QrResponseData {
|
|
65
|
+
id: string;
|
|
66
|
+
network: string;
|
|
67
|
+
asset: string;
|
|
68
|
+
amount: number | string;
|
|
69
|
+
address: string;
|
|
70
|
+
qrCodeUrl: string;
|
|
71
|
+
expiresAtMs: number;
|
|
72
|
+
paymentUrl?: string;
|
|
73
|
+
}
|
|
74
|
+
interface ClientOptions {
|
|
75
|
+
publicKey: string;
|
|
76
|
+
}
|
|
77
|
+
interface PaymentSessionOptions {
|
|
78
|
+
processId: string;
|
|
79
|
+
onSuccess: (response: ClientResponse) => void;
|
|
80
|
+
onError: (error: ClientError) => void;
|
|
81
|
+
}
|
|
82
|
+
interface PaymentOptions extends ClientOptions, PaymentSessionOptions {
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare class PaymentService {
|
|
86
|
+
private client;
|
|
87
|
+
private socket;
|
|
88
|
+
constructor(client: ApoloPayClient);
|
|
89
|
+
getPublicKey(): string;
|
|
90
|
+
getAssets(): Promise<Asset[]>;
|
|
91
|
+
fetchQrCodeDetails(details: QrRequestDetails, session: PaymentSessionOptions): Promise<QrResponseData>;
|
|
92
|
+
disconnectWebSocket(): void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
declare enum ModalStep {
|
|
96
|
+
SELECT_ASSET = 0,
|
|
97
|
+
SELECT_NETWORK = 1,
|
|
98
|
+
SHOW_QR = 2,
|
|
99
|
+
RESULT = 3
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface Dictionary {
|
|
103
|
+
trigger: {
|
|
104
|
+
loading: string;
|
|
105
|
+
};
|
|
106
|
+
modal: {
|
|
107
|
+
titles: {
|
|
108
|
+
selectAsset: string;
|
|
109
|
+
selectNetwork: string;
|
|
110
|
+
scanQr: string;
|
|
111
|
+
success: string;
|
|
112
|
+
error: string;
|
|
113
|
+
idle: string;
|
|
114
|
+
};
|
|
115
|
+
subtitles: {
|
|
116
|
+
selectAsset: string;
|
|
117
|
+
selectNetwork: string;
|
|
118
|
+
idle: string;
|
|
119
|
+
};
|
|
120
|
+
actions: {
|
|
121
|
+
back: string;
|
|
122
|
+
close: string;
|
|
123
|
+
support: string;
|
|
124
|
+
scanApp: string;
|
|
125
|
+
copy: string;
|
|
126
|
+
copied: string;
|
|
127
|
+
payFromDevice: string;
|
|
128
|
+
};
|
|
129
|
+
labels: {
|
|
130
|
+
network: string;
|
|
131
|
+
address: string;
|
|
132
|
+
amount: string;
|
|
133
|
+
product: string;
|
|
134
|
+
minutes: string;
|
|
135
|
+
seconds: string;
|
|
136
|
+
};
|
|
137
|
+
warnings: {
|
|
138
|
+
networkMatch: string;
|
|
139
|
+
noNFT: string;
|
|
140
|
+
onlyToken: string;
|
|
141
|
+
timer: string;
|
|
142
|
+
selectNetworkLater: string;
|
|
143
|
+
};
|
|
144
|
+
success: {
|
|
145
|
+
message: string;
|
|
146
|
+
message2: string;
|
|
147
|
+
details: string;
|
|
148
|
+
support: string;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
errors: {
|
|
152
|
+
generic: string;
|
|
153
|
+
publicKeyMissing: string;
|
|
154
|
+
config: string;
|
|
155
|
+
timeout: string;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type Locale = 'es' | 'en';
|
|
160
|
+
declare class I18nService {
|
|
161
|
+
private static _currentLocale;
|
|
162
|
+
private static _dictionary;
|
|
163
|
+
static setLocale(locale: Locale): void;
|
|
164
|
+
static get current(): Locale;
|
|
165
|
+
static get t(): Dictionary;
|
|
166
|
+
static interpolate(text: string, params: Record<string, string | number>): string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { ApoloPayClient, type ApoloPayClientOptions, type Asset, ClientError, type ClientOptions, ClientResponse, ClientResponseBase, type Dictionary, I18nService as I18n, type Locale, ModalStep, type Network, type PaymentOptions, PaymentService, type PaymentSessionOptions, type QrRequestDetails, type QrResponseData };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ApoloPayClient: () => ApoloPayClient,
|
|
24
|
+
ClientError: () => ClientError,
|
|
25
|
+
ClientResponse: () => ClientResponse,
|
|
26
|
+
ClientResponseBase: () => ClientResponseBase,
|
|
27
|
+
I18n: () => I18nService,
|
|
28
|
+
ModalStep: () => ModalStep,
|
|
29
|
+
PaymentService: () => PaymentService
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/apolo-pay-client.ts
|
|
34
|
+
var ApoloPayClient = class {
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.publicKey = options.publicKey;
|
|
37
|
+
}
|
|
38
|
+
getPublicKey() {
|
|
39
|
+
return this.publicKey;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/types/client-response.ts
|
|
44
|
+
var ClientResponseBase = class {
|
|
45
|
+
constructor({ code, message }) {
|
|
46
|
+
this.code = code;
|
|
47
|
+
this.message = message;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var ClientResponse = class _ClientResponse extends ClientResponseBase {
|
|
51
|
+
constructor({ code, message, result }) {
|
|
52
|
+
super({ code, message });
|
|
53
|
+
this.result = result;
|
|
54
|
+
}
|
|
55
|
+
static fromJson(json, { code, message, result } = {}) {
|
|
56
|
+
const successCode = json.status || code || "success";
|
|
57
|
+
const successMessage = json.message || message || "Success";
|
|
58
|
+
const successResult = result?.(json.result) || json.result || json;
|
|
59
|
+
return new _ClientResponse({ code: successCode, message: successMessage, result: successResult });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var ClientError = class _ClientError extends ClientResponseBase {
|
|
63
|
+
constructor({ code, message, error }) {
|
|
64
|
+
super({ code, message });
|
|
65
|
+
this.error = error;
|
|
66
|
+
}
|
|
67
|
+
static fromError(error, { code, message } = {}) {
|
|
68
|
+
const errCode = error.statusCode || code || "unknown_error";
|
|
69
|
+
const errMessage = error.message || message || "Error desconocido";
|
|
70
|
+
const err = error.error || error;
|
|
71
|
+
return new _ClientError({ code: errCode, message: errMessage, error: err });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/services/repository.ts
|
|
76
|
+
var Repository = class {
|
|
77
|
+
static async getAssets() {
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(`${this.apiUrl}/payment-button/assets`, {
|
|
80
|
+
method: "GET",
|
|
81
|
+
headers: this.headers()
|
|
82
|
+
});
|
|
83
|
+
const data = await response.json();
|
|
84
|
+
return ClientResponse.fromJson(data);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw ClientError.fromError(error, {
|
|
87
|
+
code: "get_assets_error",
|
|
88
|
+
message: "Error al obtener los activos"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
static async fetchQrCodeDetails({
|
|
93
|
+
processId,
|
|
94
|
+
assetId,
|
|
95
|
+
networkId,
|
|
96
|
+
publicKey
|
|
97
|
+
}) {
|
|
98
|
+
try {
|
|
99
|
+
const response = await fetch(`${this.apiUrl}/payment-button/process/confirm`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: this.headers(publicKey),
|
|
102
|
+
body: JSON.stringify({
|
|
103
|
+
processId,
|
|
104
|
+
assetId,
|
|
105
|
+
networkId
|
|
106
|
+
})
|
|
107
|
+
}), data = await response.json();
|
|
108
|
+
if (!data.result) {
|
|
109
|
+
throw new ClientError({
|
|
110
|
+
code: data.status || "qr_fetch_error",
|
|
111
|
+
message: data.message || "Error al obtener los detalles del c\xF3digo QR"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const wallet = data.result.wallet;
|
|
115
|
+
const network = data.result.network;
|
|
116
|
+
const address = network === "apolopay" ? `https://p2p.apolopay.app/payment-process/${processId}` : wallet;
|
|
117
|
+
return ClientResponse.fromJson(data, {
|
|
118
|
+
result: (json) => {
|
|
119
|
+
let expiresAtMs = json.expiresAtMs || json.expiresAt || Date.now() + 30 * 60 * 1e3;
|
|
120
|
+
if (typeof expiresAtMs === "string") {
|
|
121
|
+
expiresAtMs = new Date(expiresAtMs).getTime();
|
|
122
|
+
}
|
|
123
|
+
if (typeof expiresAtMs === "number" && expiresAtMs > 1e13) {
|
|
124
|
+
while (expiresAtMs > 2e12) {
|
|
125
|
+
expiresAtMs = Math.floor(expiresAtMs / 1e3);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
...json,
|
|
130
|
+
address,
|
|
131
|
+
qrCodeUrl: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${address}&ecc=H`,
|
|
132
|
+
paymentUrl: address.startsWith("http") ? address : void 0,
|
|
133
|
+
expiresAtMs: isNaN(expiresAtMs) ? Date.now() + 30 * 60 * 1e3 : expiresAtMs
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
throw ClientError.fromError(error, {
|
|
139
|
+
code: "fetch_qr_code_details_error",
|
|
140
|
+
message: "Error al obtener los detalles del c\xF3digo QR"
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
Repository.apiUrl = "https://pb-test-api.apolopay.app";
|
|
146
|
+
Repository.headers = (publicKey) => {
|
|
147
|
+
const options = {
|
|
148
|
+
"Content-Type": "application/json"
|
|
149
|
+
};
|
|
150
|
+
if (publicKey) options["x-public-key"] = publicKey;
|
|
151
|
+
return options;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/services/socket-service.ts
|
|
155
|
+
var import_socket = require("socket.io-client");
|
|
156
|
+
var _SocketService = class _SocketService {
|
|
157
|
+
constructor(client) {
|
|
158
|
+
this.sessionOptions = null;
|
|
159
|
+
this.socket = null;
|
|
160
|
+
this.client = client;
|
|
161
|
+
}
|
|
162
|
+
connect(session) {
|
|
163
|
+
if (typeof window === "undefined") return;
|
|
164
|
+
this.sessionOptions = session;
|
|
165
|
+
if (this.socket && this.socket.connected) return this.disconnect();
|
|
166
|
+
this.socket = (0, import_socket.io)(_SocketService.wsUrl, {
|
|
167
|
+
extraHeaders: {
|
|
168
|
+
"x-public-key": this.client.getPublicKey()
|
|
169
|
+
},
|
|
170
|
+
transports: ["polling"]
|
|
171
|
+
});
|
|
172
|
+
const { processId } = session;
|
|
173
|
+
this.socket.on("connect", () => this.socket?.emit("process:connect", { processId }));
|
|
174
|
+
console.log(`Conectado a Socket.io para processId: ${processId}`);
|
|
175
|
+
this.socket.on("process:message", (response) => this.handleWebSocketMessage(response));
|
|
176
|
+
this.socket.on("connect_error", (error) => {
|
|
177
|
+
console.error("Error en conexi\xF3n Socket.io:", error);
|
|
178
|
+
this.sessionOptions?.onError({ code: "connect_error", message: "Error de conexi\xF3n en tiempo real.", error });
|
|
179
|
+
this.disconnect();
|
|
180
|
+
});
|
|
181
|
+
this.socket.on("disconnect", (reason) => {
|
|
182
|
+
console.info(`Socket.io Desconectado: ${reason}`);
|
|
183
|
+
this.socket = null;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
handleWebSocketMessage(response) {
|
|
187
|
+
console.log(response);
|
|
188
|
+
if (!response.success) {
|
|
189
|
+
return this.sessionOptions?.onError({
|
|
190
|
+
code: "payment_failed",
|
|
191
|
+
message: response.message,
|
|
192
|
+
error: response.result
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (response.result.status === "completed") {
|
|
196
|
+
return this.sessionOptions?.onSuccess({
|
|
197
|
+
code: "payment_success",
|
|
198
|
+
message: response.message,
|
|
199
|
+
result: response.result
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
disconnect() {
|
|
204
|
+
if (this.socket) {
|
|
205
|
+
this.socket.disconnect();
|
|
206
|
+
this.socket = null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
_SocketService.wsUrl = "https://pb-test-ws.apolopay.app";
|
|
211
|
+
var SocketService = _SocketService;
|
|
212
|
+
|
|
213
|
+
// src/services/payment-service.ts
|
|
214
|
+
var PaymentService = class {
|
|
215
|
+
constructor(client) {
|
|
216
|
+
this.client = client;
|
|
217
|
+
this.socket = new SocketService(this.client);
|
|
218
|
+
}
|
|
219
|
+
getPublicKey() {
|
|
220
|
+
return this.client.getPublicKey();
|
|
221
|
+
}
|
|
222
|
+
// --- Métodos para obtener datos ---
|
|
223
|
+
async getAssets() {
|
|
224
|
+
const assets = await Repository.getAssets();
|
|
225
|
+
return assets.result;
|
|
226
|
+
}
|
|
227
|
+
// --- Método para obtener datos del QR ---
|
|
228
|
+
async fetchQrCodeDetails(details, session) {
|
|
229
|
+
const qrData = await Repository.fetchQrCodeDetails({
|
|
230
|
+
...details,
|
|
231
|
+
processId: session.processId,
|
|
232
|
+
publicKey: this.client.getPublicKey()
|
|
233
|
+
});
|
|
234
|
+
console.log("qrData", qrData);
|
|
235
|
+
this.socket.connect(session);
|
|
236
|
+
return qrData.result;
|
|
237
|
+
}
|
|
238
|
+
disconnectWebSocket() {
|
|
239
|
+
this.socket.disconnect();
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/types/modal-step.ts
|
|
244
|
+
var ModalStep = /* @__PURE__ */ ((ModalStep2) => {
|
|
245
|
+
ModalStep2[ModalStep2["SELECT_ASSET"] = 0] = "SELECT_ASSET";
|
|
246
|
+
ModalStep2[ModalStep2["SELECT_NETWORK"] = 1] = "SELECT_NETWORK";
|
|
247
|
+
ModalStep2[ModalStep2["SHOW_QR"] = 2] = "SHOW_QR";
|
|
248
|
+
ModalStep2[ModalStep2["RESULT"] = 3] = "RESULT";
|
|
249
|
+
return ModalStep2;
|
|
250
|
+
})(ModalStep || {});
|
|
251
|
+
|
|
252
|
+
// src/i18n/es.ts
|
|
253
|
+
var es = {
|
|
254
|
+
trigger: {
|
|
255
|
+
loading: "Cargando..."
|
|
256
|
+
},
|
|
257
|
+
modal: {
|
|
258
|
+
titles: {
|
|
259
|
+
selectAsset: 'Selecciona el <span class="highlight">stablecoin</span>',
|
|
260
|
+
selectNetwork: 'Selecciona la <span class="highlight">red</span>',
|
|
261
|
+
scanQr: 'Dep\xF3sito <span class="highlight">{symbol}</span>',
|
|
262
|
+
success: '\xA1Gracias por <span class="highlight">tu compra!</span>',
|
|
263
|
+
error: "Error en el Pago",
|
|
264
|
+
idle: "Estado inesperado"
|
|
265
|
+
},
|
|
266
|
+
subtitles: {
|
|
267
|
+
selectAsset: "Selecciona la stablecoin con la que deseas pagar",
|
|
268
|
+
selectNetwork: "Selecciona la red de tu preferencia",
|
|
269
|
+
idle: "Ocurrio un error inesperado"
|
|
270
|
+
},
|
|
271
|
+
actions: {
|
|
272
|
+
back: "Volver",
|
|
273
|
+
close: "Cerrar",
|
|
274
|
+
support: "Soporte",
|
|
275
|
+
scanApp: 'Escanea con tu celular y continua desde la app de <span style="color: var(--apolo-accent)">Apolo Pay</span>',
|
|
276
|
+
copy: "Copiar",
|
|
277
|
+
copied: "\xA1Copiado!",
|
|
278
|
+
payFromDevice: "Pagar desde este dispositivo"
|
|
279
|
+
},
|
|
280
|
+
labels: {
|
|
281
|
+
network: "Red",
|
|
282
|
+
address: "Direcci\xF3n de dep\xF3sito",
|
|
283
|
+
amount: "Monto",
|
|
284
|
+
product: "Producto o Servicio",
|
|
285
|
+
minutes: "min",
|
|
286
|
+
seconds: "seg"
|
|
287
|
+
},
|
|
288
|
+
warnings: {
|
|
289
|
+
networkMatch: "Aseg\xFArate de que la <strong>red de tu wallet coincida</strong> con la red de destino.",
|
|
290
|
+
noNFT: "No env\xEDes NFTs a esta wallet.",
|
|
291
|
+
onlyToken: "Solo se aceptan <strong>dep\xF3sitos en {symbol}</strong>. El env\xEDo de otro tipo de token podr\xEDa resultar en su p\xE9rdida.",
|
|
292
|
+
timer: "Realiza el pago dentro del tiempo indicado. <strong>{time}</strong> De lo contrario, el c\xF3digo QR se vencer\xE1.",
|
|
293
|
+
selectNetworkLater: "Luego podr\xE1s seleccionar la red de tu preferencia"
|
|
294
|
+
},
|
|
295
|
+
success: {
|
|
296
|
+
message: "Tu pago fue exitoso y en breve recibir\xE1s un correo",
|
|
297
|
+
message2: "con los detalles.",
|
|
298
|
+
details: "Detalles de la compra",
|
|
299
|
+
support: "Cualquier duda o inquietud puedes comunicarte con soporte"
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
errors: {
|
|
303
|
+
generic: "Ocurri\xF3 un error inesperado.",
|
|
304
|
+
publicKeyMissing: "Falta la Public Key",
|
|
305
|
+
config: "Error de Configuraci\xF3n",
|
|
306
|
+
timeout: "El tiempo para realizar el pago ha expirado. Por favor genera una nueva orden."
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// src/i18n/en.ts
|
|
311
|
+
var en = {
|
|
312
|
+
trigger: {
|
|
313
|
+
loading: "Loading..."
|
|
314
|
+
},
|
|
315
|
+
modal: {
|
|
316
|
+
titles: {
|
|
317
|
+
selectAsset: 'Select <span class="highlight">stablecoin</span>',
|
|
318
|
+
selectNetwork: 'Select <span class="highlight">network</span>',
|
|
319
|
+
scanQr: 'Deposit <span class="highlight">{symbol}</span>',
|
|
320
|
+
success: 'Thanks for <span class="highlight">your purchase!</span>',
|
|
321
|
+
error: "Payment Error",
|
|
322
|
+
idle: "Unexpected state"
|
|
323
|
+
},
|
|
324
|
+
subtitles: {
|
|
325
|
+
selectAsset: "Select the stablecoin you want to pay with",
|
|
326
|
+
selectNetwork: "Select your preferred network",
|
|
327
|
+
idle: "An Unexpected error occurred"
|
|
328
|
+
},
|
|
329
|
+
actions: {
|
|
330
|
+
back: "Back",
|
|
331
|
+
close: "Close",
|
|
332
|
+
support: "Support",
|
|
333
|
+
scanApp: 'Scan with your phone and continue from <br><span style="color: var(--apolo-accent)">Apolo Pay</span> app',
|
|
334
|
+
copy: "Copy",
|
|
335
|
+
copied: "Copied!",
|
|
336
|
+
payFromDevice: "Pay from this device"
|
|
337
|
+
},
|
|
338
|
+
labels: {
|
|
339
|
+
network: "Network",
|
|
340
|
+
address: "Deposit Address",
|
|
341
|
+
amount: "Amount",
|
|
342
|
+
product: "Product or Service",
|
|
343
|
+
minutes: "min",
|
|
344
|
+
seconds: "sec"
|
|
345
|
+
},
|
|
346
|
+
warnings: {
|
|
347
|
+
networkMatch: "Ensure your <strong>wallet network matches</strong> the destination network.",
|
|
348
|
+
noNFT: "Do not send NFTs to this wallet.",
|
|
349
|
+
onlyToken: "Only <strong>{symbol} deposits</strong> are accepted. Sending other tokens may result in loss.",
|
|
350
|
+
timer: "Complete payment within <strong>{time}</strong>. Otherwise, the QR code will expire.",
|
|
351
|
+
selectNetworkLater: "You will be able to select your preferred network later"
|
|
352
|
+
},
|
|
353
|
+
success: {
|
|
354
|
+
message: "Your payment was successful. You will receive an email",
|
|
355
|
+
message2: "shortly.",
|
|
356
|
+
details: "Purchase Details",
|
|
357
|
+
support: "Any doubt or inquiry you can contact support"
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
errors: {
|
|
361
|
+
generic: "An unexpected error occurred.",
|
|
362
|
+
publicKeyMissing: "Public Key is missing",
|
|
363
|
+
config: "Config Error",
|
|
364
|
+
timeout: "The payment time has expired. Please generate a new order."
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
// src/i18n/index.ts
|
|
369
|
+
var I18nService = class {
|
|
370
|
+
// Cambiar idioma
|
|
371
|
+
static setLocale(locale) {
|
|
372
|
+
this._currentLocale = locale;
|
|
373
|
+
this._dictionary = locale === "en" ? en : es;
|
|
374
|
+
}
|
|
375
|
+
static get current() {
|
|
376
|
+
return this._currentLocale;
|
|
377
|
+
}
|
|
378
|
+
// Función para obtener texto (Tipado seguro para claves anidadas sería complejo,
|
|
379
|
+
// así que usaremos acceso directo o un getter helper si lo prefieres)
|
|
380
|
+
static get t() {
|
|
381
|
+
return this._dictionary;
|
|
382
|
+
}
|
|
383
|
+
// Helper para interpolar variables: "Hola {name}" -> "Hola Mundo"
|
|
384
|
+
static interpolate(text, params) {
|
|
385
|
+
return text.replace(/{(\w+)}/g, (match, key) => {
|
|
386
|
+
return typeof params[key] !== "undefined" ? String(params[key]) : match;
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
I18nService._currentLocale = "es";
|
|
391
|
+
I18nService._dictionary = es;
|
|
392
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
393
|
+
0 && (module.exports = {
|
|
394
|
+
ApoloPayClient,
|
|
395
|
+
ClientError,
|
|
396
|
+
ClientResponse,
|
|
397
|
+
ClientResponseBase,
|
|
398
|
+
I18n,
|
|
399
|
+
ModalStep,
|
|
400
|
+
PaymentService
|
|
401
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// src/apolo-pay-client.ts
|
|
2
|
+
var ApoloPayClient = class {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.publicKey = options.publicKey;
|
|
5
|
+
}
|
|
6
|
+
getPublicKey() {
|
|
7
|
+
return this.publicKey;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/types/client-response.ts
|
|
12
|
+
var ClientResponseBase = class {
|
|
13
|
+
constructor({ code, message }) {
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.message = message;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var ClientResponse = class _ClientResponse extends ClientResponseBase {
|
|
19
|
+
constructor({ code, message, result }) {
|
|
20
|
+
super({ code, message });
|
|
21
|
+
this.result = result;
|
|
22
|
+
}
|
|
23
|
+
static fromJson(json, { code, message, result } = {}) {
|
|
24
|
+
const successCode = json.status || code || "success";
|
|
25
|
+
const successMessage = json.message || message || "Success";
|
|
26
|
+
const successResult = result?.(json.result) || json.result || json;
|
|
27
|
+
return new _ClientResponse({ code: successCode, message: successMessage, result: successResult });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var ClientError = class _ClientError extends ClientResponseBase {
|
|
31
|
+
constructor({ code, message, error }) {
|
|
32
|
+
super({ code, message });
|
|
33
|
+
this.error = error;
|
|
34
|
+
}
|
|
35
|
+
static fromError(error, { code, message } = {}) {
|
|
36
|
+
const errCode = error.statusCode || code || "unknown_error";
|
|
37
|
+
const errMessage = error.message || message || "Error desconocido";
|
|
38
|
+
const err = error.error || error;
|
|
39
|
+
return new _ClientError({ code: errCode, message: errMessage, error: err });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/services/repository.ts
|
|
44
|
+
var Repository = class {
|
|
45
|
+
static async getAssets() {
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(`${this.apiUrl}/payment-button/assets`, {
|
|
48
|
+
method: "GET",
|
|
49
|
+
headers: this.headers()
|
|
50
|
+
});
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
return ClientResponse.fromJson(data);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw ClientError.fromError(error, {
|
|
55
|
+
code: "get_assets_error",
|
|
56
|
+
message: "Error al obtener los activos"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
static async fetchQrCodeDetails({
|
|
61
|
+
processId,
|
|
62
|
+
assetId,
|
|
63
|
+
networkId,
|
|
64
|
+
publicKey
|
|
65
|
+
}) {
|
|
66
|
+
try {
|
|
67
|
+
const response = await fetch(`${this.apiUrl}/payment-button/process/confirm`, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: this.headers(publicKey),
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
processId,
|
|
72
|
+
assetId,
|
|
73
|
+
networkId
|
|
74
|
+
})
|
|
75
|
+
}), data = await response.json();
|
|
76
|
+
if (!data.result) {
|
|
77
|
+
throw new ClientError({
|
|
78
|
+
code: data.status || "qr_fetch_error",
|
|
79
|
+
message: data.message || "Error al obtener los detalles del c\xF3digo QR"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const wallet = data.result.wallet;
|
|
83
|
+
const network = data.result.network;
|
|
84
|
+
const address = network === "apolopay" ? `https://p2p.apolopay.app/payment-process/${processId}` : wallet;
|
|
85
|
+
return ClientResponse.fromJson(data, {
|
|
86
|
+
result: (json) => {
|
|
87
|
+
let expiresAtMs = json.expiresAtMs || json.expiresAt || Date.now() + 30 * 60 * 1e3;
|
|
88
|
+
if (typeof expiresAtMs === "string") {
|
|
89
|
+
expiresAtMs = new Date(expiresAtMs).getTime();
|
|
90
|
+
}
|
|
91
|
+
if (typeof expiresAtMs === "number" && expiresAtMs > 1e13) {
|
|
92
|
+
while (expiresAtMs > 2e12) {
|
|
93
|
+
expiresAtMs = Math.floor(expiresAtMs / 1e3);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
...json,
|
|
98
|
+
address,
|
|
99
|
+
qrCodeUrl: `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${address}&ecc=H`,
|
|
100
|
+
paymentUrl: address.startsWith("http") ? address : void 0,
|
|
101
|
+
expiresAtMs: isNaN(expiresAtMs) ? Date.now() + 30 * 60 * 1e3 : expiresAtMs
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw ClientError.fromError(error, {
|
|
107
|
+
code: "fetch_qr_code_details_error",
|
|
108
|
+
message: "Error al obtener los detalles del c\xF3digo QR"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
Repository.apiUrl = "https://pb-test-api.apolopay.app";
|
|
114
|
+
Repository.headers = (publicKey) => {
|
|
115
|
+
const options = {
|
|
116
|
+
"Content-Type": "application/json"
|
|
117
|
+
};
|
|
118
|
+
if (publicKey) options["x-public-key"] = publicKey;
|
|
119
|
+
return options;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/services/socket-service.ts
|
|
123
|
+
import { io } from "socket.io-client";
|
|
124
|
+
var _SocketService = class _SocketService {
|
|
125
|
+
constructor(client) {
|
|
126
|
+
this.sessionOptions = null;
|
|
127
|
+
this.socket = null;
|
|
128
|
+
this.client = client;
|
|
129
|
+
}
|
|
130
|
+
connect(session) {
|
|
131
|
+
if (typeof window === "undefined") return;
|
|
132
|
+
this.sessionOptions = session;
|
|
133
|
+
if (this.socket && this.socket.connected) return this.disconnect();
|
|
134
|
+
this.socket = io(_SocketService.wsUrl, {
|
|
135
|
+
extraHeaders: {
|
|
136
|
+
"x-public-key": this.client.getPublicKey()
|
|
137
|
+
},
|
|
138
|
+
transports: ["polling"]
|
|
139
|
+
});
|
|
140
|
+
const { processId } = session;
|
|
141
|
+
this.socket.on("connect", () => this.socket?.emit("process:connect", { processId }));
|
|
142
|
+
console.log(`Conectado a Socket.io para processId: ${processId}`);
|
|
143
|
+
this.socket.on("process:message", (response) => this.handleWebSocketMessage(response));
|
|
144
|
+
this.socket.on("connect_error", (error) => {
|
|
145
|
+
console.error("Error en conexi\xF3n Socket.io:", error);
|
|
146
|
+
this.sessionOptions?.onError({ code: "connect_error", message: "Error de conexi\xF3n en tiempo real.", error });
|
|
147
|
+
this.disconnect();
|
|
148
|
+
});
|
|
149
|
+
this.socket.on("disconnect", (reason) => {
|
|
150
|
+
console.info(`Socket.io Desconectado: ${reason}`);
|
|
151
|
+
this.socket = null;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
handleWebSocketMessage(response) {
|
|
155
|
+
console.log(response);
|
|
156
|
+
if (!response.success) {
|
|
157
|
+
return this.sessionOptions?.onError({
|
|
158
|
+
code: "payment_failed",
|
|
159
|
+
message: response.message,
|
|
160
|
+
error: response.result
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (response.result.status === "completed") {
|
|
164
|
+
return this.sessionOptions?.onSuccess({
|
|
165
|
+
code: "payment_success",
|
|
166
|
+
message: response.message,
|
|
167
|
+
result: response.result
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
disconnect() {
|
|
172
|
+
if (this.socket) {
|
|
173
|
+
this.socket.disconnect();
|
|
174
|
+
this.socket = null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
_SocketService.wsUrl = "https://pb-test-ws.apolopay.app";
|
|
179
|
+
var SocketService = _SocketService;
|
|
180
|
+
|
|
181
|
+
// src/services/payment-service.ts
|
|
182
|
+
var PaymentService = class {
|
|
183
|
+
constructor(client) {
|
|
184
|
+
this.client = client;
|
|
185
|
+
this.socket = new SocketService(this.client);
|
|
186
|
+
}
|
|
187
|
+
getPublicKey() {
|
|
188
|
+
return this.client.getPublicKey();
|
|
189
|
+
}
|
|
190
|
+
// --- Métodos para obtener datos ---
|
|
191
|
+
async getAssets() {
|
|
192
|
+
const assets = await Repository.getAssets();
|
|
193
|
+
return assets.result;
|
|
194
|
+
}
|
|
195
|
+
// --- Método para obtener datos del QR ---
|
|
196
|
+
async fetchQrCodeDetails(details, session) {
|
|
197
|
+
const qrData = await Repository.fetchQrCodeDetails({
|
|
198
|
+
...details,
|
|
199
|
+
processId: session.processId,
|
|
200
|
+
publicKey: this.client.getPublicKey()
|
|
201
|
+
});
|
|
202
|
+
console.log("qrData", qrData);
|
|
203
|
+
this.socket.connect(session);
|
|
204
|
+
return qrData.result;
|
|
205
|
+
}
|
|
206
|
+
disconnectWebSocket() {
|
|
207
|
+
this.socket.disconnect();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// src/types/modal-step.ts
|
|
212
|
+
var ModalStep = /* @__PURE__ */ ((ModalStep2) => {
|
|
213
|
+
ModalStep2[ModalStep2["SELECT_ASSET"] = 0] = "SELECT_ASSET";
|
|
214
|
+
ModalStep2[ModalStep2["SELECT_NETWORK"] = 1] = "SELECT_NETWORK";
|
|
215
|
+
ModalStep2[ModalStep2["SHOW_QR"] = 2] = "SHOW_QR";
|
|
216
|
+
ModalStep2[ModalStep2["RESULT"] = 3] = "RESULT";
|
|
217
|
+
return ModalStep2;
|
|
218
|
+
})(ModalStep || {});
|
|
219
|
+
|
|
220
|
+
// src/i18n/es.ts
|
|
221
|
+
var es = {
|
|
222
|
+
trigger: {
|
|
223
|
+
loading: "Cargando..."
|
|
224
|
+
},
|
|
225
|
+
modal: {
|
|
226
|
+
titles: {
|
|
227
|
+
selectAsset: 'Selecciona el <span class="highlight">stablecoin</span>',
|
|
228
|
+
selectNetwork: 'Selecciona la <span class="highlight">red</span>',
|
|
229
|
+
scanQr: 'Dep\xF3sito <span class="highlight">{symbol}</span>',
|
|
230
|
+
success: '\xA1Gracias por <span class="highlight">tu compra!</span>',
|
|
231
|
+
error: "Error en el Pago",
|
|
232
|
+
idle: "Estado inesperado"
|
|
233
|
+
},
|
|
234
|
+
subtitles: {
|
|
235
|
+
selectAsset: "Selecciona la stablecoin con la que deseas pagar",
|
|
236
|
+
selectNetwork: "Selecciona la red de tu preferencia",
|
|
237
|
+
idle: "Ocurrio un error inesperado"
|
|
238
|
+
},
|
|
239
|
+
actions: {
|
|
240
|
+
back: "Volver",
|
|
241
|
+
close: "Cerrar",
|
|
242
|
+
support: "Soporte",
|
|
243
|
+
scanApp: 'Escanea con tu celular y continua desde la app de <span style="color: var(--apolo-accent)">Apolo Pay</span>',
|
|
244
|
+
copy: "Copiar",
|
|
245
|
+
copied: "\xA1Copiado!",
|
|
246
|
+
payFromDevice: "Pagar desde este dispositivo"
|
|
247
|
+
},
|
|
248
|
+
labels: {
|
|
249
|
+
network: "Red",
|
|
250
|
+
address: "Direcci\xF3n de dep\xF3sito",
|
|
251
|
+
amount: "Monto",
|
|
252
|
+
product: "Producto o Servicio",
|
|
253
|
+
minutes: "min",
|
|
254
|
+
seconds: "seg"
|
|
255
|
+
},
|
|
256
|
+
warnings: {
|
|
257
|
+
networkMatch: "Aseg\xFArate de que la <strong>red de tu wallet coincida</strong> con la red de destino.",
|
|
258
|
+
noNFT: "No env\xEDes NFTs a esta wallet.",
|
|
259
|
+
onlyToken: "Solo se aceptan <strong>dep\xF3sitos en {symbol}</strong>. El env\xEDo de otro tipo de token podr\xEDa resultar en su p\xE9rdida.",
|
|
260
|
+
timer: "Realiza el pago dentro del tiempo indicado. <strong>{time}</strong> De lo contrario, el c\xF3digo QR se vencer\xE1.",
|
|
261
|
+
selectNetworkLater: "Luego podr\xE1s seleccionar la red de tu preferencia"
|
|
262
|
+
},
|
|
263
|
+
success: {
|
|
264
|
+
message: "Tu pago fue exitoso y en breve recibir\xE1s un correo",
|
|
265
|
+
message2: "con los detalles.",
|
|
266
|
+
details: "Detalles de la compra",
|
|
267
|
+
support: "Cualquier duda o inquietud puedes comunicarte con soporte"
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
errors: {
|
|
271
|
+
generic: "Ocurri\xF3 un error inesperado.",
|
|
272
|
+
publicKeyMissing: "Falta la Public Key",
|
|
273
|
+
config: "Error de Configuraci\xF3n",
|
|
274
|
+
timeout: "El tiempo para realizar el pago ha expirado. Por favor genera una nueva orden."
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// src/i18n/en.ts
|
|
279
|
+
var en = {
|
|
280
|
+
trigger: {
|
|
281
|
+
loading: "Loading..."
|
|
282
|
+
},
|
|
283
|
+
modal: {
|
|
284
|
+
titles: {
|
|
285
|
+
selectAsset: 'Select <span class="highlight">stablecoin</span>',
|
|
286
|
+
selectNetwork: 'Select <span class="highlight">network</span>',
|
|
287
|
+
scanQr: 'Deposit <span class="highlight">{symbol}</span>',
|
|
288
|
+
success: 'Thanks for <span class="highlight">your purchase!</span>',
|
|
289
|
+
error: "Payment Error",
|
|
290
|
+
idle: "Unexpected state"
|
|
291
|
+
},
|
|
292
|
+
subtitles: {
|
|
293
|
+
selectAsset: "Select the stablecoin you want to pay with",
|
|
294
|
+
selectNetwork: "Select your preferred network",
|
|
295
|
+
idle: "An Unexpected error occurred"
|
|
296
|
+
},
|
|
297
|
+
actions: {
|
|
298
|
+
back: "Back",
|
|
299
|
+
close: "Close",
|
|
300
|
+
support: "Support",
|
|
301
|
+
scanApp: 'Scan with your phone and continue from <br><span style="color: var(--apolo-accent)">Apolo Pay</span> app',
|
|
302
|
+
copy: "Copy",
|
|
303
|
+
copied: "Copied!",
|
|
304
|
+
payFromDevice: "Pay from this device"
|
|
305
|
+
},
|
|
306
|
+
labels: {
|
|
307
|
+
network: "Network",
|
|
308
|
+
address: "Deposit Address",
|
|
309
|
+
amount: "Amount",
|
|
310
|
+
product: "Product or Service",
|
|
311
|
+
minutes: "min",
|
|
312
|
+
seconds: "sec"
|
|
313
|
+
},
|
|
314
|
+
warnings: {
|
|
315
|
+
networkMatch: "Ensure your <strong>wallet network matches</strong> the destination network.",
|
|
316
|
+
noNFT: "Do not send NFTs to this wallet.",
|
|
317
|
+
onlyToken: "Only <strong>{symbol} deposits</strong> are accepted. Sending other tokens may result in loss.",
|
|
318
|
+
timer: "Complete payment within <strong>{time}</strong>. Otherwise, the QR code will expire.",
|
|
319
|
+
selectNetworkLater: "You will be able to select your preferred network later"
|
|
320
|
+
},
|
|
321
|
+
success: {
|
|
322
|
+
message: "Your payment was successful. You will receive an email",
|
|
323
|
+
message2: "shortly.",
|
|
324
|
+
details: "Purchase Details",
|
|
325
|
+
support: "Any doubt or inquiry you can contact support"
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
errors: {
|
|
329
|
+
generic: "An unexpected error occurred.",
|
|
330
|
+
publicKeyMissing: "Public Key is missing",
|
|
331
|
+
config: "Config Error",
|
|
332
|
+
timeout: "The payment time has expired. Please generate a new order."
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// src/i18n/index.ts
|
|
337
|
+
var I18nService = class {
|
|
338
|
+
// Cambiar idioma
|
|
339
|
+
static setLocale(locale) {
|
|
340
|
+
this._currentLocale = locale;
|
|
341
|
+
this._dictionary = locale === "en" ? en : es;
|
|
342
|
+
}
|
|
343
|
+
static get current() {
|
|
344
|
+
return this._currentLocale;
|
|
345
|
+
}
|
|
346
|
+
// Función para obtener texto (Tipado seguro para claves anidadas sería complejo,
|
|
347
|
+
// así que usaremos acceso directo o un getter helper si lo prefieres)
|
|
348
|
+
static get t() {
|
|
349
|
+
return this._dictionary;
|
|
350
|
+
}
|
|
351
|
+
// Helper para interpolar variables: "Hola {name}" -> "Hola Mundo"
|
|
352
|
+
static interpolate(text, params) {
|
|
353
|
+
return text.replace(/{(\w+)}/g, (match, key) => {
|
|
354
|
+
return typeof params[key] !== "undefined" ? String(params[key]) : match;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
I18nService._currentLocale = "es";
|
|
359
|
+
I18nService._dictionary = es;
|
|
360
|
+
export {
|
|
361
|
+
ApoloPayClient,
|
|
362
|
+
ClientError,
|
|
363
|
+
ClientResponse,
|
|
364
|
+
ClientResponseBase,
|
|
365
|
+
I18nService as I18n,
|
|
366
|
+
ModalStep,
|
|
367
|
+
PaymentService
|
|
368
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@apolopay-sdk/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"socket.io-client": "4.8.3"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"tsup": "8.5.0",
|
|
20
|
+
"typescript": "5.4.5"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
31
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch"
|
|
32
|
+
}
|
|
33
|
+
}
|