@voxepay/checkout 0.3.2 → 0.3.3
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/package.json +2 -1
- package/src/api/client.ts +110 -0
- package/src/components/modal.ts +1244 -0
- package/src/index.ts +73 -0
- package/src/types.ts +141 -0
- package/src/utils/card-validator.ts +181 -0
- package/src/utils/encryption.ts +496 -0
- package/src/utils/formatter.ts +71 -0
- package/src/voxepay.ts +202 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxepay/checkout",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Modern payment checkout modal for VoxePay - beautiful, fast, and secure",
|
|
5
5
|
"author": "VoxePay",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"dist",
|
|
26
|
+
"src",
|
|
26
27
|
"README.md"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VoxePay Payment API Client
|
|
3
|
+
* Handles communication with the VoxePay payment gateway
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const DEFAULT_BASE_URL = 'https://devpay.voxepay.app';
|
|
7
|
+
|
|
8
|
+
export interface InitiatePaymentRequest {
|
|
9
|
+
organizationId: string;
|
|
10
|
+
transactionRef: string;
|
|
11
|
+
customerId?: string;
|
|
12
|
+
customerEmail?: string;
|
|
13
|
+
customerPhone?: string;
|
|
14
|
+
amount: number;
|
|
15
|
+
currency: string;
|
|
16
|
+
paymentMethod: 'CARD' | 'BANK_TRANSFER';
|
|
17
|
+
authData: string;
|
|
18
|
+
narration?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface InitiatePaymentResponse {
|
|
22
|
+
paymentId: string;
|
|
23
|
+
transactionId: string;
|
|
24
|
+
transactionRef: string;
|
|
25
|
+
status: string;
|
|
26
|
+
message: string;
|
|
27
|
+
eciFlag?: string;
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ValidateOTPRequest {
|
|
32
|
+
paymentId: string;
|
|
33
|
+
otp: string;
|
|
34
|
+
transactionId: string;
|
|
35
|
+
eciFlag?: string;
|
|
36
|
+
organizationId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ValidateOTPResponse {
|
|
40
|
+
status: string;
|
|
41
|
+
message: string;
|
|
42
|
+
paymentId: string;
|
|
43
|
+
transactionRef?: string;
|
|
44
|
+
amount?: number;
|
|
45
|
+
currency?: string;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ResendOTPRequest {
|
|
50
|
+
transactionRef: string;
|
|
51
|
+
organizationId: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class VoxePayApiClient {
|
|
55
|
+
private apiKey: string;
|
|
56
|
+
private baseUrl: string;
|
|
57
|
+
|
|
58
|
+
constructor(apiKey: string, baseUrl?: string) {
|
|
59
|
+
this.apiKey = apiKey;
|
|
60
|
+
this.baseUrl = baseUrl || DEFAULT_BASE_URL;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private async request<T>(endpoint: string, body: unknown): Promise<T> {
|
|
64
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
65
|
+
|
|
66
|
+
const response = await fetch(url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json',
|
|
70
|
+
'X-API-Key': this.apiKey,
|
|
71
|
+
'Accept': 'application/json',
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(body),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const data = await response.json();
|
|
77
|
+
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
const errorMessage = data?.message || data?.error || `Request failed with status ${response.status}`;
|
|
80
|
+
const error: any = new Error(errorMessage);
|
|
81
|
+
error.code = data?.code || `HTTP_${response.status}`;
|
|
82
|
+
error.status = response.status;
|
|
83
|
+
error.data = data;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return data as T;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Initiate a card payment
|
|
92
|
+
*/
|
|
93
|
+
async initiatePayment(data: InitiatePaymentRequest): Promise<InitiatePaymentResponse> {
|
|
94
|
+
return this.request<InitiatePaymentResponse>('/api/v1/payments/initiate', data);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validate OTP for a payment
|
|
99
|
+
*/
|
|
100
|
+
async validateOTP(data: ValidateOTPRequest): Promise<ValidateOTPResponse> {
|
|
101
|
+
return this.request<ValidateOTPResponse>('/api/v1/payments/validate-otp', data);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Resend OTP for a payment
|
|
106
|
+
*/
|
|
107
|
+
async resendOTP(data: ResendOTPRequest): Promise<void> {
|
|
108
|
+
await this.request<unknown>('/api/v1/payments/resend-otp', data);
|
|
109
|
+
}
|
|
110
|
+
}
|