@phonepe-pg/pg-sdk-node 2.0.4

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 (231) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +221 -0
  3. package/dist/src/Env.d.ts +4 -0
  4. package/dist/src/Env.js +23 -0
  5. package/dist/src/EnvConfig.d.ts +11 -0
  6. package/dist/src/EnvConfig.js +42 -0
  7. package/dist/src/common/BaseClient.d.ts +33 -0
  8. package/dist/src/common/BaseClient.js +103 -0
  9. package/dist/src/common/CommonUtils.d.ts +9 -0
  10. package/dist/src/common/CommonUtils.js +45 -0
  11. package/dist/src/common/configs/CredentialConfig.d.ts +25 -0
  12. package/dist/src/common/configs/CredentialConfig.js +64 -0
  13. package/dist/src/common/configs/index.d.ts +1 -0
  14. package/dist/src/common/configs/index.js +32 -0
  15. package/dist/src/common/constants/BaseUrl.d.ts +12 -0
  16. package/dist/src/common/constants/BaseUrl.js +30 -0
  17. package/dist/src/common/constants/Headers.d.ts +16 -0
  18. package/dist/src/common/constants/Headers.js +36 -0
  19. package/dist/src/common/events/Constants.d.ts +10 -0
  20. package/dist/src/common/events/Constants.js +29 -0
  21. package/dist/src/common/events/EventQueueHandler.d.ts +11 -0
  22. package/dist/src/common/events/EventQueueHandler.js +57 -0
  23. package/dist/src/common/events/builders/BaseEventBuilder.d.ts +17 -0
  24. package/dist/src/common/events/builders/BaseEventBuilder.js +46 -0
  25. package/dist/src/common/events/builders/EventBuillder.d.ts +16 -0
  26. package/dist/src/common/events/builders/EventBuillder.js +195 -0
  27. package/dist/src/common/events/builders/EventDataBuilder.d.ts +55 -0
  28. package/dist/src/common/events/builders/EventDataBuilder.js +115 -0
  29. package/dist/src/common/events/models/BaseEvent.d.ts +11 -0
  30. package/dist/src/common/events/models/BaseEvent.js +31 -0
  31. package/dist/src/common/events/models/BulkEvent.d.ts +18 -0
  32. package/dist/src/common/events/models/BulkEvent.js +56 -0
  33. package/dist/src/common/events/models/EventData.d.ts +32 -0
  34. package/dist/src/common/events/models/EventData.js +53 -0
  35. package/dist/src/common/events/models/enums/EventState.d.ts +5 -0
  36. package/dist/src/common/events/models/enums/EventState.js +24 -0
  37. package/dist/src/common/events/models/enums/EventType.d.ts +19 -0
  38. package/dist/src/common/events/models/enums/EventType.js +38 -0
  39. package/dist/src/common/events/models/enums/FlowType.d.ts +3 -0
  40. package/dist/src/common/events/models/enums/FlowType.js +22 -0
  41. package/dist/src/common/events/publisher/DefaultEventPublisher.d.ts +7 -0
  42. package/dist/src/common/events/publisher/DefaultEventPublisher.js +31 -0
  43. package/dist/src/common/events/publisher/EventPublisher.d.ts +6 -0
  44. package/dist/src/common/events/publisher/EventPublisher.js +21 -0
  45. package/dist/src/common/events/publisher/EventPublisherFactory.d.ts +9 -0
  46. package/dist/src/common/events/publisher/EventPublisherFactory.js +38 -0
  47. package/dist/src/common/events/publisher/QueuedEventPublisher.d.ts +21 -0
  48. package/dist/src/common/events/publisher/QueuedEventPublisher.js +124 -0
  49. package/dist/src/common/exception/Constants.d.ts +3 -0
  50. package/dist/src/common/exception/Constants.js +24 -0
  51. package/dist/src/common/exception/Exceptions.d.ts +45 -0
  52. package/dist/src/common/exception/Exceptions.js +102 -0
  53. package/dist/src/common/exception/index.d.ts +1 -0
  54. package/dist/src/common/exception/index.js +32 -0
  55. package/dist/src/common/http/HttpCommand.d.ts +15 -0
  56. package/dist/src/common/http/HttpCommand.js +93 -0
  57. package/dist/src/common/http/HttpMethodType.d.ts +4 -0
  58. package/dist/src/common/http/HttpMethodType.js +23 -0
  59. package/dist/src/common/http/PhonePeResponse.d.ts +12 -0
  60. package/dist/src/common/http/PhonePeResponse.js +21 -0
  61. package/dist/src/common/http/index.d.ts +2 -0
  62. package/dist/src/common/http/index.js +33 -0
  63. package/dist/src/common/index.d.ts +5 -0
  64. package/dist/src/common/index.js +36 -0
  65. package/dist/src/common/models/MetaInfo.d.ts +26 -0
  66. package/dist/src/common/models/MetaInfo.js +61 -0
  67. package/dist/src/common/models/PaymentFlow.d.ts +5 -0
  68. package/dist/src/common/models/PaymentFlow.js +24 -0
  69. package/dist/src/common/models/PaymentFlowType.d.ts +4 -0
  70. package/dist/src/common/models/PaymentFlowType.js +23 -0
  71. package/dist/src/common/models/PgV2InstrumentType.d.ts +9 -0
  72. package/dist/src/common/models/PgV2InstrumentType.js +28 -0
  73. package/dist/src/common/models/index.d.ts +6 -0
  74. package/dist/src/common/models/index.js +37 -0
  75. package/dist/src/common/models/request/AccountConstraint.d.ts +18 -0
  76. package/dist/src/common/models/request/AccountConstraint.js +49 -0
  77. package/dist/src/common/models/request/DeviceContext.d.ts +17 -0
  78. package/dist/src/common/models/request/DeviceContext.js +46 -0
  79. package/dist/src/common/models/request/InstrumentConstraint.d.ts +5 -0
  80. package/dist/src/common/models/request/InstrumentConstraint.js +24 -0
  81. package/dist/src/common/models/request/PaymentInstrumentType.d.ts +3 -0
  82. package/dist/src/common/models/request/PaymentInstrumentType.js +22 -0
  83. package/dist/src/common/models/request/RefundRequest.d.ts +20 -0
  84. package/dist/src/common/models/request/RefundRequest.js +51 -0
  85. package/dist/src/common/models/request/index.d.ts +5 -0
  86. package/dist/src/common/models/request/index.js +36 -0
  87. package/dist/src/common/models/request/instruments/BillingAddress.d.ts +29 -0
  88. package/dist/src/common/models/request/instruments/BillingAddress.js +60 -0
  89. package/dist/src/common/models/request/instruments/CardPayRequestBuilder.d.ts +39 -0
  90. package/dist/src/common/models/request/instruments/CardPayRequestBuilder.js +113 -0
  91. package/dist/src/common/models/request/instruments/CardPaymentV2Instrument.d.ts +22 -0
  92. package/dist/src/common/models/request/instruments/CardPaymentV2Instrument.js +56 -0
  93. package/dist/src/common/models/request/instruments/CollectPaymentDetails.d.ts +5 -0
  94. package/dist/src/common/models/request/instruments/CollectPaymentDetails.js +24 -0
  95. package/dist/src/common/models/request/instruments/CollectPaymentDetailsType.d.ts +4 -0
  96. package/dist/src/common/models/request/instruments/CollectPaymentDetailsType.js +23 -0
  97. package/dist/src/common/models/request/instruments/CollectPaymentV2Instrument.d.ts +19 -0
  98. package/dist/src/common/models/request/instruments/CollectPaymentV2Instrument.js +49 -0
  99. package/dist/src/common/models/request/instruments/Expiry.d.ts +14 -0
  100. package/dist/src/common/models/request/instruments/Expiry.js +43 -0
  101. package/dist/src/common/models/request/instruments/IntentPaymentV2Instrument.d.ts +12 -0
  102. package/dist/src/common/models/request/instruments/IntentPaymentV2Instrument.js +41 -0
  103. package/dist/src/common/models/request/instruments/NetBankingPayRequestBuilder.d.ts +25 -0
  104. package/dist/src/common/models/request/instruments/NetBankingPayRequestBuilder.js +71 -0
  105. package/dist/src/common/models/request/instruments/NetBankingPaymentV2Instrument.d.ts +15 -0
  106. package/dist/src/common/models/request/instruments/NetBankingPaymentV2Instrument.js +46 -0
  107. package/dist/src/common/models/request/instruments/NewCardDetails.d.ts +29 -0
  108. package/dist/src/common/models/request/instruments/NewCardDetails.js +61 -0
  109. package/dist/src/common/models/request/instruments/PaymentV2Instrument.d.ts +7 -0
  110. package/dist/src/common/models/request/instruments/PaymentV2Instrument.js +24 -0
  111. package/dist/src/common/models/request/instruments/PhoneNumberCollectPaymentDetails.d.ts +12 -0
  112. package/dist/src/common/models/request/instruments/PhoneNumberCollectPaymentDetails.js +41 -0
  113. package/dist/src/common/models/request/instruments/TokenDetails.d.ts +39 -0
  114. package/dist/src/common/models/request/instruments/TokenDetails.js +81 -0
  115. package/dist/src/common/models/request/instruments/TokenPayRequestBuilder.d.ts +41 -0
  116. package/dist/src/common/models/request/instruments/TokenPayRequestBuilder.js +118 -0
  117. package/dist/src/common/models/request/instruments/TokenPaymentV2Instrument.d.ts +19 -0
  118. package/dist/src/common/models/request/instruments/TokenPaymentV2Instrument.js +51 -0
  119. package/dist/src/common/models/request/instruments/UpiCollectPayViaPhoneNumberRequestBuilder.d.ts +25 -0
  120. package/dist/src/common/models/request/instruments/UpiCollectPayViaPhoneNumberRequestBuilder.js +73 -0
  121. package/dist/src/common/models/request/instruments/UpiCollectPayViaVpaRequestBuilder.d.ts +25 -0
  122. package/dist/src/common/models/request/instruments/UpiCollectPayViaVpaRequestBuilder.js +71 -0
  123. package/dist/src/common/models/request/instruments/UpiIntentPayRequestBuilder.d.ts +25 -0
  124. package/dist/src/common/models/request/instruments/UpiIntentPayRequestBuilder.js +71 -0
  125. package/dist/src/common/models/request/instruments/UpiQrPaymentV2Instrument.d.ts +9 -0
  126. package/dist/src/common/models/request/instruments/UpiQrPaymentV2Instrument.js +36 -0
  127. package/dist/src/common/models/request/instruments/UpiQrRequestBuilder.d.ts +19 -0
  128. package/dist/src/common/models/request/instruments/UpiQrRequestBuilder.js +55 -0
  129. package/dist/src/common/models/request/instruments/VpaCollectPaymentDetails.d.ts +12 -0
  130. package/dist/src/common/models/request/instruments/VpaCollectPaymentDetails.js +41 -0
  131. package/dist/src/common/models/request/instruments/index.d.ts +21 -0
  132. package/dist/src/common/models/request/instruments/index.js +52 -0
  133. package/dist/src/common/models/response/CallbackData.d.ts +17 -0
  134. package/dist/src/common/models/response/CallbackData.js +21 -0
  135. package/dist/src/common/models/response/CallbackResponse.d.ts +6 -0
  136. package/dist/src/common/models/response/CallbackResponse.js +21 -0
  137. package/dist/src/common/models/response/CallbackType.d.ts +11 -0
  138. package/dist/src/common/models/response/CallbackType.js +30 -0
  139. package/dist/src/common/models/response/InstrumentCombo.d.ts +15 -0
  140. package/dist/src/common/models/response/InstrumentCombo.js +21 -0
  141. package/dist/src/common/models/response/OrderStatusResponse.d.ts +16 -0
  142. package/dist/src/common/models/response/OrderStatusResponse.js +21 -0
  143. package/dist/src/common/models/response/PaymentDetail.d.ts +24 -0
  144. package/dist/src/common/models/response/PaymentDetail.js +21 -0
  145. package/dist/src/common/models/response/PaymentRefundDetail.d.ts +24 -0
  146. package/dist/src/common/models/response/PaymentRefundDetail.js +21 -0
  147. package/dist/src/common/models/response/RefundResponse.d.ts +5 -0
  148. package/dist/src/common/models/response/RefundResponse.js +21 -0
  149. package/dist/src/common/models/response/RefundStatusResponse.d.ts +9 -0
  150. package/dist/src/common/models/response/RefundStatusResponse.js +21 -0
  151. package/dist/src/common/models/response/index.d.ts +11 -0
  152. package/dist/src/common/models/response/index.js +42 -0
  153. package/dist/src/common/models/response/paymentinstruments/AccountInstrumentV2.d.ts +10 -0
  154. package/dist/src/common/models/response/paymentinstruments/AccountInstrumentV2.js +22 -0
  155. package/dist/src/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.d.ts +7 -0
  156. package/dist/src/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.js +22 -0
  157. package/dist/src/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.d.ts +7 -0
  158. package/dist/src/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.js +22 -0
  159. package/dist/src/common/models/response/paymentinstruments/EgvPaymentInstrumentV2.d.ts +5 -0
  160. package/dist/src/common/models/response/paymentinstruments/EgvPaymentInstrumentV2.js +22 -0
  161. package/dist/src/common/models/response/paymentinstruments/NetbankingPaymentInstrumentV2.d.ts +7 -0
  162. package/dist/src/common/models/response/paymentinstruments/NetbankingPaymentInstrumentV2.js +22 -0
  163. package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentType.d.ts +8 -0
  164. package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentType.js +27 -0
  165. package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentV2.d.ts +4 -0
  166. package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentV2.js +21 -0
  167. package/dist/src/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.d.ts +4 -0
  168. package/dist/src/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.js +22 -0
  169. package/dist/src/common/models/response/paymentinstruments/index.d.ts +8 -0
  170. package/dist/src/common/models/response/paymentinstruments/index.js +39 -0
  171. package/dist/src/common/models/response/rails/PaymentRail.d.ts +9 -0
  172. package/dist/src/common/models/response/rails/PaymentRail.js +28 -0
  173. package/dist/src/common/models/response/rails/PgPaymentRail.d.ts +6 -0
  174. package/dist/src/common/models/response/rails/PgPaymentRail.js +22 -0
  175. package/dist/src/common/models/response/rails/PpiEgvPaymentRail.d.ts +3 -0
  176. package/dist/src/common/models/response/rails/PpiEgvPaymentRail.js +22 -0
  177. package/dist/src/common/models/response/rails/PpiWalletPaymentRail.d.ts +3 -0
  178. package/dist/src/common/models/response/rails/PpiWalletPaymentRail.js +22 -0
  179. package/dist/src/common/models/response/rails/UpiPaymentRail.d.ts +6 -0
  180. package/dist/src/common/models/response/rails/UpiPaymentRail.js +22 -0
  181. package/dist/src/common/models/response/rails/index.d.ts +5 -0
  182. package/dist/src/common/models/response/rails/index.js +36 -0
  183. package/dist/src/common/tokenhandler/OAuthRequest.d.ts +6 -0
  184. package/dist/src/common/tokenhandler/OAuthRequest.js +17 -0
  185. package/dist/src/common/tokenhandler/OAuthResponse.d.ts +10 -0
  186. package/dist/src/common/tokenhandler/OAuthResponse.js +52 -0
  187. package/dist/src/common/tokenhandler/TokenConstants.d.ts +4 -0
  188. package/dist/src/common/tokenhandler/TokenConstants.js +23 -0
  189. package/dist/src/common/tokenhandler/TokenService.d.ts +22 -0
  190. package/dist/src/common/tokenhandler/TokenService.js +115 -0
  191. package/dist/src/common/tokenhandler/index.d.ts +2 -0
  192. package/dist/src/common/tokenhandler/index.js +33 -0
  193. package/dist/src/index.d.ts +4 -0
  194. package/dist/src/index.js +35 -0
  195. package/dist/src/payments/v2/CustomCheckoutClient.d.ts +86 -0
  196. package/dist/src/payments/v2/CustomCheckoutClient.js +229 -0
  197. package/dist/src/payments/v2/StandardCheckoutClient.d.ts +86 -0
  198. package/dist/src/payments/v2/StandardCheckoutClient.js +227 -0
  199. package/dist/src/payments/v2/customcheckout/Constants.d.ts +9 -0
  200. package/dist/src/payments/v2/customcheckout/Constants.js +28 -0
  201. package/dist/src/payments/v2/index.d.ts +3 -0
  202. package/dist/src/payments/v2/index.js +34 -0
  203. package/dist/src/payments/v2/models/index.d.ts +2 -0
  204. package/dist/src/payments/v2/models/index.js +33 -0
  205. package/dist/src/payments/v2/models/request/CreateSdkOrderRequest.d.ts +63 -0
  206. package/dist/src/payments/v2/models/request/CreateSdkOrderRequest.js +130 -0
  207. package/dist/src/payments/v2/models/request/CustomCheckoutPayRequest.d.ts +37 -0
  208. package/dist/src/payments/v2/models/request/CustomCheckoutPayRequest.js +79 -0
  209. package/dist/src/payments/v2/models/request/MerchantUrls.d.ts +4 -0
  210. package/dist/src/payments/v2/models/request/MerchantUrls.js +24 -0
  211. package/dist/src/payments/v2/models/request/PgCheckoutPaymentFlow.d.ts +18 -0
  212. package/dist/src/payments/v2/models/request/PgCheckoutPaymentFlow.js +48 -0
  213. package/dist/src/payments/v2/models/request/PgPaymentFlow.d.ts +20 -0
  214. package/dist/src/payments/v2/models/request/PgPaymentFlow.js +50 -0
  215. package/dist/src/payments/v2/models/request/PrefillUserLoginDetails.d.ts +16 -0
  216. package/dist/src/payments/v2/models/request/PrefillUserLoginDetails.js +38 -0
  217. package/dist/src/payments/v2/models/request/StandardCheckoutPayRequest.d.ts +40 -0
  218. package/dist/src/payments/v2/models/request/StandardCheckoutPayRequest.js +82 -0
  219. package/dist/src/payments/v2/models/request/index.d.ts +7 -0
  220. package/dist/src/payments/v2/models/request/index.js +38 -0
  221. package/dist/src/payments/v2/models/response/CreateSdkOrderResponse.d.ts +6 -0
  222. package/dist/src/payments/v2/models/response/CreateSdkOrderResponse.js +21 -0
  223. package/dist/src/payments/v2/models/response/CustomCheckoutPayResponse.d.ts +8 -0
  224. package/dist/src/payments/v2/models/response/CustomCheckoutPayResponse.js +21 -0
  225. package/dist/src/payments/v2/models/response/StandardCheckoutPayResponse.d.ts +6 -0
  226. package/dist/src/payments/v2/models/response/StandardCheckoutPayResponse.js +21 -0
  227. package/dist/src/payments/v2/models/response/index.d.ts +3 -0
  228. package/dist/src/payments/v2/models/response/index.js +34 -0
  229. package/dist/src/payments/v2/standardcheckout/Constants.d.ts +9 -0
  230. package/dist/src/payments/v2/standardcheckout/Constants.js +28 -0
  231. package/package.json +58 -0
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.QueuedEventPublisher = void 0;
28
+ const EventPublisher_1 = require("./EventPublisher");
29
+ const Constants_1 = require("../Constants");
30
+ const HttpCommand_1 = require("../../http/HttpCommand");
31
+ const BulkEvent_1 = require("../models/BulkEvent");
32
+ const Headers_1 = require("../../constants/Headers");
33
+ const http_1 = require("../../http");
34
+ class QueuedEventPublisher extends EventPublisher_1.EventPublisher {
35
+ constructor(httpClient, hostUrl, queueHandler) {
36
+ super();
37
+ this._httpCommand = new HttpCommand_1.HttpCommand(hostUrl, httpClient);
38
+ this._queueHandler = queueHandler;
39
+ this.scheduler = false;
40
+ }
41
+ setAuthTokenSupplier(authTokenSupplier) {
42
+ this._authTokenSupplier = authTokenSupplier;
43
+ }
44
+ startPublishingEvents(authTokenSupplier) {
45
+ this._authTokenSupplier = authTokenSupplier;
46
+ if (this.scheduler == false) {
47
+ this.scheduler = true;
48
+ setTimeout(() => this.run(), Constants_1.Constants.INITIAL_DELAY);
49
+ }
50
+ }
51
+ send(event) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ yield this._queueHandler.add(event);
54
+ });
55
+ }
56
+ run() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (this.scheduler) {
59
+ yield this.sendEvents();
60
+ setTimeout(() => this.run(), Constants_1.Constants.DELAY);
61
+ }
62
+ });
63
+ }
64
+ sendEvents() {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ if (this._queueHandler.isEmpty()) {
68
+ return;
69
+ }
70
+ const bulkEventBatch = yield this.createEventBatches();
71
+ bulkEventBatch.forEach((sdkEventList) => __awaiter(this, void 0, void 0, function* () {
72
+ try {
73
+ yield this.sendBatchData(sdkEventList);
74
+ }
75
+ catch (error) {
76
+ console.error('Error occurred sending events batch to backend', error);
77
+ }
78
+ }));
79
+ }
80
+ catch (error) {
81
+ console.error('Error occurred sending events batch to backend', error);
82
+ }
83
+ });
84
+ }
85
+ sendBatchData(sdkEventList) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const bulkEvent = BulkEvent_1.BulkEvent.builder().events(sdkEventList).build();
88
+ const headers = yield this.getHeaders();
89
+ yield this._httpCommand.request(Constants_1.Constants.EVENTS_ENDPOINT, http_1.HttpMethodType.POST, headers, bulkEvent);
90
+ });
91
+ }
92
+ getHeaders() {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ return {
95
+ [Headers_1.Headers.ACCEPT]: Headers_1.Headers.APPLICATION_JSON,
96
+ [Headers_1.Headers.OAUTH_AUTHORIZATION]: yield this._authTokenSupplier(),
97
+ [Headers_1.Headers.CONTENT_TYPE]: Headers_1.Headers.APPLICATION_JSON,
98
+ };
99
+ });
100
+ }
101
+ createEventBatches() {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const CUR_QUEUE_SIZE = this._queueHandler.size();
104
+ const bulkEventBatch = [];
105
+ let currentBatch = [];
106
+ for (let numEventsProcessed = 0; numEventsProcessed < CUR_QUEUE_SIZE; numEventsProcessed++) {
107
+ const event = yield this._queueHandler.poll();
108
+ if (event == undefined) {
109
+ break;
110
+ }
111
+ currentBatch.push(event);
112
+ if (currentBatch.length == Constants_1.Constants.MAX_EVENTS_IN_BATCH) {
113
+ bulkEventBatch.push(currentBatch);
114
+ currentBatch = [];
115
+ }
116
+ }
117
+ if (currentBatch.length != 0) {
118
+ bulkEventBatch.push(currentBatch);
119
+ }
120
+ return bulkEventBatch;
121
+ });
122
+ }
123
+ }
124
+ exports.QueuedEventPublisher = QueuedEventPublisher;
@@ -0,0 +1,3 @@
1
+ export declare class Constants {
2
+ static readonly CLIENT_EXCEPTION: (client: string) => string;
3
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Constants = void 0;
19
+ class Constants {
20
+ }
21
+ exports.Constants = Constants;
22
+ Constants.CLIENT_EXCEPTION = (client) => {
23
+ return `Cannot re-initialize ${client}. Please utilize the existing client object with required credentials`;
24
+ };
@@ -0,0 +1,45 @@
1
+ import { AxiosResponse } from 'axios';
2
+ export declare class PhonePeException extends Error {
3
+ stack?: undefined;
4
+ type: string;
5
+ httpStatusCode?: number;
6
+ message: string;
7
+ data?: {
8
+ [key: string]: object;
9
+ };
10
+ code?: string;
11
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
12
+ }
13
+ export declare class ClientError extends PhonePeException {
14
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
15
+ }
16
+ export declare class BadRequest extends ClientError {
17
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
18
+ }
19
+ export declare class UnauthorizedAccess extends ClientError {
20
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
21
+ }
22
+ export declare class ForbiddenAccess extends ClientError {
23
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
24
+ }
25
+ export declare class ResourceNotFound extends ClientError {
26
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
27
+ }
28
+ export declare class ResourceConflict extends ClientError {
29
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
30
+ }
31
+ export declare class ResourceGone extends ClientError {
32
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
33
+ }
34
+ export declare class ResourceInvalid extends ClientError {
35
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
36
+ }
37
+ export declare class ExpectationFailed extends ClientError {
38
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
39
+ }
40
+ export declare class TooManyRequests extends ClientError {
41
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
42
+ }
43
+ export declare class ServerError extends PhonePeException {
44
+ constructor(message: string, httpStatusCode?: number, error?: AxiosResponse);
45
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ServerError = exports.TooManyRequests = exports.ExpectationFailed = exports.ResourceInvalid = exports.ResourceGone = exports.ResourceConflict = exports.ResourceNotFound = exports.ForbiddenAccess = exports.UnauthorizedAccess = exports.BadRequest = exports.ClientError = exports.PhonePeException = void 0;
19
+ const PhonePeResponse_1 = require("../http/PhonePeResponse");
20
+ const class_transformer_1 = require("class-transformer");
21
+ class PhonePeException extends Error {
22
+ constructor(message, httpStatusCode, error) {
23
+ var _a;
24
+ super(message);
25
+ this.type = this.constructor.name;
26
+ this.message = message;
27
+ this.httpStatusCode = httpStatusCode;
28
+ if (error != null) {
29
+ const phonePeResponse = (0, class_transformer_1.plainToClass)(PhonePeResponse_1.PhonePeResponse, (_a = error.data) !== null && _a !== void 0 ? _a : {});
30
+ this.code = phonePeResponse.errorCode || phonePeResponse.code;
31
+ this.data = phonePeResponse.context || phonePeResponse.data;
32
+ this.message = phonePeResponse.message || message;
33
+ }
34
+ }
35
+ }
36
+ exports.PhonePeException = PhonePeException;
37
+ class ClientError extends PhonePeException {
38
+ constructor(message, httpStatusCode, error) {
39
+ super(message, httpStatusCode, error);
40
+ }
41
+ }
42
+ exports.ClientError = ClientError;
43
+ class BadRequest extends ClientError {
44
+ constructor(message, httpStatusCode, error) {
45
+ super(message, httpStatusCode, error);
46
+ }
47
+ }
48
+ exports.BadRequest = BadRequest;
49
+ class UnauthorizedAccess extends ClientError {
50
+ constructor(message, httpStatusCode, error) {
51
+ super(message, httpStatusCode, error);
52
+ }
53
+ }
54
+ exports.UnauthorizedAccess = UnauthorizedAccess;
55
+ class ForbiddenAccess extends ClientError {
56
+ constructor(message, httpStatusCode, error) {
57
+ super(message, httpStatusCode, error);
58
+ }
59
+ }
60
+ exports.ForbiddenAccess = ForbiddenAccess;
61
+ class ResourceNotFound extends ClientError {
62
+ constructor(message, httpStatusCode, error) {
63
+ super(message, httpStatusCode, error);
64
+ }
65
+ }
66
+ exports.ResourceNotFound = ResourceNotFound;
67
+ class ResourceConflict extends ClientError {
68
+ constructor(message, httpStatusCode, error) {
69
+ super(message, httpStatusCode, error);
70
+ }
71
+ }
72
+ exports.ResourceConflict = ResourceConflict;
73
+ class ResourceGone extends ClientError {
74
+ constructor(message, httpStatusCode, error) {
75
+ super(message, httpStatusCode, error);
76
+ }
77
+ }
78
+ exports.ResourceGone = ResourceGone;
79
+ class ResourceInvalid extends ClientError {
80
+ constructor(message, httpStatusCode, error) {
81
+ super(message, httpStatusCode, error);
82
+ }
83
+ }
84
+ exports.ResourceInvalid = ResourceInvalid;
85
+ class ExpectationFailed extends ClientError {
86
+ constructor(message, httpStatusCode, error) {
87
+ super(message, httpStatusCode, error);
88
+ }
89
+ }
90
+ exports.ExpectationFailed = ExpectationFailed;
91
+ class TooManyRequests extends ClientError {
92
+ constructor(message, httpStatusCode, error) {
93
+ super(message, httpStatusCode, error);
94
+ }
95
+ }
96
+ exports.TooManyRequests = TooManyRequests;
97
+ class ServerError extends PhonePeException {
98
+ constructor(message, httpStatusCode, error) {
99
+ super(message, httpStatusCode, error);
100
+ }
101
+ }
102
+ exports.ServerError = ServerError;
@@ -0,0 +1 @@
1
+ export * from './Exceptions';
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./Exceptions"), exports);
@@ -0,0 +1,15 @@
1
+ import { HttpMethodType } from './HttpMethodType';
2
+ import { AxiosInstance } from 'axios';
3
+ export declare class HttpCommand {
4
+ private hostUrl;
5
+ private httpClient;
6
+ constructor(hostUrl: string, httpClient: AxiosInstance);
7
+ private getCompleteUrl;
8
+ request: <T>(url: string, method: HttpMethodType, headers?: {
9
+ [key: string]: string;
10
+ }, data?: object, params?: {
11
+ [key: string]: string;
12
+ }) => Promise<T>;
13
+ private makeCall;
14
+ private handleError;
15
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.HttpCommand = void 0;
31
+ const HttpMethodType_1 = require("./HttpMethodType");
32
+ const axios_1 = __importDefault(require("axios"));
33
+ const Exceptions_1 = require("../exception/Exceptions");
34
+ const HTTP_CODE_TO_EXCEPTION_MAPPER = {
35
+ 400: Exceptions_1.BadRequest,
36
+ 401: Exceptions_1.UnauthorizedAccess,
37
+ 403: Exceptions_1.ForbiddenAccess,
38
+ 404: Exceptions_1.ResourceNotFound,
39
+ 409: Exceptions_1.ResourceConflict,
40
+ 410: Exceptions_1.ResourceGone,
41
+ 417: Exceptions_1.ExpectationFailed,
42
+ 422: Exceptions_1.ResourceInvalid,
43
+ 429: Exceptions_1.TooManyRequests,
44
+ };
45
+ class HttpCommand {
46
+ constructor(hostUrl, httpClient) {
47
+ this.getCompleteUrl = (url, params) => {
48
+ const urlFormat = new URL(this.hostUrl + url);
49
+ urlFormat.search = new URLSearchParams(params).toString();
50
+ return urlFormat.toString();
51
+ };
52
+ this.request = (url, method, headers = {}, data = {}, params = {}) => __awaiter(this, void 0, void 0, function* () {
53
+ try {
54
+ const completeUrl = this.getCompleteUrl(url, params);
55
+ const response = yield this.makeCall(completeUrl, method, headers, data, params);
56
+ return response.data;
57
+ }
58
+ catch (error) {
59
+ if (axios_1.default.isAxiosError(error) && error.response) {
60
+ return this.handleError(error.response);
61
+ }
62
+ throw error;
63
+ }
64
+ });
65
+ this.makeCall = (url, method, headers = {}, data = {}, params = {}) => {
66
+ if (HttpMethodType_1.HttpMethodType.GET == method) {
67
+ return this.httpClient.get(url, { params, headers });
68
+ }
69
+ else if (HttpMethodType_1.HttpMethodType.POST == method) {
70
+ return this.httpClient.post(url, data, { headers });
71
+ }
72
+ else {
73
+ throw new Exceptions_1.PhonePeException('Method Not Supported', 405);
74
+ }
75
+ };
76
+ this.handleError = (error) => {
77
+ const responseCode = error.status;
78
+ if (responseCode in HTTP_CODE_TO_EXCEPTION_MAPPER) {
79
+ throw new HTTP_CODE_TO_EXCEPTION_MAPPER[error.status](error.statusText, error.status, error);
80
+ }
81
+ else if (responseCode >= 400 && responseCode <= 499) {
82
+ throw new Exceptions_1.ClientError(error.statusText, error.status, error);
83
+ }
84
+ else if (responseCode >= 500 && responseCode <= 599) {
85
+ throw new Exceptions_1.ServerError(error.statusText, error.status, error);
86
+ }
87
+ throw new Exceptions_1.PhonePeException(error.statusText, error.status, error);
88
+ };
89
+ this.hostUrl = hostUrl;
90
+ this.httpClient = httpClient;
91
+ }
92
+ }
93
+ exports.HttpCommand = HttpCommand;
@@ -0,0 +1,4 @@
1
+ export declare enum HttpMethodType {
2
+ GET = 0,
3
+ POST = 1
4
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HttpMethodType = void 0;
19
+ var HttpMethodType;
20
+ (function (HttpMethodType) {
21
+ HttpMethodType[HttpMethodType["GET"] = 0] = "GET";
22
+ HttpMethodType[HttpMethodType["POST"] = 1] = "POST";
23
+ })(HttpMethodType = exports.HttpMethodType || (exports.HttpMethodType = {}));
@@ -0,0 +1,12 @@
1
+ export declare class PhonePeResponse {
2
+ success?: boolean;
3
+ code?: string;
4
+ message?: string;
5
+ data?: {
6
+ [key: number]: object;
7
+ };
8
+ context?: {
9
+ [key: number]: object;
10
+ };
11
+ errorCode?: string;
12
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PhonePeResponse = void 0;
19
+ class PhonePeResponse {
20
+ }
21
+ exports.PhonePeResponse = PhonePeResponse;
@@ -0,0 +1,2 @@
1
+ export * from './PhonePeResponse';
2
+ export * from './HttpMethodType';
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./PhonePeResponse"), exports);
33
+ __exportStar(require("./HttpMethodType"), exports);
@@ -0,0 +1,5 @@
1
+ export * from './configs';
2
+ export * from './exception';
3
+ export * from './http';
4
+ export * from './tokenhandler';
5
+ export * from './models';
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Original Author(s), PhonePe India Pvt. Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./configs"), exports);
33
+ __exportStar(require("./exception"), exports);
34
+ __exportStar(require("./http"), exports);
35
+ __exportStar(require("./tokenhandler"), exports);
36
+ __exportStar(require("./models"), exports);
@@ -0,0 +1,26 @@
1
+ export declare class MetaInfo {
2
+ udf1?: string;
3
+ udf2?: string;
4
+ udf3?: string;
5
+ udf4?: string;
6
+ udf5?: string;
7
+ constructor(udf1: string, udf2: string, udf3: string, udf4: string, udf5: string);
8
+ static builder(): MetaInfoBuilder;
9
+ }
10
+ declare class MetaInfoBuilder {
11
+ private _udf1;
12
+ private _udf2;
13
+ private _udf3;
14
+ private _udf4;
15
+ private _udf5;
16
+ /**
17
+ * SETTERS
18
+ */
19
+ udf1: (udf1: string) => MetaInfoBuilder;
20
+ udf2: (udf2: string) => MetaInfoBuilder;
21
+ udf3: (udf3: string) => MetaInfoBuilder;
22
+ udf4: (udf4: string) => MetaInfoBuilder;
23
+ udf5: (udf5: string) => MetaInfoBuilder;
24
+ build: () => MetaInfo;
25
+ }
26
+ export {};