@vindhq/sloud-payment-sdk 1.0.3 → 1.0.5

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.
Files changed (163) hide show
  1. package/README.md +74 -37
  2. package/dist/index.cjs.js +51295 -24
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.d.ts +3 -258
  5. package/dist/index.esm.js +51293 -24
  6. package/dist/index.esm.js.map +1 -0
  7. package/dist/index.umd.js +51301 -24
  8. package/dist/index.umd.js.map +1 -0
  9. package/dist/react/index.esm.js +51440 -0
  10. package/dist/react/index.esm.js.map +1 -0
  11. package/dist/react/rollup.config.d.ts +8 -0
  12. package/dist/react/rollup.config.dts.d.ts +3 -0
  13. package/dist/react/src/components/Button/Button.types.d.ts +6 -0
  14. package/dist/react/src/components/Button/index.d.ts +3 -0
  15. package/dist/react/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
  16. package/dist/react/src/components/CopyToClipboardSpan/index.d.ts +3 -0
  17. package/dist/react/src/components/Input/Input.types.d.ts +17 -0
  18. package/dist/react/src/components/Input/index.d.ts +3 -0
  19. package/dist/react/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
  20. package/dist/react/src/components/TextArea/TextArea.types.d.ts +19 -0
  21. package/dist/react/src/components/TextArea/index.d.ts +3 -0
  22. package/dist/react/src/components/Widget.d.ts +6 -0
  23. package/dist/react/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
  24. package/dist/react/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
  25. package/dist/react/src/components/modals/Modal.d.ts +10 -0
  26. package/dist/react/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
  27. package/dist/react/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
  28. package/dist/react/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
  29. package/dist/react/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
  30. package/dist/react/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
  31. package/dist/react/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
  32. package/dist/react/src/components/modals/state/actions/data.d.ts +10 -0
  33. package/dist/react/src/components/modals/state/actions/index.d.ts +5 -0
  34. package/dist/react/src/components/modals/state/actions/modal.d.ts +5 -0
  35. package/dist/react/src/components/modals/state/actions/payment.d.ts +7 -0
  36. package/dist/react/src/components/modals/state/constants/actionTypes.d.ts +24 -0
  37. package/dist/react/src/components/modals/state/constants/index.d.ts +2 -0
  38. package/dist/react/src/components/modals/state/constants/initialState.d.ts +36 -0
  39. package/dist/react/src/components/modals/state/reducers/data.d.ts +2 -0
  40. package/dist/react/src/components/modals/state/reducers/index.d.ts +2 -0
  41. package/dist/react/src/components/modals/state/reducers/modal.d.ts +2 -0
  42. package/dist/react/src/components/modals/state/reducers/payment.d.ts +2 -0
  43. package/dist/react/src/components/modals/state/types/common.d.ts +12 -0
  44. package/dist/react/src/components/modals/state/types/data.d.ts +34 -0
  45. package/dist/react/src/components/modals/state/types/index.d.ts +8 -0
  46. package/dist/react/src/components/modals/state/types/modal.d.ts +12 -0
  47. package/dist/react/src/components/modals/state/types/payment.d.ts +14 -0
  48. package/dist/react/src/components/modals/state/utils/index.d.ts +37 -0
  49. package/dist/react/src/context/ModalProvider.d.ts +4 -0
  50. package/dist/react/src/context/PaymentInfoContext.d.ts +26 -0
  51. package/dist/react/src/context/PaymentWidgetContext.d.ts +13 -0
  52. package/dist/react/src/context/modal.d.ts +4 -0
  53. package/dist/react/src/context/types.d.ts +28 -0
  54. package/dist/react/src/hooks/types.d.ts +34 -0
  55. package/dist/react/src/hooks/useModalControl.d.ts +27 -0
  56. package/dist/react/src/hooks/usePaymentAPI.d.ts +10 -0
  57. package/dist/react/src/hooks/useShortPolling.d.ts +4 -0
  58. package/dist/react/src/index.d.ts +2 -0
  59. package/dist/react/src/services/config/endpoints.d.ts +9 -0
  60. package/dist/react/src/services/config/error.d.ts +5 -0
  61. package/dist/react/src/services/index.d.ts +27 -0
  62. package/dist/react/src/services/payments/index.d.ts +4 -0
  63. package/dist/react/src/services/payments/types.d.ts +68 -0
  64. package/dist/react/src/services/products/index.d.ts +1 -0
  65. package/dist/react/src/services/products/types.d.ts +124 -0
  66. package/dist/react/src/services/store/index.d.ts +2 -0
  67. package/dist/react/src/services/store/types.d.ts +57 -0
  68. package/dist/react/src/services/utils/widgetConfig.d.ts +20 -0
  69. package/dist/react/src/svg_components/ArrowLeftIcon.d.ts +3 -0
  70. package/dist/react/src/svg_components/BankTransferIcon.d.ts +2 -0
  71. package/dist/react/src/svg_components/CancelIcon.d.ts +7 -0
  72. package/dist/react/src/svg_components/CardIcon.d.ts +2 -0
  73. package/dist/react/src/svg_components/CloseIcon.d.ts +3 -0
  74. package/dist/react/src/svg_components/CopyIcon.d.ts +2 -0
  75. package/dist/react/src/svg_components/EyeCloseIcon.d.ts +5 -0
  76. package/dist/react/src/svg_components/EyeOpenIcon.d.ts +5 -0
  77. package/dist/react/src/svg_components/SloudIcon.d.ts +2 -0
  78. package/dist/react/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
  79. package/dist/react/src/utils/enums/AxiosMethods.d.ts +7 -0
  80. package/dist/react/src/utils/helpers/classNames.d.ts +7 -0
  81. package/dist/react/src/utils/helpers/formatCurrency.d.ts +10 -0
  82. package/dist/react/src/utils/helpers/phoneDefaults.d.ts +3 -0
  83. package/dist/react/src/utils/helpers/validatePhone.d.ts +7 -0
  84. package/dist/react/src/utils/image_utils/index.d.ts +9 -0
  85. package/dist/react/src/utils/storage/index.d.ts +9 -0
  86. package/dist/react/src/widget.d.ts +27 -0
  87. package/dist/rollup.config.d.ts +8 -0
  88. package/dist/rollup.config.dts.d.ts +3 -0
  89. package/dist/src/components/Button/Button.types.d.ts +6 -0
  90. package/dist/src/components/Button/index.d.ts +3 -0
  91. package/dist/src/components/CopyToClipboardSpan/CopyToClipboard.types.d.ts +4 -0
  92. package/dist/src/components/CopyToClipboardSpan/index.d.ts +3 -0
  93. package/dist/src/components/Input/Input.types.d.ts +17 -0
  94. package/dist/src/components/Input/index.d.ts +3 -0
  95. package/dist/src/components/Skeleton/PaymentOptionSkeletons.d.ts +6 -0
  96. package/dist/src/components/TextArea/TextArea.types.d.ts +19 -0
  97. package/dist/src/components/TextArea/index.d.ts +3 -0
  98. package/dist/src/components/Widget.d.ts +6 -0
  99. package/dist/src/components/modals/AwaitingPaymentModal/AwaitingPaymentModal.d.ts +2 -0
  100. package/dist/src/components/modals/AwaitingPaymentTimeoutModal/AwaitingPaymentTimeoutModal.d.ts +2 -0
  101. package/dist/src/components/modals/Modal.d.ts +10 -0
  102. package/dist/src/components/modals/PaymentDetailsModal/PaymentDetailsModal.d.ts +2 -0
  103. package/dist/src/components/modals/PaymentDetailsModal/hooks/useTimer.d.ts +7 -0
  104. package/dist/src/components/modals/PaymentOptionsModal/PaymentOptionsModal.d.ts +2 -0
  105. package/dist/src/components/modals/PaymentOptionsModal/RadioButton.d.ts +11 -0
  106. package/dist/src/components/modals/PaymentOptionsModal/paymentOptionsMap.d.ts +5 -0
  107. package/dist/src/components/modals/SuccessModal/SuccessModal.d.ts +2 -0
  108. package/dist/src/components/modals/state/actions/data.d.ts +10 -0
  109. package/dist/src/components/modals/state/actions/index.d.ts +5 -0
  110. package/dist/src/components/modals/state/actions/modal.d.ts +5 -0
  111. package/dist/src/components/modals/state/actions/payment.d.ts +7 -0
  112. package/dist/src/components/modals/state/constants/actionTypes.d.ts +24 -0
  113. package/dist/src/components/modals/state/constants/index.d.ts +2 -0
  114. package/dist/src/components/modals/state/constants/initialState.d.ts +36 -0
  115. package/dist/src/components/modals/state/reducers/data.d.ts +2 -0
  116. package/dist/src/components/modals/state/reducers/index.d.ts +2 -0
  117. package/dist/src/components/modals/state/reducers/modal.d.ts +2 -0
  118. package/dist/src/components/modals/state/reducers/payment.d.ts +2 -0
  119. package/dist/src/components/modals/state/types/common.d.ts +12 -0
  120. package/dist/src/components/modals/state/types/data.d.ts +34 -0
  121. package/dist/src/components/modals/state/types/index.d.ts +8 -0
  122. package/dist/src/components/modals/state/types/modal.d.ts +12 -0
  123. package/dist/src/components/modals/state/types/payment.d.ts +14 -0
  124. package/dist/src/components/modals/state/utils/index.d.ts +37 -0
  125. package/dist/src/context/ModalProvider.d.ts +4 -0
  126. package/dist/src/context/PaymentInfoContext.d.ts +26 -0
  127. package/dist/src/context/PaymentWidgetContext.d.ts +13 -0
  128. package/dist/src/context/modal.d.ts +4 -0
  129. package/dist/src/context/types.d.ts +28 -0
  130. package/dist/src/hooks/types.d.ts +34 -0
  131. package/dist/src/hooks/useModalControl.d.ts +27 -0
  132. package/dist/src/hooks/usePaymentAPI.d.ts +10 -0
  133. package/dist/src/hooks/useShortPolling.d.ts +4 -0
  134. package/dist/src/index.d.ts +2 -0
  135. package/dist/src/services/config/endpoints.d.ts +9 -0
  136. package/dist/src/services/config/error.d.ts +5 -0
  137. package/dist/src/services/index.d.ts +27 -0
  138. package/dist/src/services/payments/index.d.ts +4 -0
  139. package/dist/src/services/payments/types.d.ts +68 -0
  140. package/dist/src/services/products/index.d.ts +1 -0
  141. package/dist/src/services/products/types.d.ts +124 -0
  142. package/dist/src/services/store/index.d.ts +2 -0
  143. package/dist/src/services/store/types.d.ts +57 -0
  144. package/dist/src/services/utils/widgetConfig.d.ts +20 -0
  145. package/dist/src/svg_components/ArrowLeftIcon.d.ts +3 -0
  146. package/dist/src/svg_components/BankTransferIcon.d.ts +2 -0
  147. package/dist/src/svg_components/CancelIcon.d.ts +7 -0
  148. package/dist/src/svg_components/CardIcon.d.ts +2 -0
  149. package/dist/src/svg_components/CloseIcon.d.ts +3 -0
  150. package/dist/src/svg_components/CopyIcon.d.ts +2 -0
  151. package/dist/src/svg_components/EyeCloseIcon.d.ts +5 -0
  152. package/dist/src/svg_components/EyeOpenIcon.d.ts +5 -0
  153. package/dist/src/svg_components/SloudIcon.d.ts +2 -0
  154. package/dist/src/utils/enums/AxiosErrorCodes.d.ts +7 -0
  155. package/dist/src/utils/enums/AxiosMethods.d.ts +7 -0
  156. package/dist/src/utils/helpers/classNames.d.ts +7 -0
  157. package/dist/src/utils/helpers/formatCurrency.d.ts +10 -0
  158. package/dist/src/utils/helpers/phoneDefaults.d.ts +3 -0
  159. package/dist/src/utils/helpers/validatePhone.d.ts +7 -0
  160. package/dist/src/utils/image_utils/index.d.ts +9 -0
  161. package/dist/src/utils/storage/index.d.ts +9 -0
  162. package/dist/src/widget.d.ts +27 -0
  163. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -1,128 +1,12 @@
