@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.
- package/LICENSE +202 -0
- package/README.md +221 -0
- package/dist/src/Env.d.ts +4 -0
- package/dist/src/Env.js +23 -0
- package/dist/src/EnvConfig.d.ts +11 -0
- package/dist/src/EnvConfig.js +42 -0
- package/dist/src/common/BaseClient.d.ts +33 -0
- package/dist/src/common/BaseClient.js +103 -0
- package/dist/src/common/CommonUtils.d.ts +9 -0
- package/dist/src/common/CommonUtils.js +45 -0
- package/dist/src/common/configs/CredentialConfig.d.ts +25 -0
- package/dist/src/common/configs/CredentialConfig.js +64 -0
- package/dist/src/common/configs/index.d.ts +1 -0
- package/dist/src/common/configs/index.js +32 -0
- package/dist/src/common/constants/BaseUrl.d.ts +12 -0
- package/dist/src/common/constants/BaseUrl.js +30 -0
- package/dist/src/common/constants/Headers.d.ts +16 -0
- package/dist/src/common/constants/Headers.js +36 -0
- package/dist/src/common/events/Constants.d.ts +10 -0
- package/dist/src/common/events/Constants.js +29 -0
- package/dist/src/common/events/EventQueueHandler.d.ts +11 -0
- package/dist/src/common/events/EventQueueHandler.js +57 -0
- package/dist/src/common/events/builders/BaseEventBuilder.d.ts +17 -0
- package/dist/src/common/events/builders/BaseEventBuilder.js +46 -0
- package/dist/src/common/events/builders/EventBuillder.d.ts +16 -0
- package/dist/src/common/events/builders/EventBuillder.js +195 -0
- package/dist/src/common/events/builders/EventDataBuilder.d.ts +55 -0
- package/dist/src/common/events/builders/EventDataBuilder.js +115 -0
- package/dist/src/common/events/models/BaseEvent.d.ts +11 -0
- package/dist/src/common/events/models/BaseEvent.js +31 -0
- package/dist/src/common/events/models/BulkEvent.d.ts +18 -0
- package/dist/src/common/events/models/BulkEvent.js +56 -0
- package/dist/src/common/events/models/EventData.d.ts +32 -0
- package/dist/src/common/events/models/EventData.js +53 -0
- package/dist/src/common/events/models/enums/EventState.d.ts +5 -0
- package/dist/src/common/events/models/enums/EventState.js +24 -0
- package/dist/src/common/events/models/enums/EventType.d.ts +19 -0
- package/dist/src/common/events/models/enums/EventType.js +38 -0
- package/dist/src/common/events/models/enums/FlowType.d.ts +3 -0
- package/dist/src/common/events/models/enums/FlowType.js +22 -0
- package/dist/src/common/events/publisher/DefaultEventPublisher.d.ts +7 -0
- package/dist/src/common/events/publisher/DefaultEventPublisher.js +31 -0
- package/dist/src/common/events/publisher/EventPublisher.d.ts +6 -0
- package/dist/src/common/events/publisher/EventPublisher.js +21 -0
- package/dist/src/common/events/publisher/EventPublisherFactory.d.ts +9 -0
- package/dist/src/common/events/publisher/EventPublisherFactory.js +38 -0
- package/dist/src/common/events/publisher/QueuedEventPublisher.d.ts +21 -0
- package/dist/src/common/events/publisher/QueuedEventPublisher.js +124 -0
- package/dist/src/common/exception/Constants.d.ts +3 -0
- package/dist/src/common/exception/Constants.js +24 -0
- package/dist/src/common/exception/Exceptions.d.ts +45 -0
- package/dist/src/common/exception/Exceptions.js +102 -0
- package/dist/src/common/exception/index.d.ts +1 -0
- package/dist/src/common/exception/index.js +32 -0
- package/dist/src/common/http/HttpCommand.d.ts +15 -0
- package/dist/src/common/http/HttpCommand.js +93 -0
- package/dist/src/common/http/HttpMethodType.d.ts +4 -0
- package/dist/src/common/http/HttpMethodType.js +23 -0
- package/dist/src/common/http/PhonePeResponse.d.ts +12 -0
- package/dist/src/common/http/PhonePeResponse.js +21 -0
- package/dist/src/common/http/index.d.ts +2 -0
- package/dist/src/common/http/index.js +33 -0
- package/dist/src/common/index.d.ts +5 -0
- package/dist/src/common/index.js +36 -0
- package/dist/src/common/models/MetaInfo.d.ts +26 -0
- package/dist/src/common/models/MetaInfo.js +61 -0
- package/dist/src/common/models/PaymentFlow.d.ts +5 -0
- package/dist/src/common/models/PaymentFlow.js +24 -0
- package/dist/src/common/models/PaymentFlowType.d.ts +4 -0
- package/dist/src/common/models/PaymentFlowType.js +23 -0
- package/dist/src/common/models/PgV2InstrumentType.d.ts +9 -0
- package/dist/src/common/models/PgV2InstrumentType.js +28 -0
- package/dist/src/common/models/index.d.ts +6 -0
- package/dist/src/common/models/index.js +37 -0
- package/dist/src/common/models/request/AccountConstraint.d.ts +18 -0
- package/dist/src/common/models/request/AccountConstraint.js +49 -0
- package/dist/src/common/models/request/DeviceContext.d.ts +17 -0
- package/dist/src/common/models/request/DeviceContext.js +46 -0
- package/dist/src/common/models/request/InstrumentConstraint.d.ts +5 -0
- package/dist/src/common/models/request/InstrumentConstraint.js +24 -0
- package/dist/src/common/models/request/PaymentInstrumentType.d.ts +3 -0
- package/dist/src/common/models/request/PaymentInstrumentType.js +22 -0
- package/dist/src/common/models/request/RefundRequest.d.ts +20 -0
- package/dist/src/common/models/request/RefundRequest.js +51 -0
- package/dist/src/common/models/request/index.d.ts +5 -0
- package/dist/src/common/models/request/index.js +36 -0
- package/dist/src/common/models/request/instruments/BillingAddress.d.ts +29 -0
- package/dist/src/common/models/request/instruments/BillingAddress.js +60 -0
- package/dist/src/common/models/request/instruments/CardPayRequestBuilder.d.ts +39 -0
- package/dist/src/common/models/request/instruments/CardPayRequestBuilder.js +113 -0
- package/dist/src/common/models/request/instruments/CardPaymentV2Instrument.d.ts +22 -0
- package/dist/src/common/models/request/instruments/CardPaymentV2Instrument.js +56 -0
- package/dist/src/common/models/request/instruments/CollectPaymentDetails.d.ts +5 -0
- package/dist/src/common/models/request/instruments/CollectPaymentDetails.js +24 -0
- package/dist/src/common/models/request/instruments/CollectPaymentDetailsType.d.ts +4 -0
- package/dist/src/common/models/request/instruments/CollectPaymentDetailsType.js +23 -0
- package/dist/src/common/models/request/instruments/CollectPaymentV2Instrument.d.ts +19 -0
- package/dist/src/common/models/request/instruments/CollectPaymentV2Instrument.js +49 -0
- package/dist/src/common/models/request/instruments/Expiry.d.ts +14 -0
- package/dist/src/common/models/request/instruments/Expiry.js +43 -0
- package/dist/src/common/models/request/instruments/IntentPaymentV2Instrument.d.ts +12 -0
- package/dist/src/common/models/request/instruments/IntentPaymentV2Instrument.js +41 -0
- package/dist/src/common/models/request/instruments/NetBankingPayRequestBuilder.d.ts +25 -0
- package/dist/src/common/models/request/instruments/NetBankingPayRequestBuilder.js +71 -0
- package/dist/src/common/models/request/instruments/NetBankingPaymentV2Instrument.d.ts +15 -0
- package/dist/src/common/models/request/instruments/NetBankingPaymentV2Instrument.js +46 -0
- package/dist/src/common/models/request/instruments/NewCardDetails.d.ts +29 -0
- package/dist/src/common/models/request/instruments/NewCardDetails.js +61 -0
- package/dist/src/common/models/request/instruments/PaymentV2Instrument.d.ts +7 -0
- package/dist/src/common/models/request/instruments/PaymentV2Instrument.js +24 -0
- package/dist/src/common/models/request/instruments/PhoneNumberCollectPaymentDetails.d.ts +12 -0
- package/dist/src/common/models/request/instruments/PhoneNumberCollectPaymentDetails.js +41 -0
- package/dist/src/common/models/request/instruments/TokenDetails.d.ts +39 -0
- package/dist/src/common/models/request/instruments/TokenDetails.js +81 -0
- package/dist/src/common/models/request/instruments/TokenPayRequestBuilder.d.ts +41 -0
- package/dist/src/common/models/request/instruments/TokenPayRequestBuilder.js +118 -0
- package/dist/src/common/models/request/instruments/TokenPaymentV2Instrument.d.ts +19 -0
- package/dist/src/common/models/request/instruments/TokenPaymentV2Instrument.js +51 -0
- package/dist/src/common/models/request/instruments/UpiCollectPayViaPhoneNumberRequestBuilder.d.ts +25 -0
- package/dist/src/common/models/request/instruments/UpiCollectPayViaPhoneNumberRequestBuilder.js +73 -0
- package/dist/src/common/models/request/instruments/UpiCollectPayViaVpaRequestBuilder.d.ts +25 -0
- package/dist/src/common/models/request/instruments/UpiCollectPayViaVpaRequestBuilder.js +71 -0
- package/dist/src/common/models/request/instruments/UpiIntentPayRequestBuilder.d.ts +25 -0
- package/dist/src/common/models/request/instruments/UpiIntentPayRequestBuilder.js +71 -0
- package/dist/src/common/models/request/instruments/UpiQrPaymentV2Instrument.d.ts +9 -0
- package/dist/src/common/models/request/instruments/UpiQrPaymentV2Instrument.js +36 -0
- package/dist/src/common/models/request/instruments/UpiQrRequestBuilder.d.ts +19 -0
- package/dist/src/common/models/request/instruments/UpiQrRequestBuilder.js +55 -0
- package/dist/src/common/models/request/instruments/VpaCollectPaymentDetails.d.ts +12 -0
- package/dist/src/common/models/request/instruments/VpaCollectPaymentDetails.js +41 -0
- package/dist/src/common/models/request/instruments/index.d.ts +21 -0
- package/dist/src/common/models/request/instruments/index.js +52 -0
- package/dist/src/common/models/response/CallbackData.d.ts +17 -0
- package/dist/src/common/models/response/CallbackData.js +21 -0
- package/dist/src/common/models/response/CallbackResponse.d.ts +6 -0
- package/dist/src/common/models/response/CallbackResponse.js +21 -0
- package/dist/src/common/models/response/CallbackType.d.ts +11 -0
- package/dist/src/common/models/response/CallbackType.js +30 -0
- package/dist/src/common/models/response/InstrumentCombo.d.ts +15 -0
- package/dist/src/common/models/response/InstrumentCombo.js +21 -0
- package/dist/src/common/models/response/OrderStatusResponse.d.ts +16 -0
- package/dist/src/common/models/response/OrderStatusResponse.js +21 -0
- package/dist/src/common/models/response/PaymentDetail.d.ts +24 -0
- package/dist/src/common/models/response/PaymentDetail.js +21 -0
- package/dist/src/common/models/response/PaymentRefundDetail.d.ts +24 -0
- package/dist/src/common/models/response/PaymentRefundDetail.js +21 -0
- package/dist/src/common/models/response/RefundResponse.d.ts +5 -0
- package/dist/src/common/models/response/RefundResponse.js +21 -0
- package/dist/src/common/models/response/RefundStatusResponse.d.ts +9 -0
- package/dist/src/common/models/response/RefundStatusResponse.js +21 -0
- package/dist/src/common/models/response/index.d.ts +11 -0
- package/dist/src/common/models/response/index.js +42 -0
- package/dist/src/common/models/response/paymentinstruments/AccountInstrumentV2.d.ts +10 -0
- package/dist/src/common/models/response/paymentinstruments/AccountInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.d.ts +7 -0
- package/dist/src/common/models/response/paymentinstruments/CreditCardPaymentInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.d.ts +7 -0
- package/dist/src/common/models/response/paymentinstruments/DebitCardPaymentInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/EgvPaymentInstrumentV2.d.ts +5 -0
- package/dist/src/common/models/response/paymentinstruments/EgvPaymentInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/NetbankingPaymentInstrumentV2.d.ts +7 -0
- package/dist/src/common/models/response/paymentinstruments/NetbankingPaymentInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentType.d.ts +8 -0
- package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentType.js +27 -0
- package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentV2.d.ts +4 -0
- package/dist/src/common/models/response/paymentinstruments/PaymentInstrumentV2.js +21 -0
- package/dist/src/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.d.ts +4 -0
- package/dist/src/common/models/response/paymentinstruments/WalletPaymentInstrumentV2.js +22 -0
- package/dist/src/common/models/response/paymentinstruments/index.d.ts +8 -0
- package/dist/src/common/models/response/paymentinstruments/index.js +39 -0
- package/dist/src/common/models/response/rails/PaymentRail.d.ts +9 -0
- package/dist/src/common/models/response/rails/PaymentRail.js +28 -0
- package/dist/src/common/models/response/rails/PgPaymentRail.d.ts +6 -0
- package/dist/src/common/models/response/rails/PgPaymentRail.js +22 -0
- package/dist/src/common/models/response/rails/PpiEgvPaymentRail.d.ts +3 -0
- package/dist/src/common/models/response/rails/PpiEgvPaymentRail.js +22 -0
- package/dist/src/common/models/response/rails/PpiWalletPaymentRail.d.ts +3 -0
- package/dist/src/common/models/response/rails/PpiWalletPaymentRail.js +22 -0
- package/dist/src/common/models/response/rails/UpiPaymentRail.d.ts +6 -0
- package/dist/src/common/models/response/rails/UpiPaymentRail.js +22 -0
- package/dist/src/common/models/response/rails/index.d.ts +5 -0
- package/dist/src/common/models/response/rails/index.js +36 -0
- package/dist/src/common/tokenhandler/OAuthRequest.d.ts +6 -0
- package/dist/src/common/tokenhandler/OAuthRequest.js +17 -0
- package/dist/src/common/tokenhandler/OAuthResponse.d.ts +10 -0
- package/dist/src/common/tokenhandler/OAuthResponse.js +52 -0
- package/dist/src/common/tokenhandler/TokenConstants.d.ts +4 -0
- package/dist/src/common/tokenhandler/TokenConstants.js +23 -0
- package/dist/src/common/tokenhandler/TokenService.d.ts +22 -0
- package/dist/src/common/tokenhandler/TokenService.js +115 -0
- package/dist/src/common/tokenhandler/index.d.ts +2 -0
- package/dist/src/common/tokenhandler/index.js +33 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +35 -0
- package/dist/src/payments/v2/CustomCheckoutClient.d.ts +86 -0
- package/dist/src/payments/v2/CustomCheckoutClient.js +229 -0
- package/dist/src/payments/v2/StandardCheckoutClient.d.ts +86 -0
- package/dist/src/payments/v2/StandardCheckoutClient.js +227 -0
- package/dist/src/payments/v2/customcheckout/Constants.d.ts +9 -0
- package/dist/src/payments/v2/customcheckout/Constants.js +28 -0
- package/dist/src/payments/v2/index.d.ts +3 -0
- package/dist/src/payments/v2/index.js +34 -0
- package/dist/src/payments/v2/models/index.d.ts +2 -0
- package/dist/src/payments/v2/models/index.js +33 -0
- package/dist/src/payments/v2/models/request/CreateSdkOrderRequest.d.ts +63 -0
- package/dist/src/payments/v2/models/request/CreateSdkOrderRequest.js +130 -0
- package/dist/src/payments/v2/models/request/CustomCheckoutPayRequest.d.ts +37 -0
- package/dist/src/payments/v2/models/request/CustomCheckoutPayRequest.js +79 -0
- package/dist/src/payments/v2/models/request/MerchantUrls.d.ts +4 -0
- package/dist/src/payments/v2/models/request/MerchantUrls.js +24 -0
- package/dist/src/payments/v2/models/request/PgCheckoutPaymentFlow.d.ts +18 -0
- package/dist/src/payments/v2/models/request/PgCheckoutPaymentFlow.js +48 -0
- package/dist/src/payments/v2/models/request/PgPaymentFlow.d.ts +20 -0
- package/dist/src/payments/v2/models/request/PgPaymentFlow.js +50 -0
- package/dist/src/payments/v2/models/request/PrefillUserLoginDetails.d.ts +16 -0
- package/dist/src/payments/v2/models/request/PrefillUserLoginDetails.js +38 -0
- package/dist/src/payments/v2/models/request/StandardCheckoutPayRequest.d.ts +40 -0
- package/dist/src/payments/v2/models/request/StandardCheckoutPayRequest.js +82 -0
- package/dist/src/payments/v2/models/request/index.d.ts +7 -0
- package/dist/src/payments/v2/models/request/index.js +38 -0
- package/dist/src/payments/v2/models/response/CreateSdkOrderResponse.d.ts +6 -0
- package/dist/src/payments/v2/models/response/CreateSdkOrderResponse.js +21 -0
- package/dist/src/payments/v2/models/response/CustomCheckoutPayResponse.d.ts +8 -0
- package/dist/src/payments/v2/models/response/CustomCheckoutPayResponse.js +21 -0
- package/dist/src/payments/v2/models/response/StandardCheckoutPayResponse.d.ts +6 -0
- package/dist/src/payments/v2/models/response/StandardCheckoutPayResponse.js +21 -0
- package/dist/src/payments/v2/models/response/index.d.ts +3 -0
- package/dist/src/payments/v2/models/response/index.js +34 -0
- package/dist/src/payments/v2/standardcheckout/Constants.d.ts +9 -0
- package/dist/src/payments/v2/standardcheckout/Constants.js +28 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 PhonePe Private Limited
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# PhonePe B2B Payment Gateway SDK for Node
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A Node package for seamless integration with PhonePe Payment Gateway APIs.
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Requirements](#requirements)
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Node](#node)
|
|
13
|
+
- [Quick Start](#quick-start)
|
|
14
|
+
- [Initialization](#initialization)
|
|
15
|
+
- [Standard Checkout Flow](#standard-checkout-flow)
|
|
16
|
+
- [Checking Order Status](#checking-order-status)
|
|
17
|
+
- [Handling Callbacks](#handling-callbacks)
|
|
18
|
+
- [SDK Order Integration](#sdk-order-integration)
|
|
19
|
+
- [Documentation](#documentation)
|
|
20
|
+
- [Contributing](#contributing)
|
|
21
|
+
- [License](#license)
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node Version: 14.21
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
### Node
|
|
30
|
+
|
|
31
|
+
Install the dependency using npm:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
npm i https://phonepe.mycloudrepo.io/public/repositories/phonepe-pg-sdk-node/releases/v2/phonepe-pg-sdk-node-2.0.3.tgz
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Initialization
|
|
40
|
+
|
|
41
|
+
Before using the SDK, you need to acquire your credentials from the [PhonePe Merchant Portal](https://developer.phonepe.com/v1/docs/merchant-onboarding).
|
|
42
|
+
|
|
43
|
+
You need three key pieces of information:
|
|
44
|
+
1. `clientId` - Your merchant identifier
|
|
45
|
+
2. `clientSecret` - Your authentication secret
|
|
46
|
+
3. `clientVersion` - API version to use
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
import {StandardCheckoutClient, Env} from 'pg-sdk-node';
|
|
50
|
+
|
|
51
|
+
const clientId = "<clientId>";
|
|
52
|
+
const clientSecret = "<clientSecret>";
|
|
53
|
+
const clientVersion = 1; //insert your client version here
|
|
54
|
+
const env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
|
|
55
|
+
|
|
56
|
+
const client = StandardCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Standard Checkout Flow
|
|
60
|
+
|
|
61
|
+
To initiate a payment, create a request using `StandardCheckoutPayRequest.builder()`:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
import {StandardCheckoutPayRequest} from 'pg-sdk-node';
|
|
65
|
+
import {randomUUID} from 'crypto';
|
|
66
|
+
|
|
67
|
+
const merchantOrderId = randomUUID();
|
|
68
|
+
const amount = 100;
|
|
69
|
+
const redirectUrl = "https://www.merchant.com/redirect";
|
|
70
|
+
|
|
71
|
+
const request = StandardCheckoutPayRequest.builder()
|
|
72
|
+
.merchantOrderId(merchantOrderId)
|
|
73
|
+
.amount(amount)
|
|
74
|
+
.redirectUrl(redirectUrl)
|
|
75
|
+
.build();
|
|
76
|
+
|
|
77
|
+
client.pay(request).then((response)=> {
|
|
78
|
+
const checkoutPageUrl = response.redirectUrl;
|
|
79
|
+
console.log(checkoutPageUrl);
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Redirect the user to checkoutPageUrl to complete the payment
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Checking Order Status
|
|
86
|
+
|
|
87
|
+
To check the status of an order:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
const merchantOrderId = '<MERCHANT_ORDER_ID>'; //Order Id used for creating new order
|
|
91
|
+
|
|
92
|
+
client.getOrderStatus(merchantOrderId).then((response) => {
|
|
93
|
+
const state = response.state;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Handle the state accordingly in your application
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Handling Callbacks
|
|
100
|
+
|
|
101
|
+
PhonePe sends callbacks to your configured endpoint. Validate these callbacks to ensure they're authentic:
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
const authorizationHeaderData = "<FETCH_SHA_256_DATA_FROM_HEADER>" // received in the response headers
|
|
105
|
+
const phonepeS2SCallbackResponseBodyString = "{\"type\": \"PG_ORDER_COMPLETED\",\"payload\": {}}" // receiver in response body
|
|
106
|
+
|
|
107
|
+
const usernameConfigured = "<MERCHANT_USERNAME>"
|
|
108
|
+
const passwordConfigured = "<MERCHANT_PASSWORD>"
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const callbackResponse = client.validateCallback(
|
|
112
|
+
usernameConfigured,
|
|
113
|
+
passwordConfigured,
|
|
114
|
+
authorizationHeaderData,
|
|
115
|
+
phonepeS2SCallbackResponseBodyString );
|
|
116
|
+
|
|
117
|
+
const orderId = callbackResponse.payload.orderId;
|
|
118
|
+
const state = callbackResponse.payload.state;
|
|
119
|
+
|
|
120
|
+
// Process the order based on its state
|
|
121
|
+
} catch (err) {
|
|
122
|
+
// Handle invalid callback - potential security issue
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### SDK Order Integration
|
|
128
|
+
|
|
129
|
+
For mobile SDK integration, first create an order on your server:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import {StandardCheckoutClient, Env, CreateSdkOrderRequest} from 'pg-sdk-node';
|
|
133
|
+
import {randomUUID} from 'crypto';
|
|
134
|
+
|
|
135
|
+
const clientId = "<clientId>";
|
|
136
|
+
const clientSecret = "<clientSecret>";
|
|
137
|
+
const clientVersion = 1; //insert your client version here
|
|
138
|
+
const env = Env.SANDBOX; //change to Env.PRODUCTION when you go live
|
|
139
|
+
|
|
140
|
+
const client = StandardCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env);
|
|
141
|
+
|
|
142
|
+
const merchantOrderId = randomUUID();
|
|
143
|
+
const amount = 1000;
|
|
144
|
+
const redirectUrl = "https://redirectUrl.com";
|
|
145
|
+
|
|
146
|
+
const request = CreateSdkOrderRequest.StandardCheckoutBuilder()
|
|
147
|
+
.merchantOrderId(merchantOrderId)
|
|
148
|
+
.amount(amount)
|
|
149
|
+
.redirectUrl(redirectUrl)
|
|
150
|
+
.build();
|
|
151
|
+
|
|
152
|
+
client.createSdkOrder(request).then((response) => {
|
|
153
|
+
const token = response.token
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
// Pass this token to your mobile app to initiate payment through the PhonePe SDK
|
|
157
|
+
|
|
158
|
+
#### Disabling Payment Retry
|
|
159
|
+
|
|
160
|
+
You can disable the payment retry option for a transaction by setting `disablePaymentRetry` to `true`. This is applicable for both `StandardCheckoutPayRequest` and `CreateSdkOrderRequest`.
|
|
161
|
+
|
|
162
|
+
For `StandardCheckoutPayRequest`:
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
const request = StandardCheckoutPayRequest.builder()
|
|
166
|
+
.merchantOrderId(merchantOrderId)
|
|
167
|
+
.amount(amount)
|
|
168
|
+
.redirectUrl(redirectUrl)
|
|
169
|
+
.disablePaymentRetry(true) // Set to true to disable payment retry
|
|
170
|
+
.build();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
For `CreateSdkOrderRequest`:
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
const request = CreateSdkOrderRequest.StandardCheckoutBuilder()
|
|
177
|
+
.merchantOrderId(merchantOrderId)
|
|
178
|
+
.amount(amount)
|
|
179
|
+
.redirectUrl(redirectUrl)
|
|
180
|
+
.disablePaymentRetry(true) // Set to true to disable payment retry
|
|
181
|
+
.build();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Documentation
|
|
185
|
+
|
|
186
|
+
For detailed API documentation, advanced features, and integration options:
|
|
187
|
+
|
|
188
|
+
- [Standard Checkout Documentation](https://developer.phonepe.com/v1/reference/nodejs-sdk-standard-checkout)
|
|
189
|
+
- [PhonePe Developer Portal](https://developer.phonepe.com/)
|
|
190
|
+
|
|
191
|
+
## Contributing
|
|
192
|
+
|
|
193
|
+
Contributions to PG Node SDK are welcome! Here's how you can contribute:
|
|
194
|
+
|
|
195
|
+
1. Fork the repository
|
|
196
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
197
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
198
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
199
|
+
5. Open a Pull Request
|
|
200
|
+
|
|
201
|
+
Please ensure your code follows the project's coding standards and includes appropriate tests.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
Copyright 2025 PhonePe Private Limited
|
|
209
|
+
|
|
210
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
211
|
+
you may not use this file except in compliance with the License.
|
|
212
|
+
You may obtain a copy of the License at
|
|
213
|
+
|
|
214
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
215
|
+
|
|
216
|
+
Unless required by applicable law or agreed to in writing, software
|
|
217
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
218
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
219
|
+
See the License for the specific language governing permissions and
|
|
220
|
+
limitations under the License.
|
|
221
|
+
```
|
package/dist/src/Env.js
ADDED
|
@@ -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.Env = void 0;
|
|
19
|
+
var Env;
|
|
20
|
+
(function (Env) {
|
|
21
|
+
Env["SANDBOX"] = "SANDBOX";
|
|
22
|
+
Env["PRODUCTION"] = "PRODUCTION";
|
|
23
|
+
})(Env = exports.Env || (exports.Env = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Env } from './Env';
|
|
2
|
+
export declare class EnvConfig {
|
|
3
|
+
private _pgHostUrl;
|
|
4
|
+
private _oAuthHostUrl;
|
|
5
|
+
private _eventsHostUrl;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getBaseUrls(envType: Env): EnvConfig;
|
|
8
|
+
get pgHostUrl(): string;
|
|
9
|
+
get oAuthHostUrl(): string;
|
|
10
|
+
get eventsHostUrl(): string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.EnvConfig = void 0;
|
|
19
|
+
const BaseUrl_1 = require("./common/constants/BaseUrl");
|
|
20
|
+
const Env_1 = require("./Env");
|
|
21
|
+
class EnvConfig {
|
|
22
|
+
constructor(pgHostUrl, oAuthHostUrl, eventsHostUrl) {
|
|
23
|
+
this._pgHostUrl = pgHostUrl;
|
|
24
|
+
this._oAuthHostUrl = oAuthHostUrl;
|
|
25
|
+
this._eventsHostUrl = eventsHostUrl;
|
|
26
|
+
}
|
|
27
|
+
static getBaseUrls(envType) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(BaseUrl_1.BaseUrl, envType))
|
|
29
|
+
return new EnvConfig(BaseUrl_1.BaseUrl[envType].PG_HOST_URL, BaseUrl_1.BaseUrl[envType].OAUTH_HOST_URL, BaseUrl_1.BaseUrl[envType].EVENTS_HOST_URL);
|
|
30
|
+
return new EnvConfig(BaseUrl_1.BaseUrl[Env_1.Env.SANDBOX].PG_HOST_URL, BaseUrl_1.BaseUrl[Env_1.Env.SANDBOX].OAUTH_HOST_URL, BaseUrl_1.BaseUrl[Env_1.Env.SANDBOX].EVENTS_HOST_URL);
|
|
31
|
+
}
|
|
32
|
+
get pgHostUrl() {
|
|
33
|
+
return this._pgHostUrl;
|
|
34
|
+
}
|
|
35
|
+
get oAuthHostUrl() {
|
|
36
|
+
return this._oAuthHostUrl;
|
|
37
|
+
}
|
|
38
|
+
get eventsHostUrl() {
|
|
39
|
+
return this._eventsHostUrl;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.EnvConfig = EnvConfig;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Env } from '../Env';
|
|
3
|
+
import { CredentialConfig } from './configs/CredentialConfig';
|
|
4
|
+
import { TokenService } from './tokenhandler/TokenService';
|
|
5
|
+
import { HttpMethodType } from './http/HttpMethodType';
|
|
6
|
+
import { ClassType } from 'class-transformer-validator';
|
|
7
|
+
import { EventPublisher } from './events/publisher/EventPublisher';
|
|
8
|
+
export declare abstract class BaseClient {
|
|
9
|
+
private readonly _env;
|
|
10
|
+
private readonly _tokenService;
|
|
11
|
+
private readonly _merchantConfig;
|
|
12
|
+
private readonly _httpCommand;
|
|
13
|
+
private readonly _httpClient;
|
|
14
|
+
private readonly _shouldPublishEvents;
|
|
15
|
+
private readonly _eventPublisherFactory;
|
|
16
|
+
private readonly _eventPublisher;
|
|
17
|
+
protected constructor(clientId: string, clientSecret: string, clientVersion: number, env: Env, shouldPublishEvents: boolean);
|
|
18
|
+
protected requestViaAuthRefresh: <T>(method: HttpMethodType, url: string, responseType: ClassType<T>, headers: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
}, data?: object, pathParams?: {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
} | undefined) => Promise<T>;
|
|
23
|
+
private addAuthHeader;
|
|
24
|
+
/**
|
|
25
|
+
* Getters for BaseClient fields
|
|
26
|
+
*/
|
|
27
|
+
get env(): Env;
|
|
28
|
+
get httpClient(): AxiosInstance;
|
|
29
|
+
get tokenService(): TokenService;
|
|
30
|
+
get merchantConfig(): CredentialConfig;
|
|
31
|
+
get shouldPublishEvents(): boolean;
|
|
32
|
+
get eventPublisher(): EventPublisher;
|
|
33
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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.BaseClient = void 0;
|
|
31
|
+
const axios_1 = __importDefault(require("axios"));
|
|
32
|
+
const CredentialConfig_1 = require("./configs/CredentialConfig");
|
|
33
|
+
const TokenService_1 = require("./tokenhandler/TokenService");
|
|
34
|
+
const HttpCommand_1 = require("./http/HttpCommand");
|
|
35
|
+
const Headers_1 = require("./constants/Headers");
|
|
36
|
+
const class_transformer_1 = require("class-transformer");
|
|
37
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
38
|
+
const Exceptions_1 = require("./exception/Exceptions");
|
|
39
|
+
const EnvConfig_1 = require("../EnvConfig");
|
|
40
|
+
const EventPublisherFactory_1 = require("./events/publisher/EventPublisherFactory");
|
|
41
|
+
class BaseClient {
|
|
42
|
+
constructor(clientId, clientSecret, clientVersion, env, shouldPublishEvents) {
|
|
43
|
+
this.requestViaAuthRefresh = (method, url, responseType, headers, data, pathParams) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const httpHeaders = yield this.addAuthHeader(headers);
|
|
45
|
+
try {
|
|
46
|
+
const response = yield this._httpCommand.request(url, method, httpHeaders, data, pathParams);
|
|
47
|
+
const deserializedResponse = (0, class_transformer_1.plainToClass)(responseType, response);
|
|
48
|
+
return deserializedResponse;
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof Exceptions_1.UnauthorizedAccess) {
|
|
52
|
+
yield this.tokenService.forceRefreshToken();
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.addAuthHeader = (headers) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const httpHeaders = Object.assign({}, headers);
|
|
59
|
+
httpHeaders[Headers_1.Headers.OAUTH_AUTHORIZATION] =
|
|
60
|
+
yield this._tokenService.getOAuthToken();
|
|
61
|
+
return httpHeaders;
|
|
62
|
+
});
|
|
63
|
+
this._httpClient = axios_1.default.create();
|
|
64
|
+
this._env = env;
|
|
65
|
+
this._merchantConfig = CredentialConfig_1.CredentialConfig.builder()
|
|
66
|
+
.clientId(clientId)
|
|
67
|
+
.clientSecret(clientSecret)
|
|
68
|
+
.clientVersion(clientVersion)
|
|
69
|
+
.build();
|
|
70
|
+
(0, axios_retry_1.default)(this._httpClient, {
|
|
71
|
+
retries: 0, // No retries
|
|
72
|
+
});
|
|
73
|
+
this._httpCommand = new HttpCommand_1.HttpCommand(EnvConfig_1.EnvConfig.getBaseUrls(env).pgHostUrl, this._httpClient);
|
|
74
|
+
this._shouldPublishEvents = shouldPublishEvents;
|
|
75
|
+
this._eventPublisherFactory = new EventPublisherFactory_1.EventPublisherFactory(this.httpClient, EnvConfig_1.EnvConfig.getBaseUrls(env).eventsHostUrl);
|
|
76
|
+
this._eventPublisher =
|
|
77
|
+
this._eventPublisherFactory.getEventPublisher(shouldPublishEvents);
|
|
78
|
+
this._tokenService = new TokenService_1.TokenService(this._httpClient, this._merchantConfig, env, this._eventPublisher);
|
|
79
|
+
this._eventPublisher.startPublishingEvents(this.tokenService.getOAuthToken);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Getters for BaseClient fields
|
|
83
|
+
*/
|
|
84
|
+
get env() {
|
|
85
|
+
return this._env;
|
|
86
|
+
}
|
|
87
|
+
get httpClient() {
|
|
88
|
+
return this._httpClient;
|
|
89
|
+
}
|
|
90
|
+
get tokenService() {
|
|
91
|
+
return this._tokenService;
|
|
92
|
+
}
|
|
93
|
+
get merchantConfig() {
|
|
94
|
+
return this._merchantConfig;
|
|
95
|
+
}
|
|
96
|
+
get shouldPublishEvents() {
|
|
97
|
+
return this._shouldPublishEvents;
|
|
98
|
+
}
|
|
99
|
+
get eventPublisher() {
|
|
100
|
+
return this._eventPublisher;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.BaseClient = BaseClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare enum SHA_ALGORITHM {
|
|
2
|
+
SHA256 = "SHA256"
|
|
3
|
+
}
|
|
4
|
+
export declare class CommonUtils {
|
|
5
|
+
static calculateSha256(args: object): string;
|
|
6
|
+
static shaHex(data: string, algorithm: SHA_ALGORITHM): string;
|
|
7
|
+
static isCallbackValid(username: string, password: string, authorization: string): boolean;
|
|
8
|
+
}
|
|
9
|
+
export {};
|