@voxepay/checkout 0.4.0 → 0.5.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/dist/api/client.d.ts +28 -5
- package/dist/index.cjs.js +44 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +44 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/voxepay-checkout.min.js +1 -1
- package/dist/voxepay-checkout.min.js.map +1 -1
- package/package.json +1 -1
- package/src/api/client.ts +70 -12
package/src/api/client.ts
CHANGED
|
@@ -55,15 +55,27 @@ export type DVAPaymentStatus =
|
|
|
55
55
|
export interface PaymentStatusResponse {
|
|
56
56
|
id: string;
|
|
57
57
|
transactionRef: string;
|
|
58
|
-
|
|
58
|
+
customerId?: string;
|
|
59
59
|
amount: number;
|
|
60
|
-
|
|
60
|
+
currency: string;
|
|
61
|
+
paymentMethod: 'CARD' | 'BANK_TRANSFER';
|
|
62
|
+
status: DVAPaymentStatus;
|
|
63
|
+
paymentId?: string;
|
|
64
|
+
otpRequired?: boolean;
|
|
65
|
+
authorizationUrl?: string;
|
|
66
|
+
message?: string;
|
|
67
|
+
otpAttempts?: number;
|
|
68
|
+
maxOtpAttempts?: number;
|
|
69
|
+
createdAt: string;
|
|
61
70
|
completedAt?: string;
|
|
62
71
|
virtualAccount?: {
|
|
63
72
|
account_number: string;
|
|
73
|
+
account_name: string;
|
|
74
|
+
bank_name: string;
|
|
75
|
+
bank_code: string;
|
|
76
|
+
expires_at: string;
|
|
64
77
|
status: string;
|
|
65
78
|
};
|
|
66
|
-
[key: string]: unknown;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
export interface ValidateOTPRequest {
|
|
@@ -91,13 +103,22 @@ export interface ResendOTPRequest {
|
|
|
91
103
|
|
|
92
104
|
export class VoxePayApiClient {
|
|
93
105
|
private apiKey: string;
|
|
106
|
+
private bearerToken?: string;
|
|
94
107
|
private baseUrl: string;
|
|
95
108
|
|
|
96
|
-
constructor(apiKey: string, baseUrl?: string) {
|
|
109
|
+
constructor(apiKey: string, baseUrl?: string, bearerToken?: string) {
|
|
97
110
|
this.apiKey = apiKey;
|
|
111
|
+
this.bearerToken = bearerToken;
|
|
98
112
|
this.baseUrl = baseUrl || DEFAULT_BASE_URL;
|
|
99
113
|
}
|
|
100
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Set Bearer token for authenticated endpoints (like getPaymentStatus)
|
|
117
|
+
*/
|
|
118
|
+
setBearerToken(token: string): void {
|
|
119
|
+
this.bearerToken = token;
|
|
120
|
+
}
|
|
121
|
+
|
|
101
122
|
private async request<T>(endpoint: string, body: unknown): Promise<T> {
|
|
102
123
|
const url = `${this.baseUrl}${endpoint}`;
|
|
103
124
|
|
|
@@ -125,15 +146,22 @@ export class VoxePayApiClient {
|
|
|
125
146
|
return data as T;
|
|
126
147
|
}
|
|
127
148
|
|
|
128
|
-
private async get<T>(endpoint: string): Promise<T> {
|
|
149
|
+
private async get<T>(endpoint: string, useBearerAuth = false): Promise<T> {
|
|
129
150
|
const url = `${this.baseUrl}${endpoint}`;
|
|
130
151
|
|
|
152
|
+
const headers: Record<string, string> = {
|
|
153
|
+
'Accept': 'application/json',
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
if (useBearerAuth && this.bearerToken) {
|
|
157
|
+
headers['Authorization'] = `Bearer ${this.bearerToken}`;
|
|
158
|
+
} else {
|
|
159
|
+
headers['X-API-Key'] = this.apiKey;
|
|
160
|
+
}
|
|
161
|
+
|
|
131
162
|
const response = await fetch(url, {
|
|
132
163
|
method: 'GET',
|
|
133
|
-
headers
|
|
134
|
-
'X-API-Key': this.apiKey,
|
|
135
|
-
'Accept': 'application/json',
|
|
136
|
-
},
|
|
164
|
+
headers,
|
|
137
165
|
});
|
|
138
166
|
|
|
139
167
|
const data = await response.json();
|
|
@@ -144,6 +172,7 @@ export class VoxePayApiClient {
|
|
|
144
172
|
error.code = data?.errorCode || data?.code || `HTTP_${response.status}`;
|
|
145
173
|
error.status = response.status;
|
|
146
174
|
error.data = data;
|
|
175
|
+
error.success = data?.success;
|
|
147
176
|
throw error;
|
|
148
177
|
}
|
|
149
178
|
|
|
@@ -181,11 +210,40 @@ export class VoxePayApiClient {
|
|
|
181
210
|
|
|
182
211
|
/**
|
|
183
212
|
* Get payment status by transaction reference (used for polling DVA payments)
|
|
213
|
+
* Uses public endpoint - no authentication required
|
|
214
|
+
* @param transactionRef - The transaction reference to check
|
|
215
|
+
* @param options - Optional query parameters (simulateWebhook, bypassKey)
|
|
184
216
|
*/
|
|
185
|
-
async getPaymentStatus(
|
|
186
|
-
|
|
187
|
-
|
|
217
|
+
async getPaymentStatus(
|
|
218
|
+
transactionRef: string,
|
|
219
|
+
options?: { simulateWebhook?: boolean; bypassKey?: string }
|
|
220
|
+
): Promise<PaymentStatusResponse> {
|
|
221
|
+
let endpoint = `/api/v1/payments/public/${encodeURIComponent(transactionRef)}`;
|
|
222
|
+
|
|
223
|
+
// Add query parameters if provided
|
|
224
|
+
const queryParams: string[] = [];
|
|
225
|
+
if (options?.simulateWebhook !== undefined) {
|
|
226
|
+
queryParams.push(`simulateWebhook=${options.simulateWebhook}`);
|
|
227
|
+
}
|
|
228
|
+
if (options?.bypassKey) {
|
|
229
|
+
queryParams.push(`bypassKey=${encodeURIComponent(options.bypassKey)}`);
|
|
230
|
+
}
|
|
231
|
+
if (queryParams.length > 0) {
|
|
232
|
+
endpoint += `?${queryParams.join('&')}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const response = await this.get<{ success: boolean; message: string; data: PaymentStatusResponse; errorCode?: string }>(
|
|
236
|
+
endpoint,
|
|
237
|
+
false // Use X-API-Key (public endpoint doesn't need Bearer token)
|
|
188
238
|
);
|
|
239
|
+
|
|
240
|
+
if (!response.success) {
|
|
241
|
+
const error: any = new Error(response.message || 'Payment not found');
|
|
242
|
+
error.code = response.errorCode || 'PAYMENT_NOT_FOUND';
|
|
243
|
+
error.success = false;
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
|
|
189
247
|
return response.data;
|
|
190
248
|
}
|
|
191
249
|
}
|