1
- /**
2
- * Common fields shared across all payment types
3
- */
4
- interface BasePaymentWidgetOptions {
1
+ interface PaymentWidgetOptions {
5
2
  public_key: string;
6
3
  isLocalEnv?: boolean;
7
- transaction_id?: string;
8
- customer_id?: string;
9
- business_id?: string;
10
- }
11
- interface Customer {
4
+ amount: number;
12
5
  first_name: string;
13
6
  last_name: string;
14
7
  phone_number: string;
15
8
  email: string;
16
9
  }
17
- interface DeliveryDetails {
18
- street: string;
19
- city: string;
20
- state: string;
21
- country: string;
22
- note?: string;
23
- }
24
- interface Product {
25
- product_id: string;
26
- quantity: number;
27
- variation?: string[];
28
- }
29
- /**
30
- * String literal types for payment modes
31
- * These provide better IntelliSense suggestions
32
- */
33
- type PaymentType = "external" | "storefront" | "sloudfront";
34
- /**
35
- * String literal types for channel options
36
- * These provide better IntelliSense suggestions
37
- */
38
- type ChannelType = "pickup" | "delivery";
39
- /**
40
- * Enum for backward compatibility and convenience
41
- * Use either string literals or enum values
42
- */
43
- declare enum ModeType {
44
- Storefront = "storefront",
45
- External = "external",
46
- Sloudfront = "sloudfront"
47
- }
48
- /**
49
- * Options for external payment type
50
- * Used for simple payments with customer details
51
- */
52
- interface ExternalPaymentWidgetOptions extends BasePaymentWidgetOptions {
53
- type: "external";
54
- amount: number;
55
- customer: Customer;
56
- }
57
- /**
58
- * Base options for storefront payment type (shared fields)
59
- */
60
- interface BaseStorefrontPaymentWidgetOptions extends BasePaymentWidgetOptions {
61
- type: "storefront";
62
- slug: string;
63
- amount: number;
64
- discount?: number;
65
- customer: Customer;
66
- products: Product[];
67
- }
68
- /**
69
- * Storefront options when channel is 'pickup' - delivery_details is optional
70
- */
71
- interface StorefrontPickupOptions extends BaseStorefrontPaymentWidgetOptions {
72
- channel: "pickup";
73
- delivery_details?: DeliveryDetails;
74
- }
75
- /**
76
- * Storefront options when channel is 'delivery' - delivery_details is required
77
- */
78
- interface StorefrontDeliveryOptions extends BaseStorefrontPaymentWidgetOptions {
79
- channel: "delivery";
80
- delivery_details: DeliveryDetails;
81
- }
82
- /**
83
- * Options for storefront payment type
84
- * Used for e-commerce orders with products and delivery
85
- * delivery_details is required only when channel is 'delivery'
86
- */
87
- type StorefrontPaymentWidgetOptions = StorefrontPickupOptions | StorefrontDeliveryOptions;
88
- /**
89
- * Base options for sloudfront payment type (shared fields)
90
- */
91
- interface BaseSloudfrontPaymentWidgetOptions extends BasePaymentWidgetOptions {
92
- type: "sloudfront";
93
- amount: number;
94
- discount?: number;
95
- customer: Customer;
96
- products: Product[];
97
- transaction_id?: string;
98
- customer_id: string;
99
- business_id: string;
100
- }
101
- /**
102
- * Sloudfront options when channel is 'pickup' - delivery_details is optional
103
- */
104
- interface SloudfrontPickupOptions extends BaseSloudfrontPaymentWidgetOptions {
105
- channel: "pickup";
106
- delivery_details?: DeliveryDetails;
107
- }
108
- /**
109
- * Sloudfront options when channel is 'delivery' - delivery_details is required
110
- */
111
- interface SloudfrontDeliveryOptions extends BaseSloudfrontPaymentWidgetOptions {
112
- channel: "delivery";
113
- delivery_details: DeliveryDetails;
114
- }
115
- /**
116
- * Options for sloudfront payment type
117
- * delivery_details is required only when channel is 'delivery'
118
- */
119
- type SloudfrontPaymentWidgetOptions = SloudfrontPickupOptions | SloudfrontDeliveryOptions;
120
- /**
121
- * Discriminated union of all payment widget option types
122
- * TypeScript will enforce that the correct fields are provided based on the type
123
- */
124
- type PaymentWidgetOptions = ExternalPaymentWidgetOptions | StorefrontPaymentWidgetOptions | SloudfrontPaymentWidgetOptions;
125
-
126
10
  declare class PaymentWidget {
127
11
  private options;
128
12
  private container;
@@ -142,143 +26,4 @@ declare class PaymentWidget {
142
26
  hidePopup(): void;
143
27
  }
144
28
 
145
- declare class PaymentWidgetValidationError extends Error {
146
- constructor(message: string);
147
- }
148
- /**
149
- * Validates payment widget options based on the type
150
- * @throws {PaymentWidgetValidationError} if validation fails
151
- */
152
- declare function validatePaymentWidgetOptions(options: PaymentWidgetOptions): void;
153
-
154
- interface IExternalPaymentPayload {
155
- type: "external";
156
- amount: number;
157
- customer: {
158
- first_name: string;
159
- last_name: string;
160
- phone_number: string;
161
- email: string;
162
- };
163
- }
164
- interface IStorefrontPaymentPayload {
165
- type: "storefront";
166
- slug: string;
167
- order: {
168
- additional_amount?: number;
169
- discount?: number;
170
- items: Array<{
171
- product_id: string;
172
- quantity: number;
173
- variation?: string[];
174
- }>;
175
- payment_method?: string;
176
- channel?: string;
177
- buyer_details: {
178
- first_name: string;
179
- last_name: string;
180
- email: string;
181
- phone_number: string;
182
- };
183
- delivery_details?: {
184
- street: string;
185
- city: string;
186
- state: string;
187
- country: string;
188
- note?: string;
189
- };
190
- };
191
- }
192
- interface ISloudfrontPaymentPayload {
193
- type: "sloudfront";
194
- manual_order: {
195
- additional_amount?: number;
196
- discount?: number;
197
- items: Array<{
198
- product_id: string;
199
- quantity: number;
200
- variation?: string[];
201
- }>;
202
- payment_method?: string;
203
- channel?: string;
204
- buyer_details?: {
205
- first_name: string;
206
- last_name: string;
207
- email: string;
208
- phone_number: string;
209
- };
210
- delivery_details?: {
211
- street: string;
212
- city: string;
213
- state: string;
214
- country: string;
215
- note?: string;
216
- };
217
- transaction_id?: string;
218
- customer_id: string;
219
- business_id: string;
220
- };
221
- }
222
- type IGeneratePaymentInstrumentPayload = IExternalPaymentPayload | IStorefrontPaymentPayload | ISloudfrontPaymentPayload;
223
-
224
- /**
225
- * Base interface for payload builders
226
- */
227
- interface PayloadBuilder<T extends IGeneratePaymentInstrumentPayload> {
228
- build(options: PaymentWidgetOptions, payment_method?: string): T;
229
- }
230
- /**
231
- * Factory function to build payment instrument payload based on options type
232
- *
233
- * @param options - Payment widget options
234
- * @returns Constructed payload for the payment instrument API
235
- * @throws Error if the payment type is not supported
236
- *
237
- * @example
238
- * // External payment
239
- * const payload = buildPaymentInstrumentPayload({
240
- * type: "external",
241
- * amount: 25000,
242
- * // ... other options
243
- * });
244
- *
245
- * @example
246
- * // Storefront payment
247
- * const payload = buildPaymentInstrumentPayload({
248
- * type: "storefront",
249
- * slug: "my-store",
250
- * products: [...],
251
- * // ... other options
252
- * });
253
- */
254
- declare function buildPaymentInstrumentPayload(options: PaymentWidgetOptions, payment_method?: string): IGeneratePaymentInstrumentPayload;
255
- /**
256
- * Register a new payload builder for a custom payment type
257
- * This allows for extending the system with new payment types without modifying existing code
258
- *
259
- * @param type - The payment type identifier
260
- * @param builder - The payload builder instance
261
- *
262
- * @example
263
- * class SubscriptionPaymentPayloadBuilder implements PayloadBuilder<ISubscriptionPaymentPayload> {
264
- * build(options: PaymentWidgetOptions): ISubscriptionPaymentPayload {
265
- * return {
266
- * type: "subscription",
267
- * plan_id: options.plan_id,
268
- * // ... other fields
269
- * };
270
- * }
271
- * }
272
- *
273
- * registerPayloadBuilder("subscription", new SubscriptionPaymentPayloadBuilder());
274
- */
275
- declare function registerPayloadBuilder(type: string, builder: PayloadBuilder<IGeneratePaymentInstrumentPayload>): void;
276
- /**
277
- * Get all registered payment types
278
- *
279
- * @returns Array of registered payment type identifiers
280
- */
281
- declare function getRegisteredPaymentTypes(): string[];
282
-
283
- export { ModeType, PaymentWidgetValidationError, buildPaymentInstrumentPayload, PaymentWidget as default, getRegisteredPaymentTypes, registerPayloadBuilder, validatePaymentWidgetOptions };
284
- export type { ChannelType, ExternalPaymentWidgetOptions, PaymentType, PaymentWidgetOptions, SloudfrontPaymentWidgetOptions, StorefrontPaymentWidgetOptions };
29
+ export { PaymentWidget as default };