@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
|
@@ -0,0 +1,229 @@
|
|
|
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.CustomCheckoutClient = void 0;
|
|
28
|
+
const class_transformer_1 = require("class-transformer");
|
|
29
|
+
const BaseClient_1 = require("../../common/BaseClient");
|
|
30
|
+
const CommonUtils_1 = require("../../common/CommonUtils");
|
|
31
|
+
const Exceptions_1 = require("../../common/exception/Exceptions");
|
|
32
|
+
const HttpMethodType_1 = require("../../common/http/HttpMethodType");
|
|
33
|
+
const Env_1 = require("../../Env");
|
|
34
|
+
const Constants_1 = require("./customcheckout/Constants");
|
|
35
|
+
const CallbackResponse_1 = require("../../common/models/response/CallbackResponse");
|
|
36
|
+
const CustomCheckoutPayResponse_1 = require("./models/response/CustomCheckoutPayResponse");
|
|
37
|
+
const OrderStatusResponse_1 = require("../../common/models/response/OrderStatusResponse");
|
|
38
|
+
const RefundResponse_1 = require("../../common/models/response/RefundResponse");
|
|
39
|
+
const RefundStatusResponse_1 = require("../../common/models/response/RefundStatusResponse");
|
|
40
|
+
const PaymentFlowType_1 = require("../../common/models/PaymentFlowType");
|
|
41
|
+
const CreateSdkOrderResponse_1 = require("./models/response/CreateSdkOrderResponse");
|
|
42
|
+
const Constants_2 = require("../../common/exception/Constants");
|
|
43
|
+
const Headers_1 = require("../../common/constants/Headers");
|
|
44
|
+
const EventType_1 = require("../../common/events/models/enums/EventType");
|
|
45
|
+
const EventState_1 = require("../../common/events/models/enums/EventState");
|
|
46
|
+
const EventBuillder_1 = require("../../common/events/builders/EventBuillder");
|
|
47
|
+
class CustomCheckoutClient extends BaseClient_1.BaseClient {
|
|
48
|
+
constructor(clientId, clientSecret, clientVersion, env, shouldPublishEvents) {
|
|
49
|
+
super(clientId, clientSecret, clientVersion, env, shouldPublishEvents);
|
|
50
|
+
/**
|
|
51
|
+
* Initiate a Pay Order
|
|
52
|
+
*
|
|
53
|
+
* @param payRequest Request required to initiate the order. Depending on the instrument type, different builders can be used
|
|
54
|
+
* @return Promise<CustomCheckoutPayResponse> which contains the data according to the instrument used
|
|
55
|
+
*/
|
|
56
|
+
this.pay = (payRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const url = Constants_1.CustomCheckoutConstants.PAY_API;
|
|
58
|
+
const headers = payRequest.deviceOS
|
|
59
|
+
? Object.assign(Object.assign({}, this.headers), { [Headers_1.Headers.X_DEVICE_OS]: payRequest.deviceOS }) : this.headers;
|
|
60
|
+
try {
|
|
61
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, CustomCheckoutPayResponse_1.CustomCheckoutPayResponse, headers, payRequest);
|
|
62
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCustomCheckoutPayRequest)(EventState_1.EventState.SUCCESS, EventType_1.EventType.PAY_SUCCESS, payRequest, url));
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCustomCheckoutPayRequest)(EventState_1.EventState.FAILED, EventType_1.EventType.PAY_FAILED, payRequest, url, error));
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
/**
|
|
71
|
+
* Gets status of an order
|
|
72
|
+
*
|
|
73
|
+
* @param merchantOrderId Order id generated by merchant
|
|
74
|
+
* @param details true -> order status has all attempt details under paymentDetails list
|
|
75
|
+
* false -> order status has only latest attempt details under paymentDetails list
|
|
76
|
+
* @return Promise<OrderStatusResponse> which contains the details about the order
|
|
77
|
+
*/
|
|
78
|
+
this.getOrderStatus = (merchantOrderId, details = false) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const url = Constants_1.CustomCheckoutConstants.ORDER_STATUS_API.replace('{ORDER_ID}', merchantOrderId);
|
|
80
|
+
try {
|
|
81
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, OrderStatusResponse_1.OrderStatusResponse, this.headers, {}, { [Constants_1.CustomCheckoutConstants.ORDER_DETAILS]: details.toString() });
|
|
82
|
+
this.eventPublisher.send((0, EventBuillder_1.buildOrderStatusEvent)(EventState_1.EventState.SUCCESS, merchantOrderId, PaymentFlowType_1.PaymentFlowType.PG, url, EventType_1.EventType.ORDER_STATUS_SUCCESS));
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.eventPublisher.send((0, EventBuillder_1.buildOrderStatusEvent)(EventState_1.EventState.FAILED, merchantOrderId, PaymentFlowType_1.PaymentFlowType.PG, url, EventType_1.EventType.ORDER_STATUS_FAILED, error));
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Initiate a refund of an order which is in completed state
|
|
92
|
+
*
|
|
93
|
+
* @param refundRequest Request required to initiate the order. It is build using RefundRequest.builder()
|
|
94
|
+
* @return Promise<RefundResponse> which contains the details about the refund
|
|
95
|
+
*/
|
|
96
|
+
this.refund = (refundRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const url = Constants_1.CustomCheckoutConstants.REFUND_API;
|
|
98
|
+
try {
|
|
99
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, RefundResponse_1.RefundResponse, this.headers, refundRequest);
|
|
100
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundEvent)(EventState_1.EventState.SUCCESS, refundRequest, url, PaymentFlowType_1.PaymentFlowType.PG, EventType_1.EventType.REFUND_SUCCESS));
|
|
101
|
+
return response;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundEvent)(EventState_1.EventState.FAILED, refundRequest, url, PaymentFlowType_1.PaymentFlowType.PG, EventType_1.EventType.REFUND_FAILED, error));
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Gets the status of refund
|
|
110
|
+
*
|
|
111
|
+
* @param refundId Generated by merchant at the time of initiating the refund
|
|
112
|
+
* @return Promise<RefundStatusResponse> which contains the status about the refund
|
|
113
|
+
*/
|
|
114
|
+
this.getRefundStatus = (refundId) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const url = Constants_1.CustomCheckoutConstants.REFUND_STATUS_API.replace('{REFUND_ID}', refundId);
|
|
116
|
+
try {
|
|
117
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, RefundStatusResponse_1.RefundStatusResponse, this.headers);
|
|
118
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundStatusEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.REFUND_STATUS_SUCCESS, refundId, url, PaymentFlowType_1.PaymentFlowType.PG));
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundStatusEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.REFUND_STATUS_FAILED, refundId, url, PaymentFlowType_1.PaymentFlowType.PG));
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Gets the status of a transaction attempted
|
|
128
|
+
*
|
|
129
|
+
* @param transactionId Transaction attempt id generated by PhonePe
|
|
130
|
+
* @return Promise<OrderStatusResponse> which contains the details about that specific transactionId
|
|
131
|
+
*/
|
|
132
|
+
this.getTransactionStatus = (transactionId) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
const url = Constants_1.CustomCheckoutConstants.TRANSACTION_STATUS_API.replace('{TRANSACTION_ID}', transactionId);
|
|
134
|
+
try {
|
|
135
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, OrderStatusResponse_1.OrderStatusResponse, this.headers);
|
|
136
|
+
this.eventPublisher.send((0, EventBuillder_1.buildTransactionStatusEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.TRANSACTION_STATUS_SUCCESS, transactionId, url, PaymentFlowType_1.PaymentFlowType.PG));
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
this.eventPublisher.send((0, EventBuillder_1.buildTransactionStatusEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.TRANSACTION_STATUS_FAILED, transactionId, url, PaymentFlowType_1.PaymentFlowType.PG, error));
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
/**
|
|
145
|
+
* Create order token for SDK integrated order requests
|
|
146
|
+
*
|
|
147
|
+
* @param sdkRequest Request object build using CreateSdkOrderRequest.builder()
|
|
148
|
+
* @return Promise<CreateSdkOrderResponse> which contains token details to be consumed by the UI
|
|
149
|
+
*/
|
|
150
|
+
this.createSdkOrder = (sdkRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
const url = Constants_1.CustomCheckoutConstants.CREATE_ORDER_API;
|
|
152
|
+
try {
|
|
153
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, CreateSdkOrderResponse_1.CreateSdkOrderResponse, this.headers, sdkRequest);
|
|
154
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCreateSdkOrderEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.CREATE_SDK_ORDER_SUCCESS, sdkRequest, url, PaymentFlowType_1.PaymentFlowType.PG));
|
|
155
|
+
return response;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCreateSdkOrderEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.CREATE_SDK_ORDER_SUCCESS, sdkRequest, url, PaymentFlowType_1.PaymentFlowType.PG));
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* Validate if the callback is valid
|
|
164
|
+
*
|
|
165
|
+
* @param username username set by the merchant on the dashboard
|
|
166
|
+
* @param password password set by the merchant on the dashboard
|
|
167
|
+
* @param authorization String data under `authorization` key of response headers
|
|
168
|
+
* @param responseBody Callback response body
|
|
169
|
+
* @return CallbackResponse Deserialized callback body
|
|
170
|
+
* @throws PhonePeException when callback is not valid
|
|
171
|
+
*/
|
|
172
|
+
this.validateCallback = (username, password, authorization, responseBody) => {
|
|
173
|
+
if (!CommonUtils_1.CommonUtils.isCallbackValid(username, password, authorization)) {
|
|
174
|
+
throw new Exceptions_1.PhonePeException('Invalid Callback', 417);
|
|
175
|
+
}
|
|
176
|
+
const parsedBody = JSON.parse(responseBody);
|
|
177
|
+
return (0, class_transformer_1.plainToClass)(CallbackResponse_1.CallbackResponse, parsedBody);
|
|
178
|
+
};
|
|
179
|
+
this.prepareHeaders = () => {
|
|
180
|
+
return {
|
|
181
|
+
[Headers_1.Headers.CONTENT_TYPE]: Headers_1.Headers.APPLICATION_JSON,
|
|
182
|
+
[Headers_1.Headers.SOURCE]: Headers_1.Headers.INTEGRATION,
|
|
183
|
+
[Headers_1.Headers.SOURCE_VERSION]: Headers_1.Headers.API_VERSION,
|
|
184
|
+
[Headers_1.Headers.SOURCE_PLATFORM]: Headers_1.Headers.SDK_TYPE,
|
|
185
|
+
[Headers_1.Headers.SOURCE_PLATFORM_VERSION]: Headers_1.Headers.SDK_VERSION,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
this.eventPublisher.send((0, EventBuillder_1.buildInitClientEvent)(EventType_1.EventType.CUSTOM_CHECKOUT_CLIENT_INITIALIZED, PaymentFlowType_1.PaymentFlowType.PG));
|
|
189
|
+
this.headers = this.prepareHeaders();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.CustomCheckoutClient = CustomCheckoutClient;
|
|
193
|
+
/**
|
|
194
|
+
* Generates a CustomCheckout Client for interacting with the PhonePe APIs
|
|
195
|
+
*
|
|
196
|
+
* @param clientId Unique clientId assigned to merchant by PhonePe
|
|
197
|
+
* @param clientSecret Secret provided by PhonePe
|
|
198
|
+
* @param clientVersion The client version used for secure transactions
|
|
199
|
+
* @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the production
|
|
200
|
+
* environment.
|
|
201
|
+
* @param shouldPublishEvents When true, events are sent to PhonePe providing smoother experience
|
|
202
|
+
* @return CustomCheckoutClient object for interacting with the PhonePe APIs
|
|
203
|
+
*/
|
|
204
|
+
CustomCheckoutClient.getInstance = (clientId, clientSecret, clientVersion, env, shouldPublishEvents = true) => {
|
|
205
|
+
shouldPublishEvents = shouldPublishEvents && env == Env_1.Env.PRODUCTION;
|
|
206
|
+
if (CustomCheckoutClient._client == undefined) {
|
|
207
|
+
CustomCheckoutClient._client = new CustomCheckoutClient(clientId, clientSecret, clientVersion, env, shouldPublishEvents);
|
|
208
|
+
return CustomCheckoutClient._client;
|
|
209
|
+
}
|
|
210
|
+
const requestedClientSHA = CommonUtils_1.CommonUtils.calculateSha256({
|
|
211
|
+
clientId: clientId,
|
|
212
|
+
clientSecret: clientSecret,
|
|
213
|
+
clientVersion: clientVersion,
|
|
214
|
+
env: env,
|
|
215
|
+
shouldPublishEvents: shouldPublishEvents,
|
|
216
|
+
paymentFlowType: PaymentFlowType_1.PaymentFlowType.PG,
|
|
217
|
+
});
|
|
218
|
+
const cachedClientSHA = CommonUtils_1.CommonUtils.calculateSha256({
|
|
219
|
+
clientId: CustomCheckoutClient._client.merchantConfig.clientId,
|
|
220
|
+
clientSecret: CustomCheckoutClient._client.merchantConfig.clientSecret,
|
|
221
|
+
clientVersion: CustomCheckoutClient._client.merchantConfig.clientVersion,
|
|
222
|
+
env: CustomCheckoutClient._client.env,
|
|
223
|
+
shouldPublishEvents: CustomCheckoutClient._client.shouldPublishEvents,
|
|
224
|
+
paymentFlowType: PaymentFlowType_1.PaymentFlowType.PG,
|
|
225
|
+
});
|
|
226
|
+
if (requestedClientSHA == cachedClientSHA)
|
|
227
|
+
return CustomCheckoutClient._client;
|
|
228
|
+
throw new Exceptions_1.PhonePeException(Constants_2.Constants.CLIENT_EXCEPTION(CustomCheckoutClient._client.constructor.name));
|
|
229
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BaseClient } from '../../common/BaseClient';
|
|
2
|
+
import { Env } from '../../Env';
|
|
3
|
+
import { StandardCheckoutPayRequest } from './models/request/StandardCheckoutPayRequest';
|
|
4
|
+
import { OrderStatusResponse } from '../../common/models/response/OrderStatusResponse';
|
|
5
|
+
import { StandardCheckoutPayResponse } from './models/response/StandardCheckoutPayResponse';
|
|
6
|
+
import { RefundRequest } from '../../common/models/request/RefundRequest';
|
|
7
|
+
import { RefundResponse } from '../../common/models/response/RefundResponse';
|
|
8
|
+
import { RefundStatusResponse } from '../../common/models/response/RefundStatusResponse';
|
|
9
|
+
import { CallbackResponse } from '../../common/models/response/CallbackResponse';
|
|
10
|
+
import { CreateSdkOrderRequest } from './models/request/CreateSdkOrderRequest';
|
|
11
|
+
import { CreateSdkOrderResponse } from './models/response/CreateSdkOrderResponse';
|
|
12
|
+
export declare class StandardCheckoutClient extends BaseClient {
|
|
13
|
+
private static _client;
|
|
14
|
+
private headers;
|
|
15
|
+
private constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Generates a StandardCheckout 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 StandardCheckoutClient object for interacting with the PhonePe APIs
|
|
26
|
+
*/
|
|
27
|
+
static getInstance: (clientId: string, clientSecret: string, clientVersion: number, env: Env, shouldPublishEvents?: boolean) => StandardCheckoutClient;
|
|
28
|
+
/**
|
|
29
|
+
* Initiate a pay order for Standard Checkout
|
|
30
|
+
*
|
|
31
|
+
* @param payRequest Request required to initiate the order. It is build using StandardCheckoutPayRequest.builder()
|
|
32
|
+
* @return Promise<StandardCheckoutPayResponse> which contains the url for payment gateway
|
|
33
|
+
*/
|
|
34
|
+
pay: (payRequest: StandardCheckoutPayRequest) => Promise<StandardCheckoutPayResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the status of the order
|
|
37
|
+
*
|
|
38
|
+
* @param merchantOrderId Generated by the merchant at the time of initiating the order
|
|
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
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
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.StandardCheckoutClient = void 0;
|
|
28
|
+
const BaseClient_1 = require("../../common/BaseClient");
|
|
29
|
+
const CommonUtils_1 = require("../../common/CommonUtils");
|
|
30
|
+
const Exceptions_1 = require("../../common/exception/Exceptions");
|
|
31
|
+
const HttpMethodType_1 = require("../../common/http/HttpMethodType");
|
|
32
|
+
const Env_1 = require("../../Env");
|
|
33
|
+
const OrderStatusResponse_1 = require("../../common/models/response/OrderStatusResponse");
|
|
34
|
+
const StandardCheckoutPayResponse_1 = require("./models/response/StandardCheckoutPayResponse");
|
|
35
|
+
const Constants_1 = require("./standardcheckout/Constants");
|
|
36
|
+
const RefundResponse_1 = require("../../common/models/response/RefundResponse");
|
|
37
|
+
const RefundStatusResponse_1 = require("../../common/models/response/RefundStatusResponse");
|
|
38
|
+
const class_transformer_1 = require("class-transformer");
|
|
39
|
+
const CallbackResponse_1 = require("../../common/models/response/CallbackResponse");
|
|
40
|
+
const PaymentFlowType_1 = require("../../common/models/PaymentFlowType");
|
|
41
|
+
const CreateSdkOrderResponse_1 = require("./models/response/CreateSdkOrderResponse");
|
|
42
|
+
const Constants_2 = require("../../common/exception/Constants");
|
|
43
|
+
const Headers_1 = require("../../common/constants/Headers");
|
|
44
|
+
const EventType_1 = require("../../common/events/models/enums/EventType");
|
|
45
|
+
const EventState_1 = require("../../common/events/models/enums/EventState");
|
|
46
|
+
const EventBuillder_1 = require("../../common/events/builders/EventBuillder");
|
|
47
|
+
class StandardCheckoutClient extends BaseClient_1.BaseClient {
|
|
48
|
+
constructor(clientId, clientSecret, clientVersion, env, shouldPublishEvents) {
|
|
49
|
+
super(clientId, clientSecret, clientVersion, env, shouldPublishEvents);
|
|
50
|
+
/**
|
|
51
|
+
* Initiate a pay order for Standard Checkout
|
|
52
|
+
*
|
|
53
|
+
* @param payRequest Request required to initiate the order. It is build using StandardCheckoutPayRequest.builder()
|
|
54
|
+
* @return Promise<StandardCheckoutPayResponse> which contains the url for payment gateway
|
|
55
|
+
*/
|
|
56
|
+
this.pay = (payRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const url = Constants_1.StandardCheckoutContants.PAY_API;
|
|
58
|
+
try {
|
|
59
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, StandardCheckoutPayResponse_1.StandardCheckoutPayResponse, this.headers, payRequest);
|
|
60
|
+
this.eventPublisher.send((0, EventBuillder_1.buildStandardCheckoutPayEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.PAY_SUCCESS, payRequest, url));
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.eventPublisher.send((0, EventBuillder_1.buildStandardCheckoutPayEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.PAY_FAILED, payRequest, url, error));
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Gets the status of the order
|
|
70
|
+
*
|
|
71
|
+
* @param merchantOrderId Generated by the merchant at the time of initiating the order
|
|
72
|
+
* @param details true -> order status has all attempt details under paymentDetails list
|
|
73
|
+
* false -> order status has only latest attempt details under paymentDetails list
|
|
74
|
+
* @return Promise<OrderStatusResponse> which contains the details about the order
|
|
75
|
+
*/
|
|
76
|
+
this.getOrderStatus = (merchantOrderId, details = false) => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const url = Constants_1.StandardCheckoutContants.ORDER_STATUS_API.replace('{ORDER_ID}', merchantOrderId);
|
|
78
|
+
try {
|
|
79
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, OrderStatusResponse_1.OrderStatusResponse, this.headers, {}, { [Constants_1.StandardCheckoutContants.ORDER_DETAILS]: details.toString() });
|
|
80
|
+
this.eventPublisher.send((0, EventBuillder_1.buildOrderStatusEvent)(EventState_1.EventState.SUCCESS, merchantOrderId, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT, url, EventType_1.EventType.ORDER_STATUS_SUCCESS));
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
this.eventPublisher.send((0, EventBuillder_1.buildOrderStatusEvent)(EventState_1.EventState.FAILED, merchantOrderId, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT, url, EventType_1.EventType.ORDER_STATUS_FAILED, error));
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Initiate a refund of an order which is in completed state
|
|
90
|
+
*
|
|
91
|
+
* @param refundRequest Request required to initiate the order. It is build using RefundRequest.builder()
|
|
92
|
+
* @return Promise<RefundResponse> which contains the details about the refund
|
|
93
|
+
*/
|
|
94
|
+
this.refund = (refundRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const url = Constants_1.StandardCheckoutContants.REFUND_API;
|
|
96
|
+
try {
|
|
97
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, RefundResponse_1.RefundResponse, this.headers, refundRequest);
|
|
98
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundEvent)(EventState_1.EventState.SUCCESS, refundRequest, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT, EventType_1.EventType.REFUND_SUCCESS));
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundEvent)(EventState_1.EventState.FAILED, refundRequest, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT, EventType_1.EventType.REFUND_FAILED, error));
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
/**
|
|
107
|
+
* Gets the status of refund
|
|
108
|
+
*
|
|
109
|
+
* @param refundId Generated by merchant at the time of initiating the refund
|
|
110
|
+
* @return Promise<RefundStatusResponse> which contains the status about the refund
|
|
111
|
+
*/
|
|
112
|
+
this.getRefundStatus = (refundId) => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const url = Constants_1.StandardCheckoutContants.REFUND_STATUS_API.replace('{REFUND_ID}', refundId);
|
|
114
|
+
try {
|
|
115
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, RefundStatusResponse_1.RefundStatusResponse, this.headers);
|
|
116
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundStatusEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.REFUND_STATUS_SUCCESS, refundId, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
117
|
+
return response;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
this.eventPublisher.send((0, EventBuillder_1.buildRefundStatusEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.REFUND_STATUS_FAILED, refundId, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Gets the status of a transaction attempted
|
|
126
|
+
*
|
|
127
|
+
* @param transactionId Transaction attempt id generated by PhonePe
|
|
128
|
+
* @return Promise<OrderStatusResponse> which contains the details about that specific transactionId
|
|
129
|
+
*/
|
|
130
|
+
this.getTransactionStatus = (transactionId) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const url = Constants_1.StandardCheckoutContants.TRANSACTION_STATUS_API.replace('{TRANSACTION_ID}', transactionId);
|
|
132
|
+
try {
|
|
133
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.GET, url, OrderStatusResponse_1.OrderStatusResponse, this.headers);
|
|
134
|
+
this.eventPublisher.send((0, EventBuillder_1.buildTransactionStatusEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.TRANSACTION_STATUS_SUCCESS, transactionId, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.eventPublisher.send((0, EventBuillder_1.buildTransactionStatusEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.TRANSACTION_STATUS_FAILED, transactionId, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* Create order token for SDK integrated order requests
|
|
144
|
+
*
|
|
145
|
+
* @param sdkRequest Request object build using CreateSdkOrderRequest.builder()
|
|
146
|
+
* @return Promise<CreateSdkOrderResponse> which contains token details to be consumed by the UI
|
|
147
|
+
*/
|
|
148
|
+
this.createSdkOrder = (sdkRequest) => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const url = Constants_1.StandardCheckoutContants.CREATE_ORDER_API;
|
|
150
|
+
try {
|
|
151
|
+
const response = yield this.requestViaAuthRefresh(HttpMethodType_1.HttpMethodType.POST, url, CreateSdkOrderResponse_1.CreateSdkOrderResponse, this.headers, sdkRequest);
|
|
152
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCreateSdkOrderEvent)(EventState_1.EventState.SUCCESS, EventType_1.EventType.CREATE_SDK_ORDER_SUCCESS, sdkRequest, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
153
|
+
return response;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
this.eventPublisher.send((0, EventBuillder_1.buildCreateSdkOrderEvent)(EventState_1.EventState.FAILED, EventType_1.EventType.CREATE_SDK_ORDER_FAILED, sdkRequest, url, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
/**
|
|
161
|
+
* Validate if the callback is valid
|
|
162
|
+
*
|
|
163
|
+
* @param username username set by the merchant on the dashboard
|
|
164
|
+
* @param password password set by the merchant on the dashboard
|
|
165
|
+
* @param authorization String data under `authorization` key of response headers
|
|
166
|
+
* @param responseBody Callback response body
|
|
167
|
+
* @return CallbackResponse Deserialized callback body
|
|
168
|
+
* @throws PhonePeException when callback is not valid
|
|
169
|
+
*/
|
|
170
|
+
this.validateCallback = (username, password, authorization, responseBody) => {
|
|
171
|
+
if (!CommonUtils_1.CommonUtils.isCallbackValid(username, password, authorization)) {
|
|
172
|
+
throw new Exceptions_1.PhonePeException('Invalid Callback', 417);
|
|
173
|
+
}
|
|
174
|
+
const parsedBody = JSON.parse(responseBody);
|
|
175
|
+
return (0, class_transformer_1.plainToClass)(CallbackResponse_1.CallbackResponse, parsedBody);
|
|
176
|
+
};
|
|
177
|
+
this.prepareHeaders = () => {
|
|
178
|
+
return {
|
|
179
|
+
[Headers_1.Headers.CONTENT_TYPE]: Headers_1.Headers.APPLICATION_JSON,
|
|
180
|
+
[Headers_1.Headers.SOURCE]: Headers_1.Headers.INTEGRATION,
|
|
181
|
+
[Headers_1.Headers.SOURCE_VERSION]: Headers_1.Headers.API_VERSION,
|
|
182
|
+
[Headers_1.Headers.SOURCE_PLATFORM]: Headers_1.Headers.SDK_TYPE,
|
|
183
|
+
[Headers_1.Headers.SOURCE_PLATFORM_VERSION]: Headers_1.Headers.SDK_VERSION,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
this.eventPublisher.send((0, EventBuillder_1.buildInitClientEvent)(EventType_1.EventType.STANDARD_CHECKOUT_CLIENT_INITIALIZED, PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT));
|
|
187
|
+
this.headers = this.prepareHeaders();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.StandardCheckoutClient = StandardCheckoutClient;
|
|
191
|
+
/**
|
|
192
|
+
* Generates a StandardCheckout Client for interacting with the PhonePe APIs
|
|
193
|
+
*
|
|
194
|
+
* @param clientId Unique clientId assigned to merchant by PhonePe
|
|
195
|
+
* @param clientSecret Secret provided by PhonePe
|
|
196
|
+
* @param clientVersion The client version used for secure transactions
|
|
197
|
+
* @param env Set to `Env.SANDBOX` for the SANDBOX environment or `Env.PRODUCTION` for the production
|
|
198
|
+
* environment.
|
|
199
|
+
* @param shouldPublishEvents When true, events are sent to PhonePe providing smoother experience
|
|
200
|
+
* @return StandardCheckoutClient object for interacting with the PhonePe APIs
|
|
201
|
+
*/
|
|
202
|
+
StandardCheckoutClient.getInstance = (clientId, clientSecret, clientVersion, env, shouldPublishEvents = true) => {
|
|
203
|
+
shouldPublishEvents = shouldPublishEvents && env == Env_1.Env.PRODUCTION;
|
|
204
|
+
if (StandardCheckoutClient._client == undefined) {
|
|
205
|
+
StandardCheckoutClient._client = new StandardCheckoutClient(clientId, clientSecret, clientVersion, env, shouldPublishEvents);
|
|
206
|
+
return StandardCheckoutClient._client;
|
|
207
|
+
}
|
|
208
|
+
const requestedClientSHA = CommonUtils_1.CommonUtils.calculateSha256({
|
|
209
|
+
clientId: clientId,
|
|
210
|
+
clientSecret: clientSecret,
|
|
211
|
+
clientVersion: clientVersion,
|
|
212
|
+
env: env,
|
|
213
|
+
shouldPublishEvents: shouldPublishEvents,
|
|
214
|
+
paymentFlowType: PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT,
|
|
215
|
+
});
|
|
216
|
+
const cachedClientSHA = CommonUtils_1.CommonUtils.calculateSha256({
|
|
217
|
+
clientId: StandardCheckoutClient._client.merchantConfig.clientId,
|
|
218
|
+
clientSecret: StandardCheckoutClient._client.merchantConfig.clientSecret,
|
|
219
|
+
clientVersion: StandardCheckoutClient._client.merchantConfig.clientVersion,
|
|
220
|
+
env: StandardCheckoutClient._client.env,
|
|
221
|
+
shouldPublishEvents: StandardCheckoutClient._client.shouldPublishEvents,
|
|
222
|
+
paymentFlowType: PaymentFlowType_1.PaymentFlowType.PG_CHECKOUT,
|
|
223
|
+
});
|
|
224
|
+
if (requestedClientSHA == cachedClientSHA)
|
|
225
|
+
return StandardCheckoutClient._client;
|
|
226
|
+
throw new Exceptions_1.PhonePeException(Constants_2.Constants.CLIENT_EXCEPTION(StandardCheckoutClient._client.constructor.name));
|
|
227
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class CustomCheckoutConstants {
|
|
2
|
+
static readonly PAY_API: string;
|
|
3
|
+
static readonly ORDER_STATUS_API: string;
|
|
4
|
+
static readonly ORDER_DETAILS: string;
|
|
5
|
+
static readonly REFUND_API: string;
|
|
6
|
+
static readonly REFUND_STATUS_API: string;
|
|
7
|
+
static readonly TRANSACTION_STATUS_API: string;
|
|
8
|
+
static readonly CREATE_ORDER_API: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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.CustomCheckoutConstants = void 0;
|
|
19
|
+
class CustomCheckoutConstants {
|
|
20
|
+
}
|
|
21
|
+
exports.CustomCheckoutConstants = CustomCheckoutConstants;
|
|
22
|
+
CustomCheckoutConstants.PAY_API = '/payments/v2/pay';
|
|
23
|
+
CustomCheckoutConstants.ORDER_STATUS_API = '/payments/v2/order/{ORDER_ID}/status';
|
|
24
|
+
CustomCheckoutConstants.ORDER_DETAILS = 'details';
|
|
25
|
+
CustomCheckoutConstants.REFUND_API = '/payments/v2/refund';
|
|
26
|
+
CustomCheckoutConstants.REFUND_STATUS_API = '/payments/v2/refund/{REFUND_ID}/status';
|
|
27
|
+
CustomCheckoutConstants.TRANSACTION_STATUS_API = '/payments/v2/transaction/{TRANSACTION_ID}/status';
|
|
28
|
+
CustomCheckoutConstants.CREATE_ORDER_API = '/payments/v2/sdk/order';
|
|
@@ -0,0 +1,34 @@
|
|
|
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("./CustomCheckoutClient"), exports);
|
|
33
|
+
__exportStar(require("./StandardCheckoutClient"), exports);
|
|
34
|
+
__exportStar(require("./models"), exports);
|