@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,22 @@
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.UpiPaymentRail = void 0;
19
+ const PaymentRail_1 = require("./PaymentRail");
20
+ class UpiPaymentRail extends PaymentRail_1.PaymentRail {
21
+ }
22
+ exports.UpiPaymentRail = UpiPaymentRail;
@@ -0,0 +1,5 @@
1
+ export * from './PgPaymentRail';
2
+ export * from './PpiEgvPaymentRail';
3
+ export * from './PpiWalletPaymentRail';
4
+ export * from './UpiPaymentRail';
5
+ export * from './PaymentRail';
@@ -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("./PgPaymentRail"), exports);
33
+ __exportStar(require("./PpiEgvPaymentRail"), exports);
34
+ __exportStar(require("./PpiWalletPaymentRail"), exports);
35
+ __exportStar(require("./UpiPaymentRail"), exports);
36
+ __exportStar(require("./PaymentRail"), exports);
@@ -0,0 +1,6 @@
1
+ export interface OAuthRequest {
2
+ client_id: string;
3
+ client_secret: string;
4
+ client_version: string;
5
+ grant_type: string;
6
+ }
@@ -0,0 +1,17 @@
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 });
@@ -0,0 +1,10 @@
1
+ export declare class OAuthResponse {
2
+ accessToken: string;
3
+ encryptedAccessToken: string;
4
+ refreshToken: string;
5
+ expiresIn: number;
6
+ issuedAt: number;
7
+ expiresAt: number;
8
+ sessionExpiresAt: number;
9
+ tokenType: string;
10
+ }
@@ -0,0 +1,52 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.OAuthResponse = void 0;
25
+ const class_transformer_1 = require("class-transformer");
26
+ class OAuthResponse {
27
+ }
28
+ __decorate([
29
+ (0, class_transformer_1.Expose)({ name: 'access_token' })
30
+ ], OAuthResponse.prototype, "accessToken", void 0);
31
+ __decorate([
32
+ (0, class_transformer_1.Expose)({ name: 'encrypted_access_token' })
33
+ ], OAuthResponse.prototype, "encryptedAccessToken", void 0);
34
+ __decorate([
35
+ (0, class_transformer_1.Expose)({ name: 'refresh_token' })
36
+ ], OAuthResponse.prototype, "refreshToken", void 0);
37
+ __decorate([
38
+ (0, class_transformer_1.Expose)({ name: 'expires_in' })
39
+ ], OAuthResponse.prototype, "expiresIn", void 0);
40
+ __decorate([
41
+ (0, class_transformer_1.Expose)({ name: 'issued_at' })
42
+ ], OAuthResponse.prototype, "issuedAt", void 0);
43
+ __decorate([
44
+ (0, class_transformer_1.Expose)({ name: 'expires_at' })
45
+ ], OAuthResponse.prototype, "expiresAt", void 0);
46
+ __decorate([
47
+ (0, class_transformer_1.Expose)({ name: 'session_expires_at' })
48
+ ], OAuthResponse.prototype, "sessionExpiresAt", void 0);
49
+ __decorate([
50
+ (0, class_transformer_1.Expose)({ name: 'token_type' })
51
+ ], OAuthResponse.prototype, "tokenType", void 0);
52
+ exports.OAuthResponse = OAuthResponse;
@@ -0,0 +1,4 @@
1
+ export declare class TokenConstants {
2
+ static readonly OAUTH_GRANT_TYPE = "client_credentials";
3
+ static readonly OAUTH_GET_TOKEN = "/v1/oauth/token";
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.TokenConstants = void 0;
19
+ class TokenConstants {
20
+ }
21
+ exports.TokenConstants = TokenConstants;
22
+ TokenConstants.OAUTH_GRANT_TYPE = 'client_credentials';
23
+ TokenConstants.OAUTH_GET_TOKEN = '/v1/oauth/token';
@@ -0,0 +1,22 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { CredentialConfig } from '../configs/CredentialConfig';
3
+ import { Env } from '../../Env';
4
+ import { OAuthResponse } from './OAuthResponse';
5
+ import { EventPublisher } from '../events/publisher/EventPublisher';
6
+ export declare class TokenService {
7
+ private credentialConfig;
8
+ static oAuthResponse: OAuthResponse | null;
9
+ private httpCommand;
10
+ private eventPublisher;
11
+ private mutex;
12
+ set oAuthResponse(oAuthResponse: OAuthResponse);
13
+ constructor(httpClient: AxiosInstance, credentialConfig: CredentialConfig, env: Env, eventPublisher: EventPublisher);
14
+ private prepareRequestHeaders;
15
+ private formatCachedToken;
16
+ private getCurrentTime;
17
+ getOAuthToken: () => Promise<string>;
18
+ private fetchTokenFromPhonePe;
19
+ forceRefreshToken: () => Promise<void>;
20
+ private isCachedTokenValid;
21
+ private prepareFormBody;
22
+ }
@@ -0,0 +1,115 @@
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.TokenService = void 0;
28
+ const OAuthResponse_1 = require("./OAuthResponse");
29
+ const Headers_1 = require("../constants/Headers");
30
+ const TokenConstants_1 = require("./TokenConstants");
31
+ const HttpCommand_1 = require("../http/HttpCommand");
32
+ const HttpMethodType_1 = require("../http/HttpMethodType");
33
+ const class_transformer_1 = require("class-transformer");
34
+ const EnvConfig_1 = require("../../EnvConfig");
35
+ const EventBuillder_1 = require("../events/builders/EventBuillder");
36
+ const EventType_1 = require("../events/models/enums/EventType");
37
+ const async_mutex_1 = require("async-mutex");
38
+ class TokenService {
39
+ set oAuthResponse(oAuthResponse) {
40
+ TokenService.oAuthResponse = oAuthResponse;
41
+ }
42
+ constructor(httpClient, credentialConfig, env, eventPublisher) {
43
+ this.mutex = new async_mutex_1.Mutex();
44
+ this.prepareRequestHeaders = () => {
45
+ return {
46
+ [Headers_1.Headers.CONTENT_TYPE]: Headers_1.Headers.APPLICATION_FORM_URLENCODED,
47
+ [Headers_1.Headers.ACCEPT]: Headers_1.Headers.APPLICATION_JSON,
48
+ };
49
+ };
50
+ this.formatCachedToken = () => {
51
+ var _a, _b;
52
+ return `${(_a = TokenService.oAuthResponse) === null || _a === void 0 ? void 0 : _a.tokenType} ${(_b = TokenService.oAuthResponse) === null || _b === void 0 ? void 0 : _b.accessToken}`;
53
+ };
54
+ this.getCurrentTime = () => {
55
+ return Math.floor(Date.now() / 1000);
56
+ };
57
+ this.getOAuthToken = () => __awaiter(this, void 0, void 0, function* () {
58
+ if (this.isCachedTokenValid()) {
59
+ return this.formatCachedToken();
60
+ }
61
+ try {
62
+ yield this.fetchTokenFromPhonePe();
63
+ }
64
+ catch (error) {
65
+ if (TokenService.oAuthResponse == null) {
66
+ console.warn('No cached token, error occurred while fetching new token', error);
67
+ throw error;
68
+ }
69
+ console.warn('Returning cached token, error occurred while fetching new token', error);
70
+ this.eventPublisher.send((0, EventBuillder_1.buildOAuthEvent)(this.getCurrentTime(), TokenConstants_1.TokenConstants.OAUTH_GET_TOKEN, EventType_1.EventType.OAUTH_FETCH_FAILED_USED_CACHED_TOKEN, error, TokenService.oAuthResponse.issuedAt, TokenService.oAuthResponse.expiresAt));
71
+ }
72
+ return this.formatCachedToken();
73
+ });
74
+ this.fetchTokenFromPhonePe = (forceRefresh = false) => __awaiter(this, void 0, void 0, function* () {
75
+ yield this.mutex.runExclusive(() => __awaiter(this, void 0, void 0, function* () {
76
+ // if multiple operations call the fetchTokenFromPhonePe, first operations will enter and fetch the token, and the subsequent operations will use the fetched token, avoiding unnecessary api call
77
+ if (forceRefresh != true && this.isCachedTokenValid()) {
78
+ return;
79
+ }
80
+ const formBody = this.prepareFormBody();
81
+ const url = TokenConstants_1.TokenConstants.OAUTH_GET_TOKEN;
82
+ const response = yield this.httpCommand.request(url, HttpMethodType_1.HttpMethodType.POST, this.prepareRequestHeaders(), formBody);
83
+ TokenService.oAuthResponse = (0, class_transformer_1.plainToClass)(OAuthResponse_1.OAuthResponse, response);
84
+ }));
85
+ });
86
+ this.forceRefreshToken = () => __awaiter(this, void 0, void 0, function* () {
87
+ yield this.fetchTokenFromPhonePe(true);
88
+ });
89
+ this.isCachedTokenValid = () => {
90
+ var _a, _b;
91
+ if (TokenService.oAuthResponse == null) {
92
+ return false;
93
+ }
94
+ const issuedAt = (_a = TokenService.oAuthResponse) === null || _a === void 0 ? void 0 : _a.issuedAt;
95
+ const expireAt = (_b = TokenService.oAuthResponse) === null || _b === void 0 ? void 0 : _b.expiresAt;
96
+ const currentTime = this.getCurrentTime();
97
+ const reloadTime = Math.floor(issuedAt + (expireAt - issuedAt) / 2);
98
+ return currentTime < reloadTime;
99
+ };
100
+ this.prepareFormBody = () => {
101
+ const formBody = {
102
+ client_id: this.credentialConfig.clientId,
103
+ client_secret: this.credentialConfig.clientSecret,
104
+ client_version: this.credentialConfig.clientVersion.toString(),
105
+ grant_type: TokenConstants_1.TokenConstants.OAUTH_GRANT_TYPE,
106
+ };
107
+ return formBody;
108
+ };
109
+ this.credentialConfig = credentialConfig;
110
+ this.httpCommand = new HttpCommand_1.HttpCommand(EnvConfig_1.EnvConfig.getBaseUrls(env).oAuthHostUrl, httpClient);
111
+ this.eventPublisher = eventPublisher;
112
+ this.eventPublisher.send((0, EventBuillder_1.buildInitClientEvent)(EventType_1.EventType.TOKEN_SERVICE_INITIALIZED));
113
+ }
114
+ }
115
+ exports.TokenService = TokenService;
@@ -0,0 +1,2 @@
1
+ export * from './OAuthResponse';
2
+ export * from './OAuthRequest';
@@ -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("./OAuthResponse"), exports);
33
+ __exportStar(require("./OAuthRequest"), exports);
@@ -0,0 +1,4 @@
1
+ export * from './Env';
2
+ export * from './common';
3
+ export * from './payments/v2';
4
+ export * from './EnvConfig';
@@ -0,0 +1,35 @@
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("./Env"), exports);
33
+ __exportStar(require("./common"), exports);
34
+ __exportStar(require("./payments/v2"), exports);
35
+ __exportStar(require("./EnvConfig"), exports);
@@ -0,0 +1,86 @@
1
+ import { BaseClient } from '../../common/BaseClient';
2
+ import { Env } from '../../Env';
3
+ import { CustomCheckoutPayRequest } from './models/request/CustomCheckoutPayRequest';
4
+ import { RefundRequest } from '../../common/models/request/RefundRequest';
5
+ import { CallbackResponse } from '../../common/models/response/CallbackResponse';
6
+ import { CustomCheckoutPayResponse } from './models/response/CustomCheckoutPayResponse';
7
+ import { OrderStatusResponse } from '../../common/models/response/OrderStatusResponse';
8
+ import { RefundResponse } from '../../common/models/response/RefundResponse';
9
+ import { RefundStatusResponse } from '../../common/models/response/RefundStatusResponse';
10
+ import { CreateSdkOrderRequest } from './models/request/CreateSdkOrderRequest';
11
+ import { CreateSdkOrderResponse } from './models/response/CreateSdkOrderResponse';
12
+ export declare class CustomCheckoutClient extends BaseClient {
13
+ private static _client;
14
+ private headers;
15
+ private constructor();
16
+ /**
17
+ * Generates a CustomCheckout Client for interacting with the PhonePe APIs
18
+ *
19
+ * @param clientId Unique clientId assigned to merchant by PhonePe
20
+ * @param clientSecret Secret provided by PhonePe
21
+ * @param clientVersion The client version used for secure transactions
22
+ * @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the production
23
+ * environment.
24
+ * @param shouldPublishEvents When true, events are sent to PhonePe providing smoother experience
25
+ * @return CustomCheckoutClient object for interacting with the PhonePe APIs
26
+ */
27
+ static getInstance: (clientId: string, clientSecret: string, clientVersion: number, env: Env, shouldPublishEvents?: boolean) => CustomCheckoutClient;
28
+ /**
29
+ * Initiate a Pay Order
30
+ *
31
+ * @param payRequest Request required to initiate the order. Depending on the instrument type, different builders can be used
32
+ * @return Promise<CustomCheckoutPayResponse> which contains the data according to the instrument used
33
+ */
34
+ pay: (payRequest: CustomCheckoutPayRequest) => Promise<CustomCheckoutPayResponse>;
35
+ /**
36
+ * Gets status of an order
37
+ *
38
+ * @param merchantOrderId Order id generated by merchant
39
+ * @param details true -> order status has all attempt details under paymentDetails list
40
+ * false -> order status has only latest attempt details under paymentDetails list
41
+ * @return Promise<OrderStatusResponse> which contains the details about the order
42
+ */
43
+ getOrderStatus: (merchantOrderId: string, details?: boolean) => Promise<OrderStatusResponse>;
44
+ /**
45
+ * Initiate a refund of an order which is in completed state
46
+ *
47
+ * @param refundRequest Request required to initiate the order. It is build using RefundRequest.builder()
48
+ * @return Promise<RefundResponse> which contains the details about the refund
49
+ */
50
+ refund: (refundRequest: RefundRequest) => Promise<RefundResponse>;
51
+ /**
52
+ * Gets the status of refund
53
+ *
54
+ * @param refundId Generated by merchant at the time of initiating the refund
55
+ * @return Promise<RefundStatusResponse> which contains the status about the refund
56
+ */
57
+ getRefundStatus: (refundId: string) => Promise<RefundStatusResponse>;
58
+ /**
59
+ * Gets the status of a transaction attempted
60
+ *
61
+ * @param transactionId Transaction attempt id generated by PhonePe
62
+ * @return Promise<OrderStatusResponse> which contains the details about that specific transactionId
63
+ */
64
+ getTransactionStatus: (transactionId: string) => Promise<OrderStatusResponse>;
65
+ /**
66
+ * Create order token for SDK integrated order requests
67
+ *
68
+ * @param sdkRequest Request object build using CreateSdkOrderRequest.builder()
69
+ * @return Promise<CreateSdkOrderResponse> which contains token details to be consumed by the UI
70
+ */
71
+ createSdkOrder: (sdkRequest: CreateSdkOrderRequest) => Promise<CreateSdkOrderResponse>;
72
+ /**
73
+ * Validate if the callback is valid
74
+ *
75
+ * @param username username set by the merchant on the dashboard
76
+ * @param password password set by the merchant on the dashboard
77
+ * @param authorization String data under `authorization` key of response headers
78
+ * @param responseBody Callback response body
79
+ * @return CallbackResponse Deserialized callback body
80
+ * @throws PhonePeException when callback is not valid
81
+ */
82
+ validateCallback: (username: string, password: string, authorization: string, responseBody: string) => CallbackResponse;
83
+ prepareHeaders: () => {
84
+ [x: string]: string;
85
+ };
86
+ }